Programming Project 2: Syntax Analysis
Written by Julie Zelenski, Godmar Back, and updated by Jerry.
This time around you’ll extend your Decaf compiler (at this point it’s nothing more than
a lexer) to handle the syntax analysis phase, the second task of the front-end, by using
to create a parser. The parser will read Decaf source programs and construct a
parse tree. If no syntax errors are encountered, your code will print the completed parse
tree as flat text. At this stage, you aren’t responsible for verifying
The purpose of this project is to familiarize you with the tools and give you experience in
solving typical problems one encounters when using them to generate a parser.
There are two challenges to this assignment. The first is all about
LR parsing knowledge, coming up to speed on how the tools work, and generating a
Decaf parser. The second challenge will come in familiarizing yourself with our
provided code for building a parse tree. In years gone by, we have not provided this
infrastructure, because we previously thought that students would rather make their
own choices. But past students have said they needed more guidance, especially where
it saves them from dead ends, so we’re giving you a set of classes to provide some
structure to your design. It's just a starting skeleton to get you going on, and your job
will be to fully flesh it out over the course of the projects. My sense is that in the long
run you'll be glad to have had our help, but you'll have to first invest the time to come
up to speed on someone else's code, so be prepared for that in this project.
Due: Wednesday, July 13
at 11:59 p.m.
Decaf Program Structure
The reference grammar given in the Decaf language handout defines the official
grammar specification you must parse. The language supports global variables,
functions, classes and interfaces, variables of various types including arrays and objects,
arithmetic and Boolean expressions, constructs such as
, and so on. First,
peruse the grammar specification carefully. Although the grammar is fairly large, most
of it is not tricky to parse.