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 (almost exactly) 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. You may assume that there is no
predefined Object
class and that classes defined
without an extends
clause do not implicitly
extend Object
. All classes in 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.
A method may be restricted to have at most 5 parameters in its
argument list.
The only other available
statements are if
, while
, and
assignment.
MiniJava treats certain lexical strings like "true", "false",
"main", "String" and others
as reserved keywords to simplify scanning and parsing.
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. One difference
from full Java is that any string in double quotes
appearing in the grammar, like "true", should
be treated as a reserved word for our MiniJava project,
even if it can be used or redeclared as an
identifier or has other possible uses in full Java. You should
implement full MiniJava as described in the Grammar and on
the MiniJava web site, except that, for
our project, /* comments */
are not nested, i.e.,
you need to implement /* */
comments, but the
first */
terminates any open comment regardless
of how many /*
sequences 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 not starting with 0, or the number 0 by itself, denoting a decimal integer value.
The implementation platform for the project is Java 11 with
the JFlex/CUP scanner/parser tools. You are free to use any
development environment you wish, but your resulting project
should build (using ant
) and run on the lab linux
machines, attu, and/or the current lab Linux VM.
It also should be possible to develop the project on a system
with more recent versions of Java installed, but be sure that your
code does not use any language features or extensions not present in Java 11,
which is the version currently installed on the lab machines.
If you use IntelliJ or Eclipse, you can create a suitable project by following the instructions in the starter code README files. Follow those instructions carefully. It will save you time, even if you are the impatient sort, and failing to do so may produce a project that is misconfigured or that fails to work properly.
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 object-oriented (as well as procedural) languages. If you are feeling ambitious 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
include ==
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.Object
class that is implicitly the
superclass of any class that does not explicitly
extend
another class.String
literals, extend System.out.println
to
support String
s and overload the +
operator for String
values.double
as a numeric type, overload
System.out.println
to print double
s,
and implement arithmetic operations for double
, possibly including
mixed-mode integer and floating-point arithmetic.More Sophisticated, but very interesting
instanceof
and type casts (which can
require a runtime instanceof
check). (This
actually is surprisingly easy to do.)super.
as a prefix in method
calls.super(...)
at the beginning of the body of a
constructor.int
s, except the type checking rules
are more interesting).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.
Students in M 501 (the 5th-year Master's version of the course) will be required to implement one significant extension beyond the ones outlined above if they are using extra work on the project as their additional M 501 work. Some suggested extensions are detailed here, and you may propose others. Students taking 401 can attempt these extensions for extra credit if desired. Students in M 501 can add additional extra credit features beyond the required extension if desired.