The course project is to implement the MiniJava language specified in the Appendix of Appel's Modern Compiler Implementation in Java, 2nd edition and described on the MiniJava web site. MiniJava is a subset of Java and the meaning of a MiniJava program is given by its meaning as a Java program.
Compared to full Java, a MiniJava program consists of a single
class containing a static main method followed by zero or more other classes.
There are no other static methods or variables. Classes may extend other classes,
and method overriding is included, but method overloading is not.
All classes making up a MiniJava program are included in a single source file.
The only types available are int
, boolean
, int[]
and reference types (classes). "System.out.println(...);
"
is a statement and can only print integers - it is not a normal method call,
and does not refer to a static method of a class. All methods are value-returning
and must end with a single return
statement. The only other available
statements are if
, while
, and assignment. There are other simplifications to keep the project size reasonable.
The full
MiniJava grammar is given on the project web site and in the Appendix of
Appel's Modern Compiler Implementation in Java (2nd ed). Look at the
grammar carefully to see what is and is not included in the language subset.
You should implement full MiniJava as described there, except that you do
not need to implement nested /* comments */. (You need to implement /* */ comments,
but do not need to allow them to nest, i.e., the first */ terminates any open
comment regardless of how many /* symbols have appeared before it, as in standard
Java. You also need to implement //
comments.)
There are two symbols in the grammar that are not otherwise specified. An <IDENTIFIER> is a sequence of letters, digits, and underscores, starting with a letter. Uppercase letters are distinguished from lowercase. An <INTEGER_LITERAL> is a sequence of decimal digits that denotes an integer value.
Your MiniJava compiler should be implemented in Java using the
JFlex/CUP scanner/parser tools. You are free to use any development platform
and environment you wish, but your resulting project should build (using ant
)
and run on the lab linux machines, attu, or the lab VM (more details forthcoming).
If you use Eclipse, you can create a suitable project
by following the instructions in the starter code README files. Don't create a new generic
Java project - it doesn't
set things up correctly.
The basic project requirements are small enough to be tractable in a one-quarter course project, but include enough to cover the core ideas of compiling an object-oriented (as well as procedural) language. If you are feeling ambitous and have the time, you are invited to add additional parts of Java to the language. Here are a few suggestions.
Some Simple Ideas
null
as a constant expression and support ==
and !=
for object reference
types.return
statements anywhere in a method.this
.void
methods, a return
statement with no
expression, and appropriate type checking rules.public
and private
declarations on both
methods and instance variables, and check to ensure that access restrictions
are not violated.Adding an additional numeric type like double
would not be particularly
interesting, since there is relatively little difference in how the compiler
handles ints
and
doubles
. However, adding String
literals and the
concatenation (+) operator would be interesting.
More Sophisticated, but very interesting
instanceof
and type casts (which can require a runtime instanceof
check).super.
as a prefix in method calls.super(...)
at the
beginning of the body of a constructor.Of the suggested extensions, adding instanceof
, type casts, and super.
are
particularly instructive.
Some small amount of extra credit will be awarded to projects that go beyond the basic requirements.