BNF for functions.oo
NON-TERMINALS
CompilationUnit
::=
ClassDeclaration
<EOF>
ClassDeclaration
::=
"class" <IDENTIFIER> "{" (
ClassBodyDeclaration
)* "}"
ClassBodyDeclaration
::=
MethodDeclaration
MethodDeclaration
::=
"static"
ResultType
<IDENTIFIER>
FormalParameters
( (
Block
| ";" ) )
FormalParameters
::=
"(" (
FormalParameter
( ","
FormalParameter
)* )? ")"
FormalParameter
::=
CallingConvention
PrimitiveType
<IDENTIFIER>
CallingConvention
::=
( "val" | "need" )
PrimitiveType
::=
( "boolean" | "int" | "float" )
ResultType
::=
( "void" |
PrimitiveType
)
Expression
::=
ConditionalExpression
ConditionalExpression
::=
ConditionalOrExpression
( "?"
Expression
":"
ConditionalExpression
)?
ConditionalOrExpression
::=
ConditionalAndExpression
( "||"
ConditionalAndExpression
)*
ConditionalAndExpression
::=
InclusiveOrExpression
( "&&"
InclusiveOrExpression
)*
InclusiveOrExpression
::=
ExclusiveOrExpression
( "|"
ExclusiveOrExpression
)*
ExclusiveOrExpression
::=
AndExpression
( "^"
AndExpression
)*
AndExpression
::=
EqualityExpression
( "&"
EqualityExpression
)*
EqualityExpression
::=
InstanceOfExpression
( ( ( "==" | "!=" ) )
InstanceOfExpression
)*
InstanceOfExpression
::=
RelationalExpression
( "instanceof"
PrimitiveType
)?
RelationalExpression
::=
ShiftExpression
( ( ( "<" | ">" | "<=" | ">=" ) )
ShiftExpression
)?
ShiftExpression
::=
AdditiveExpression
( ( ( "<<" | ">>" | ">>>" ) )
AdditiveExpression
)*
AdditiveExpression
::=
MultiplicativeExpression
( ( ( "+" | "-" ) )
MultiplicativeExpression
)*
MultiplicativeExpression
::=
UnaryExpression
( ( ( "*" | "/" | "%" ) )
UnaryExpression
)*
UnaryExpression
::=
( ( ( "+" | "-" ) )
UnaryExpression
|
UnaryExpressionNotPlusMinus
)
UnaryExpressionNotPlusMinus
::=
( ( ( "~" | "!" ) )
UnaryExpression
|
PrimaryExpression
)
PrimaryExpression
::=
(
Literal
| "("
Expression
")" |
StaticMethodCall
| <IDENTIFIER> )
StaticMethodCall
::=
<IDENTIFIER>
Arguments
Literal
::=
( <INTEGER_LITERAL> | <FLOATING_POINT_LITERAL> |
BooleanLiteral
|
NullLiteral
)
BooleanLiteral
::=
( "true" | "false" )
NullLiteral
::=
"null"
Arguments
::=
"(" (
ArgumentList
)? ")"
ArgumentList
::=
Expression
( ","
Expression
)*
Statement
::=
(
Block
|
EmptyStatement
|
StatementExpression
";" |
SwitchStatement
|
IfStatement
|
WhileStatement
|
BreakStatement
|
ContinueStatement
|
ReturnStatement
|
PrintStatement
)
PrintStatement
::=
"print" "("
Expression
")"
Block
::=
"{" (
BlockStatement
)* "}"
BlockStatement
::=
(
LocalVariableDeclaration
";" |
Statement
)
LocalVariableDeclaration
::=
PrimitiveType
<IDENTIFIER> "="
Expression
EmptyStatement
::=
";"
StatementExpression
::=
<IDENTIFIER> "="
Expression
SwitchStatement
::=
"switch" "("
Expression
")" "{" (
SwitchLabel
(
BlockStatement
)* )* "}"
SwitchLabel
::=
( "case"
Expression
":" | "default" ":" )
IfStatement
::=
"if" "("
Expression
")"
Statement
( "else"
Statement
)?
WhileStatement
::=
"while" "("
Expression
")"
Statement
BreakStatement
::=
"break" ";"
ContinueStatement
::=
"continue" ";"
ReturnStatement
::=
"return" (
Expression
)? ";"