BNF for tacojava2.jj

TOKENS

/************************************
 * The TACoJava2 Grammar Starts Here *
 ************************************/
Goal ::= MainClass ( TypeDeclaration )* <EOF>
MainClass ::= "class" Identifier "{" "public" "static" "void" "main" "(" "String" "[" "]" Identifier ")" "{" ( VarDeclaration )* ( Statement )* "}" "}"
TypeDeclaration ::= ClassDeclaration
| ClassExtendsDeclaration
ClassDeclaration ::= "class" Identifier "{" ( VarDeclaration )* ( MethodDeclaration )* "}"
ClassExtendsDeclaration ::= "class" Identifier "extends" Identifier "{" ( VarDeclaration )* ( MethodDeclaration )* "}"
VarDeclaration ::= Type Identifier ";"
MethodDeclaration ::= "public" Type Identifier "(" ( FormalParameterList )? ")" "{" ( VarDeclaration )* ( Statement )* "return" ConstOrId ";" "}"
FormalParameterList ::= FormalParameter ( FormalParameterRest )*
FormalParameter ::= Type Identifier
FormalParameterRest ::= "," FormalParameter
Type ::= ArrayType
| BooleanType
| IntegerType
| Identifier
ArrayType ::= "int" "[" "]"
BooleanType ::= "boolean"
IntegerType ::= "int"
Statement ::= Block
| AssignmentStatement
| ArrayAssignmentStatement
| FieldAssignmentStatement
| VoidMessageSendStatement
| IfStatement
| WhileStatement
| ForStatement
| PrintStatement
Block ::= "{" ( Statement )* "}"
AssignmentStatement ::= Identifier "=" Expression ";"
VoidMessageSendStatement ::= MessageSend ";"
ArrayAssignmentStatement ::= Identifier "[" ConstOrId "]" "=" ConstOrId ";"
FieldAssignmentStatement ::= Identifier "." Identifier "=" ConstOrId ";"
IfStatement ::= "if" "(" ConstOrId ")" Statement "else" Statement
WhileStatement ::= "while" "(" ConstOrId ")" Statement
ForStatement ::= "for" "(" Identifier "=" Expression ";" Expression ";" Identifier "=" Expression ")" Statement
PrintStatement ::= "System.out.println" "(" ConstOrId ")" ";"
Expression ::= AndExpression
| CompareExpression
| PlusExpression
| MinusExpression
| TimesExpression
| ArrayLookup
| ArrayLength
| MessageSend
| PrimaryExpression
AndExpression ::= ConstOrId "&" ConstOrId
CompareExpression ::= ConstOrId "<" ConstOrId
PlusExpression ::= ConstOrId "+" ConstOrId
MinusExpression ::= ConstOrId "-" ConstOrId
TimesExpression ::= ConstOrId "*" ConstOrId
ArrayLookup ::= Identifier "[" ConstOrId "]"
ArrayLength ::= Identifier "." "length"
MessageSend ::= PrimaryExpression "." Identifier "(" ( ArgList )? ")"
ArgList ::= ConstOrId ( ArgRest )*
ArgRest ::= "," ConstOrId
PrimaryExpression ::= IntegerLiteral
| TrueLiteral
| FalseLiteral
| Identifier
| ThisExpression
| ArrayAllocationExpression
| AllocationExpression
| NotExpression
IntegerLiteral ::= IntegerLiteralWithPosSign
| IntegerLiteralWithNegSign
| PlainIntegerLiteral
PlainIntegerLiteral ::= <INTEGER_LITERAL>
IntegerLiteralWithPosSign ::= "+" <INTEGER_LITERAL>
IntegerLiteralWithNegSign ::= "-" <INTEGER_LITERAL>
ConstOrId ::= IntegerLiteral
| Identifier
| TrueLiteral
| FalseLiteral
TrueLiteral ::= "true"
FalseLiteral ::= "false"
Identifier ::= <IDENTIFIER>
ThisExpression ::= "this"
ArrayAllocationExpression ::= "new" "int" "[" ConstOrId "]"
AllocationExpression ::= "new" Identifier "(" ")"
NotExpression ::= "!" Identifier