The course project is to implement the MiniJava language specified in the Appendix of Appel's Modern Compiler Implementation in Java, 2nd edition. MiniJava is a subset of Java and the meaning of a MiniJava program is given by its meaning as a Java program.
We will make one additional simplification: arrays do not need to be implemented. That means that the basic project requirements do not include the following productions from the MiniJava grammar:
Type ::= int [ ]
Statement ::= id [ Exp ] = Exp ;
Exp ::= Exp [ Exp ] | Exp . length | new int [ Exp ]
The array parameter syntax is still included in the main method declaration, but the parameter and its declaration are ignored. All other features of MiniJava, including inheritance (extends) are included.
The basic project requirements are small enough to be tractable in a 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
//
and continue
to the end of the line should be simple. Handling /* ... */
comments that
can span multiple lines is more difficult, but not too hard.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 practically no 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 ordinary 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 extra credit will be available for projects that go beyond the basic requirements.