COSC 170 Compiler Construction
Spring 2009
Project #3: Parser
Implement a Parser for our dialect of the MiniJava programming
language, as detailed below.
Project 2 may be completed in teams of three.
Due: Friday, February 13, 11:59PM CST.
Submit entire Project3 directory (JavaCC grammar, abstract syntax tree
classes, associated helper classes, and Makefile) via turnin
command on Morbius.
Directions
Read Chapters 3 and 4 of Appel.
Use JavaCC to implement
the scanner and parser rules for our dialect of MiniJava.
Run the reference implementation of the parser on Morbius with
the command: ~brylow/cosc170/Projects/parser program.java
Create your parser in a package called "Parse" with a
main program in class "Main". My grading protocol will
assume that your project can be compiled and run with the following
command line: cd Project3; make; java Parse.Main inputfile.java.
Build a decent set of MiniJava testcases. Several exist in the
book, and on the web, and can be adapted to our dialect easily.
Having a good set of test inputs will be critical to your success in
later phases of the project. The majority of project points will be
assigned by running diff to compare your output against mine.
Debug until done.
Specification
The Scanner should take a MiniJava program file name on the command
line and write the abstract syntax tree to stdout.
Our language will consist of:
Identifiers as defined in appendix A.1
Decimal Integer Literals as defined in A.1
The MiniJava Grammar as specified here,
which is a subtly enhanced version of the book's MiniJava grammar.
The grammar will need to be modified to eliminate left recursion,
enforce proper Java
operator precedence and associativity, and to eliminate parsing conflicts.
The grammar as given also accepts various non-sensical constructs,
like having a Boolean expression on the left hand side of an
assignment statement, which you may eliminate in your parser.
You must build and output an Abstract Syntax Tree. The JavaDoc description
of the AST classes is
here.
Other useful links:
Java Language Specification
Textbook
Website
Back
[Rev 1.4 2009 Feb 02 14:27 DWB]