CSE 401 17wi - MiniJava
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.
You may assume that
there is no predefined
and that classes defined without an
do not implicitly extend
All classes in a MiniJava program are included in a single source file.
The only types available are
and reference types (classes). "
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
while, and assignment. There are other simplifications to keep the project size reasonable.
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
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.
The implementation platform for the project
is Java 8 with the
JFlex/CUP scanner/parser tools.
You are free to use any development
environment you wish, but your resulting project should build (using
and run on the lab linux machines, attu, and/or the lab Linux VM.
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
Eclipse Java project -- it doesn't set things up correctly.
Follow the instructions carefully. It will save you time, even if you are the
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
- Add nested
/* ... */comments.
- Add additional arithmetic and relational operators for integers that are not included in the basic MiniJava specification.
nullas a constant expression and include
!=for object reference types.
returnstatements anywhere in a method.
- Allow calls of local methods without the explicit use of
- Relax the ordering of declarations so that variables can be declared anywhere in a method body.
- Allow initialization of variables in declarations.
returnstatement with no expression, and appropriate type checking rules.
privatedeclarations on both methods and instance variables, and check to ensure that access restrictions are not violated.
- Add a top-level
Objectclass that is implicitly the superclass of any class that does not explicitly
Strings and overload the
doubleas a numeric type, overload
doubles, and implement arithmetic operations for
double, possibly including mixed-mode integer and floating-point arithmetic.
More Sophisticated, but very interesting
instanceofand type casts (which can require a runtime
instanceofcheck). (This actually is surprisingly easy to do.)
super.as a prefix in method calls.
- Add constructor declarations with optional parameters. To make this useful,
you probably want to include the use of
super(...)at the beginning of the body of a constructor.
- Support arrays of objects (no harder to implement than arrays of
ints, 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.
Computer Science & Engineering University of Washington Box 352350 Seattle, WA 98195-2350 (206) 543-1695 voice, (206) 543-2969 FAX
Comments to adminanchor