BNF for microjava.jj
NON-TERMINALS
Goal
::=
MainClass
(
TypeDeclaration
)* <EOF>
MainClass
::=
"class"
Identifier
"{" "public" "static" "void" "main" "(" "String" "[" "]"
Identifier
")" "{" "new"
Identifier
"(" ")" "."
Identifier
"(" (
ExpressionList
)? ")" ";" "}" "}"
TypeDeclaration
::=
ClassDeclaration
|
ClassExtendsDeclaration
ClassDeclaration
::=
"class"
Identifier
"{" (
VarDeclaration
)* (
MethodDeclaration
)* "}"
ClassExtendsDeclaration
::=
"class"
Identifier
"extends"
Identifier
"{" (
VarDeclaration
)* (
MethodDeclaration
)* "}"
VarDeclaration
::=
Type
Identifier
";"
MethodDeclaration
::=
"public" "void"
Identifier
"(" (
FormalParameterList
)? ")" "{" (
VarDeclaration
)* (
Statement
)* "}"
FormalParameterList
::=
FormalParameter
(
FormalParameterRest
)*
FormalParameter
::=
Type
Identifier
FormalParameterRest
::=
","
FormalParameter
Type
::=
ArrayType
|
BooleanType
|
IntegerType
|
Identifier
ArrayType
::=
"int" "[" "]"
BooleanType
::=
"boolean"
IntegerType
::=
"int"
Statement
::=
Block
|
AssignmentStatement
|
ArrayAssignmentStatement
|
IfStatement
|
WhileStatement
|
PrintStatement
|
MessageSendStatement
Block
::=
"{" (
Statement
)* "}"
AssignmentStatement
::=
VarRef
"="
Expression
";"
ArrayAssignmentStatement
::=
Identifier
"["
Expression
"]" "="
Expression
";"
IfStatement
::=
"if" "("
Expression
")"
Statement
"else"
Statement
WhileStatement
::=
"while" "("
Expression
")"
Statement
PrintStatement
::=
"System.out.println" "("
Expression
")" ";"
MessageSendStatement
::=
Identifier
"."
Identifier
"(" (
ExpressionList
)? ")" ";"
Expression
::=
AndExpression
|
CompareExpression
|
PlusExpression
|
MinusExpression
|
TimesExpression
|
ArrayLookup
|
PrimaryExpression
AndExpression
::=
PrimaryExpression
"&"
PrimaryExpression
CompareExpression
::=
PrimaryExpression
"<"
PrimaryExpression
PlusExpression
::=
PrimaryExpression
"+"
PrimaryExpression
MinusExpression
::=
PrimaryExpression
"-"
PrimaryExpression
TimesExpression
::=
PrimaryExpression
"*"
PrimaryExpression
ArrayLookup
::=
PrimaryExpression
"["
PrimaryExpression
"]"
ExpressionList
::=
Expression
(
ExpressionRest
)*
ExpressionRest
::=
","
Expression
PrimaryExpression
::=
IntegerLiteral
|
TrueLiteral
|
FalseLiteral
|
VarRef
|
ThisExpression
|
ArrayAllocationExpression
|
AllocationExpression
|
NotExpression
|
BracketExpression
IntegerLiteral
::=
<INTEGER_LITERAL>
TrueLiteral
::=
"true"
FalseLiteral
::=
"false"
Identifier
::=
<IDENTIFIER>
ThisExpression
::=
"this"
ArrayAllocationExpression
::=
"new" "int" "["
Expression
"]"
AllocationExpression
::=
"new"
Identifier
"(" ")"
NotExpression
::=
"!"
Expression
BracketExpression
::=
"("
Expression
")"
VarRef
::=
DotExpression
|
Identifier
DotExpression
::=
Identifier
"."
Identifier