BNF for looptacojava2.jj

TOKENS

<DEFAULT> SKIP : {
" "
| "\t"
| "\n"
| "\r"
| "\f"
}

   
<DEFAULT> SPECIAL : {
<SINGLE_LINE_COMMENT: "//" (~["\n","\r"])* ("\n" | "\r" | "\r\n")>
| <FORMAL_COMMENT: "/**" (~["*"])* "*" ("*" | ~["*","/"] (~["*"])* "*")* "/">
}

   
<DEFAULT> TOKEN : {
<LPAREN: "(">
| <RPAREN: ")">
| <LSQPAREN: "[">
| <RSQPAREN: "]">
| <LBRACE: "{">
| <RBRACE: "}">
| <SEMICOLON: ";">
| <DOT: ".">
| <ASSIGN: "=">
| <LT: "<">
| <PLUS: "+">
| <MINUS: "-">
| <AND: "&">
| <NOT: "!">
| <BOOLEAN: "boolean">
| <CLASS: "class">
| <INTERFACE: "interface">
| <ELSE: "else">
| <EXTENDS: "extends">
| <FALSE: "false">
| <IF: "if">
| <WHILE: "while">
| <FOR: "for">
| <INTEGER: "int">
| <LENGTH: "length">
| <MAIN: "main">
| <NEW: "new">
| <PUBLIC: "public">
| <RETURN: "return">
| <STATIC: "static">
| <STRING: "String">
| <THIS: "this">
| <TRUE: "true">
| <PRINT: "System.out.println">
| <VOID: "void">
| <SCOMMENT1: "/*">
| <SCOMMENT2: "*/">
| <INDEPENDENTITERS: "INDEPENDENTITERS?">
| <LIC: "LOOPINVARIANTCODE?">
}

   
<DEFAULT> TOKEN : {
<INTEGER_LITERAL: ["1"-"9"] (["0"-"9"])* | "0">
}

   
<DEFAULT> TOKEN : {
<IDENTIFIER: <LETTER> (<LETTER> | <DIGIT>)*>
| <#LETTER: ["$","A"-"Z","_","a"-"z","\u00c0"-"\u00d6","\u00d8"-"\u00f6","\u00f8"-"\u00ff","\u0100"-"\u1fff","\u3040"-"\u318f","\u3300"-"\u337f","\u3400"-"\u3d2d","\u4e00"-"\u9fff","\uf900"-"\ufaff"]>
| <#DIGIT: ["0"-"9","\u0660"-"\u0669","\u06f0"-"\u06f9","\u0966"-"\u096f","\u09e6"-"\u09ef","\u0a66"-"\u0a6f","\u0ae6"-"\u0aef","\u0b66"-"\u0b6f","\u0be7"-"\u0bef","\u0c66"-"\u0c6f","\u0ce6"-"\u0cef","\u0d66"-"\u0d6f","\u0e50"-"\u0e59","\u0ed0"-"\u0ed9","\u1040"-"\u1049"]>
}

   

NON-TERMINALS

/************************************
 * The LoopyTACoJava2 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" Identifier ";" "}"
FormalParameterList ::= FormalParameter ( FormalParameterRest )*
FormalParameter ::= Type Identifier
FormalParameterRest ::= "," FormalParameter
Type ::= ArrayType
| BooleanType
| IntegerType
| Identifier
ArrayType ::= "int" "[" "]"
BooleanType ::= "boolean"
IntegerType ::= "int"
Statement ::= Block
| AssignmentStatements
| IfStatement
| WhileStatement
| ForStatement
| PrintStatement
AssignmentStatements ::= ( LICAnn )? ( AssignmentStatement | ArrayAssignmentStatement | FieldAssignmentStatement )
LICAnn ::= <SCOMMENT1> <LIC> <SCOMMENT2>
Block ::= "{" ( Statement )* "}"
AssignmentStatement ::= Identifier "=" Expression ";"
ArrayAssignmentStatement ::= Identifier "[" Identifier "]" "=" ConstOrId ";"
FieldAssignmentStatement ::= Identifier "." Identifier "=" Identifier ";"
IfStatement ::= "if" "(" Identifier ")" Statement "else" Statement
WhileStatement ::= "while" "(" Identifier ")" Statement
ForStatement ::= ( LoopAnnotation )? "for" "(" Identifier "=" Expression ";" Expression ";" Identifier "=" Expression ")" Statement
LoopAnnotation ::= IndependentIters
IndependentIters ::= <SCOMMENT1> <INDEPENDENTITERS> <SCOMMENT2>
PrintStatement ::= "System.out.println" "(" Identifier ")" ";"
Expression ::= AndExpression
| CompareExpression
| PlusExpression
| MinusExpression
| TimesExpression
| ArrayLookup
| ArrayLength
| MessageSend
| PrimaryExpression
AndExpression ::= Identifier "&" Identifier
CompareExpression ::= ConstOrId "<" ConstOrId
PlusExpression ::= ConstOrId "+" ConstOrId
MinusExpression ::= ConstOrId "-" ConstOrId
TimesExpression ::= ConstOrId "*" ConstOrId
ArrayLookup ::= Identifier "[" Identifier "]"
ArrayLength ::= Identifier "." "length"
MessageSend ::= PrimaryExpression "." Identifier "(" ( ArgList )? ")"
ArgList ::= Identifier ( ArgRest )*
ArgRest ::= "," Identifier
PrimaryExpression ::= IntegerLiteral
| TrueLiteral
| FalseLiteral
| Identifier
| ThisExpression
| ArrayAllocationExpression
| AllocationExpression
| NotExpression
IntegerLiteral ::= <INTEGER_LITERAL>
TrueLiteral ::= "true"
FalseLiteral ::= "false"
Identifier ::= <IDENTIFIER>
ConstOrId ::= Identifier
| IntegerLiteral
| TrueLiteral
| FalseLiteral
ThisExpression ::= "this"
ArrayAllocationExpression ::= "new" "int" "[" Identifier "]"
AllocationExpression ::= "new" Identifier "(" ")"
NotExpression ::= "!" Identifier