COP 5621 - Homework 4 - MiniJava Abstract Syntax
Due Wednesday, October 27
In this assignment, we will add actions to our MiniJava parsers
to build abstract syntax trees, as described on pages 98-100.
Especially study the summary of the class constructors on page 99.
Now /homes/smithg/compiler/minijava/chap4 contains quite
a few directories and files, but for this assignment you just need to
copy your MiniJava.lex into parse/
and extend your MiniJava grammar from Homework 3 with actions to build
abstract syntax trees.
Study the new skeleton Grm.cup in chap4/parse/ carefully;
it demonstrates techniques that you will need for synthesizing the trees.
A few remarks:
- I've included a test file, Preced.java, and the output
that my parser produces for it, Preced.out.
- All of the classes in syntaxtree/
(except for Identifier and the list classes like
ClassDeclList) have been extended with a pos
field to record the position in the source file that corresponds
with each piece of abstract syntax.
(Positions are briefly discussed on pages 91-93.)
These pos fields allow later compiler phases to give
precise error messages.
See the skeleton Grm.cup for a couple examples of how
these pos fields are filled in.
- Details about CUP actions can be found in the reference manual at
http://www.cs.princeton.edu/~appel/modern/java/CUP/.
- You may find it helpful to rewrite some of the rules in your grammar
to make it easier to generate abstract syntax.
For example, I ended up modifying my rules for FormalList
and ExpList.
Back to