Chapter 3 Rule Language Syntax : Rule Language Syntax

Rule Language Syntax
<Conditions> := { <Predicate> }*
<Actions> := { <StatementOrLocalDecl> }*
<Predicate> := <Expression> ";"
<StatementOrLocalDecl> := <Statement> | <LocalVariableDeclaration> ";"
<Statement> := <LineStatement> | <BlockStatement>
<LineStatement> := ";" | <StatementExpression> ";" | "break" ";" |
"continue" ";" | "return" { <Expression> }? ";"
<BlockStatement> := <Block> | <If> | <While> | <For>| <TryCatchFinally>
<StatementExpression> := <PrimaryExpression> "=" <Expression> | <Name> <Arguments>
<Name> := <Identifier> { .<Identifier> }*
<Arguments> := "(" Expression() { "," Expression() }* ")"
<LocalVariableDeclaration> := <Type> <VariableNameAndInit> { ","
<VariableNameAndInit> }*
<VariableNameAndInit> := <Identifier> { "=" <Expression> |
<DeclarationArrayLiteral> }?
<Type> := <TypeName> { "[]" }?
<TypeName> := <Name> | "boolean" | "int" | "long" | "double"
<DeclarationArrayLiteral> := "{" <Expression> { , <Expression> }* "}"
<Block> := "{" { <StatementOrLocalDecl> }* "}"
<If> := "if" "(" <Expression> ")" <Statement>
<While> := "while" "(" <Expression> ")" <Statement>
<For> := "for" "(" { <LocalVariableDeclaration> |
<StatementExpressionList> }? ";" { <Expression> }?
";" { <StatementExpressionList> }? ")" <Statement>
<StatementExpressionList> := <StatementExpression> {
"," <StatementExpression> }*
<TryCatchFinally> := "try" <Block> { "catch" "(" "Exception" <Identifier>
")" <Block> { "finally" <Block> }? | "finally" <Block> }<Expression> := <ConditionalExpression> { '||'
<ConditionalExpression> }*
<CondtionalExpression> := <EquivalenceExpression> { '&&'
<EquivalenceExpression> }*
<EquivalenceExpression> := <LogicalExpresion> { <EquivalenceOps>
<LogicalExpression> }*
<LogicalExpression> := <AdditiveExpresion> { <LogicalOps>
<AdditiveExpression> | "instanceof" <Type> } }*
<AdditiveExpression> := <MultilicativeExpression> { <AditiveOps>
<MultiplicativeExpression> }*
<MultiplicativeExpression> := <PrimaryExpression> { <MultiplicativeOps>
<PrimaryExpression> }*
<UniaryExpression> := <PrimaryExpression> {<UnaryOps>
<PrimaryExperssion>}*
<PrimaryExpression> := <PrimaryPrefix> { <PrimarySuffix> }*
<PrimaryPrefix> := <Literal> | "(" <Expression> ")" | <Name> |
<ArrayLiteral> | <ArrayAllocator>
<ArrayLiteral> := <Type> "{" <Expression> { , <Expression> }* "}"
<ArrayAllocator> := <Type> "[" <Expression> "]" "{}"
<PrimarySuffix> := <ArrayIndex> | <Arguments> | <PropertyOrAttrAccess>
<PropertyOrAttrAccess> := [ "." , "@" ] <Identifier>
<ArrayIndex> := "[" <Expression> "]"
<EquivalenceOps> := ["==" , "!="]
<LogicalOps> := ["<" , "<=" , "=>" , ">"]
<AditiveOps> := ["+" , "-"]
<MultiplicativeOps> := ["*" , "/" , "%"]
<UnaryOps> := ["!" , "-" , "+"]
 
 
<Literal> := <INTEGRAL_LITERAL> | <DOUBLE_LITERAL> |
<STRING_LITERAL> | <BOOLEAN_LITERAL> | "null"
<INTEGRAL_LITERAL> := <DECIMAL_INT_LITERAL> | <HEX_INT_LITERAL> |
<OCTAL_INT_LITERAL>
| <DECIMAL_LONG_LITERAL> | <HEX_LONG_LITERAL> |
<OCTAL_LONG_LITERAL>
<DOUBLE_LITERAL> := { ["0"-"9"] }+ "." { ["0"-"9"] }* { <EXPONENT> }? {
["d" , "D"] }? | "." { ["0"-"9"] }+ { <EXPONENT> }? {
["d" , "D"] }? | { ["0"-"9"] }+ <EXPONENT> {
["d","D"] }? | { ["0"-"9"] }+ { <EXPONENT> }? ["d" ,
"D"]
<STRING_LITERAL> := '"' <STRING_CONTENTS> '"'
<BOOLEAN_LITERAL> := "true" | "false"
<DECIMAL_INT_LITERAL> := ["1"-"9"] { ["0" - "9"] }*
<HEX_INT_LITERAL> := "0" ["x" , "X"] { ["0"-"9" , "a"-"f" , "A"-"F"] }+
<OCTAL_INT_LITERAL> := "0" { ["0"-"7"] }*
<DECIMAL_LONG_LITERAL> := <DECIMAL_INT_LITERAL> ["l" , "L"]
<HEX_LONG_LITERAL> := <HEX_INT_LITERAL> ["l" , "L"]
<OCTAL_LONG_LITERAL> := <OCTAL_INT_LITERAL> ["l" , "L"]
<EXPONENT> := ["e" , "E"] { ["+" , "-"] }? { ["0"-"9"] }+
<STRING_CONTENTS> := { ~['"' , '\' , "\n" , "\r"] |{ '\'
{ ["n" , "t" , "b" , "r" , "f" , '\' , "'" , '"'] |
["0"-"7"] { ["0"-"7"] }? | ["0"-"3"] ["0"-"7"]
["0"-"7"]
    }
  }
}*
<ReserevedWord> := [ "true", "false", "null", "if", "else", "while",
"for", "continue","break", "return", "int", "long",
"double", "boolean", "instanceof", "rule",
"attribute", "declare", "when", "then", "this",
"moveto", "requeue", "priority", "package", "char",
"float", "abstract", "default", "private", "do",
"implements", "protected","throw", "import",
"public", "throws", "byte", "transient", "case",
"extends","short", "try", "catch", "final",
"interface", "static", "void", "finally",
"strictfp", "volatile","class", "native", "super",
"const", "new", "switch", "goto", "synchronized" ]
// Identifiers additionaly are restricted not to be any of the above reserved words
 
<Identifier> := [ <ID_START> { <ID_PART> }* ]
<ID_START> := except '$', any character for which
java.lang.Character.isJavaIdentifierStart()
returns true
<ID_PART> := except '$', any character for which
java.lang.Character.isJavaIdentifierPart()
returns true
 
<SINGLE_LN_COMMENT> := "//" { ~[ "\n", "\r", "\r\n" ] }*
{ [ "\n", "\r", "\r\n" ] }
<MULTI_LN_COMMENT> := "/*" { ~[ "*/" ] }* "*/"