First, we list the full grammar for MeggyJava, which will be completed in PA5. Below that grammar are versions of the grammar for PA2 through PA4.
This final grammar (PA5) adds variable declarations, assignment statements, objects, and arrays to the PA4 MeggyJava Grammar. The new MeggyJr feature since PA4 is setAuxLEDs.
Goal | ::= | "import" "meggy.Meggy" ";" MainClass ( ClassDeclaration )* <EOF> |
MainClass | ::= | "class" Identifier "{" "public" "static" "void" "main" "(" "String" "[" "]" Identifier ")" "{" (Statement)* "}" "}" |
ClassDeclaration | ::= | "class" Identifier "{" ( VarDeclaration )* ( MethodDeclaration )* "}" |
VarDeclaration | ::= | Type Identifier ";" |
MethodDeclaration | ::= | "public" Type Identifier "(" ( Type Identifier ( "," Type Identifier )* )? ")" "{" ( VarDeclaration )* ( Statement )* ("return" Expression ";")? "}" |
Type | ::= | "Meggy.Color" "[" "]" |
| | "int" "[" "]" | |
| | "boolean" | |
| | "byte" | |
| | "int" | |
| | "void" | |
| | "Meggy.Color" | |
| | "Meggy.Button" | |
| | "Meggy.Tone" | |
| | Identifier | |
Statement | ::= | "{" ( Statement )* "}" |
| | "Meggy.setPixel" "(" Expression "," Expression "," Expression ")" ";" | |
| | "Meggy.setAuxLEDs" "(" Expression ")" ";" | |
| | "Meggy.toneStart" "(" Expression "," Expression ")" ";" | |
| | "Meggy.delay" "(" Expression ")" ";" | |
| | Expression "." Identifier "(" ( Expression ( "," Expression )* )? ")" ";" | |
| | "if" "(" Expression ")" Statement | |
| | "if" "(" Expression ")" Statement "else" Statement | |
| | "while" "(" Expression ")" Statement | |
| | Identifier "=" Expression ";" | |
| | Identifier "[" Expression "]" "=" Expression ";" | |
Expression | ::= | Expression ( "&&" | "<" | "==" | "+" | "-" | "*" ) Expression |
| | "-" Expression | |
| | Expression "[" Expression "]" | |
| | Expression "." "length" | |
| | Expression "." Identifier "(" ( Expression ( "," Expression )* )? ")" | |
| | "Meggy.getPixel" "(" Expression "," Expression ")" | |
| | "Meggy.checkButton" "(" Expression ")" | |
| | "(" "byte" ")" Expression | |
| | <INT_LITERAL> | |
| | <COLOR_LITERAL> | |
| | <BUTTON_LITERAL> | |
| | <TONE_LITERAL> | |
| | "true" | |
| | "false" | |
| | Identifier | |
| | "this" | |
| | "new" "Meggy.Color" "[" Expression "]" | |
| | "new" "int" "[" Expression "]" | |
| | "new" Identifier "(" ")" | |
| | "!" Expression | |
| | "(" Expression ")" | |
Identifier | ::= | <IDENTIFIER> |
Goal | ::= | "import" "meggy.Meggy" ";" MainClass <EOF> |
MainClass | ::= | "class" Identifier "{" "public" "static" "void" "main" "(" "String" "[" "]" Identifier ")" "{" (Statement)* "}" "}" |
Statement | ::= | "Meggy.setPixel" "(" Expression "," Expression "," Expression ")" ";" |
Expression | ::= | "(" "byte" ")" Expression |
| | <INT_LITERAL> | |
| | <COLOR_LITERAL> |
Goal | ::= | "import" "meggy.Meggy" ";" MainClass <EOF> |
MainClass | ::= | "class" Identifier "{" "public" "static" "void" "main" "(" "String" "[" "]" Identifier ")" "{" (Statement)* "}" "}" |
Statement | ::= | "{" ( Statement )* "}" |
| | "Meggy.setPixel" "(" Expression "," Expression "," Expression ")" ";" | |
| | "Meggy.delay" "(" Expression ")" ";" | |
| | "if" "(" Expression ")" Statement | |
| | "if" "(" Expression ")" Statement "else" Statement | |
| | "while" "(" Expression ")" Statement | |
Expression | ::= | Expression ( "&&" | "==" | "+" | "-" | "*" ) Expression |
| | "-" Expression | |
| | "Meggy.getPixel" "(" Expression "," Expression ")" | |
| | "Meggy.checkButton" "(" Expression ")" | |
| | "(" "byte" ")" Expression | |
| | <INT_LITERAL> | |
| | <COLOR_LITERAL> | |
| | <BUTTON_LITERAL> | |
| | "true" | |
| | "false" | | | "!" Expression |
| | "(" Expression ")" |
Goal | ::= | "import" "meggy.Meggy" ";" MainClass ( ClassDeclaration )* <EOF> |
MainClass | ::= | "class" Identifier "{" "public" "static" "void" "main" "(" "String" "[" "]" Identifier ")" "{" (Statement)* "}" "}" |
ClassDeclaration | ::= | "class" Identifier "{" ( MethodDeclaration )* "}" |
MethodDeclaration | ::= | "public" Type Identifier "(" ( Type Identifier ( "," Type Identifier )* )? ")" "{" ( Statement )* ("return" Expression ";")? "}" |
Type | ::= | "boolean" |
| | "byte" | |
| | "int" | |
| | "void" | |
| | "Meggy.Color" | |
| | "Meggy.Button" | |
| | "Meggy.Tone" | |
Statement | ::= | "{" ( Statement )* "}" |
| | "Meggy.setPixel" "(" Expression "," Expression "," Expression ")" ";" | |
| | "Meggy.toneStart" "(" Expression "," Expression ")" ";" | |
| | "Meggy.delay" "(" Expression ")" ";" | |
| | Expression "." Identifier "(" ( Expression ( "," Expression )* )? ")" ";" | |
| | "if" "(" Expression ")" Statement | |
| | "if" "(" Expression ")" Statement "else" Statement | |
| | "while" "(" Expression ")" Statement | |
Expression | ::= | Expression ( "&&" | "<" | "==" | "+" | "-" | "*" ) Expression |
| | "-" Expression | |
| | Expression "." Identifier "(" ( Expression ( "," Expression )* )? ")" | |
| | "Meggy.getPixel" "(" Expression "," Expression ")" | |
| | "Meggy.checkButton" "(" Expression ")" | |
| | "(" "byte" ")" Expression | |
| | <INT_LITERAL> | |
| | <COLOR_LITERAL> | |
| | <BUTTON_LITERAL> | |
| | <TONE_LITERAL> | |
| | "true" | |
| | "false" | |
| | Identifier | |
| | "this" | |
| | "new" Identifier "(" ")" | |
| | "!" Expression | |
| | "(" Expression ")" | |
Identifier | ::= | <IDENTIFIER> |