| Goal | MainClass ClassDeclaration EOF | |
| MainClass | "class" Identifier "{" "public" "static" "void" "main" "(" "String" "[" "]" Identifier ")" "{" Statement "}" "}" | |
| ClassDeclaration | "class" Identifier "extends" Identifier "{" VarDeclaration MethodDeclaration "}" | |
| "record" Identifier "(" Type Identifier "," Type Identifier ")" "{" "}" | ||
| VarDeclaration | Type Identifier ";" | |
| MethodDeclaration | "public" Type Identifier "(" Type Identifier "," Type Identifier ")" "{" VarDeclaration Statement "return" Expression ";" "}" | |
| Type | "int" "[" "]" | |
| "boolean" | ||
| "int" | ||
| Identifier | ||
| Statement | "{" Statement "}" | |
| "if" "(" Expression ")" Statement "else" Statement | ||
| "while" "(" Expression ")" Statement | ||
| "System" "." "out" "." "println" "(" Expression ")" ";" | ||
| Identifier "=" Expression ";" | ||
| Identifier "[" Expression "]" "=" Expression ";" | ||
| Expression | Expression "&&" | "<" | "+" | "-" | "*" Expression | |
| Expression "." Identifier "(" Expression "," Expression ")" | ||
| Expression "[" Expression "]" | ||
| Expression "." "length" | ||
| "new" "int" "[" Expression "]" | ||
| "new" Identifier "(" Expression "," Expression ")" | ||
| "!" Expression | ||
| IntegerLiteral | ||
| "true" | ||
| "false" | ||
| Identifier | ||
| "this" | ||
| "(" Expression ")" | ||
| Identifier | one or more letters, digits, and underscores, starting with a letter | |
| IntegerLiteral | one or more decimal digits [see Java spec for largest] | |
| EOF | a distinguished token returned by the scanner at end-of-file |
There is a problem of consistency with Java concerning array access and array creation.
They are both expressions.
In Java new int [5][4] is 2D array creation and not array access
as in MiniJava (new int [5])[4].
No Java/Python unicode escapes \uXXXX are used in MiniJava,
but are easy to include using a JavaCC options: JAVA_UNICODE_ESCAPE=true.
Line terminators are LF, CF, or CF followed by LF. In addition to the line terminators, white space is SP, HT, or the FF characters. (In Java the input can end with the US-ASCII SUB character, also known as "control-Z".)
/* One commment /* Nested comment */ Bad things will happen */The second /* will be ignored (it is in a comment), and the first */ will terminate the comment. Now, "bad things will happen" as the remaining text is not a comment.
Appel, 2nd edition, page 484, describes comments in MiniJava as being nestable. This is an interesting exercise for the scanner, but is not correct.
Any Latin-1 character is legal in a Java comment.
javac -encoding ISO-8859-1 ClassFile.javaA Mini Java program behaves exactly like the Java program.
The following program is not legal in Java:
class Main {
void m() {
int goto = 3; // 'goto' is a reserved word in Java
}
}
it should not be legal in Mini-Java.
A Mini-Java program with uninitilized variables ought to be illegal just as in Java. A Mini-java program with unreachable statements ought to be illegal just as in Java.
A minimal Mini-Java compiler must, however, include the following features: