Backus-Naur Form (BNF) for KBML
The following details KBML grammar.
topLevelExpression
: kbmlExpression EOF
| appendExpression EOF
;
kbmlExpression
: ifExpression
;
appendExpression
: HASH LCURLY
( kbmlExpression ( COMMA kbmlExpression )*
|
)
RCURLY
;
ifExpression
: "if" logicalOrExpression "then" logicalOrExpression "else" ifExpression
| logicalOrExpression
;
logicalOrExpression
: logicalAndExpression ( "or" logicalAndExpression )*
;
logicalAndExpression
: logicalNotExpression ( "and" logicalNotExpression )*
;
logicalNotExpression
: "not" equalityExpression
| equalityExpression
;
equalityExpression
: relationalExpression
( ( NOT_EQUAL relationalExpression )
| ( EQUAL relationalExpression )
)*
;
relationalExpression
: shiftExpression
( ( LT shiftExpression )
| ( GT shiftExpression )
| ( LE shiftExpression )
| ( GE shiftExpression )
|
)
;
shiftExpression
: additiveExpression
( ( SL additiveExpression )
| ( SR additiveExpression )
)*
;
additiveExpression
: multiplicativeExpression
( ( PLUS multiplicativeExpression )
| ( MINUS multiplicativeExpression )
)*
;
multiplicativeExpression
: binaryOrExpression
( ( STAR binaryOrExpression )
| ( DIV binaryOrExpression )
| ( MOD binaryOrExpression )
)*
;
binaryOrExpression
: binaryXorExpression ( BOR binaryXorExpression )*
;
binaryXorExpression
: binaryAndExpression ( BXOR binaryAndExpression )*
;
binaryAndExpression
: predicateExpression ( BAND predicateExpression )*
;
predicateExpression
: unaryExpression
( "is"
( "not"
|
)
( ( ( "a"
| "an"
)
IDENT
( "of" unaryExpression
|
) )
| ( "in"
( ( "scope" STRING_LITERAL )
| ( "subnet" ipAddress DIV NUM_INT
)
| unaryExpression
) )
| ( "one" "of" expressionList )
| "bound"
| ( IDENT "of" unaryExpression )
| unaryExpression
)
| "starts" "with" unaryExpression
| "ends" "with" unaryExpression
| "matches" unaryExpression
| "dsnMatches" unaryExpression
| "has" unaryExpression
|
)
;
unaryExpression
: quantificationExpression
| MINUS unaryExpression
| LNOT unaryExpression
| PLUS unaryExpression
| attributeExpression
;
ipAddress
: IP_ADDRESS
;
expressionList
: LPAREN kbmlExpression ( COMMA kbmlExpression )* RPAREN
;
quantificationExpression
: "some" IDENT
( IDENT
|
)
;
attributeExpression
: primaryExpression ( ( DOT
| ( SQUOTE
( "s"
|
) )
)
IDENT
( argList
|
)
)*
;
primaryExpression
: constantExpression
| function
| LPAREN kbmlExpression RPAREN
;
argList
: LPAREN RPAREN
| expressionList
;
constantExpression
: NUM_INT
| NUM_LONG
| NUM_FLOAT
| IP_ADDRESS
| STRING_LITERAL
| "true"
| "false"
;
function
: ( "the"
|
)
IDENT
( argList
|
)
;