Project 2: Parser

Due 11:59pm Thursday October 4

Useful Links

Description

Implement a parser for the Mojo language using JavaCC.

Getting Started

Begin first by extending your JavaCC scanner for Mojo tokens from project 1 (if your scanner still needs more work please see the TA and he will help you get it fixed). Starting with your scanner, write JavaCC grammar rules for Mojo. Initially, your parser will simply take an input and decide if it is a syntactically correct Mojo program.

Once you have this working you will then use your parser to construct an abstract syntax tree (AST) for the input program.

Source code to get started with is available via svn:

	svn co svn+ssh://sslab01.cs.purdue.edu/homes/cs352/svn/p2

This command will checkout a copy of the project files to a local working directory p2. We are serving up the sources to you using SVN so we can easily push any fixes out to you as you work on the project. You may notice that the p2 directory contains src, bin, and lib subdirectories. The src subdirectory contains source files for this project. The bin subdirectory is intended to be the target directory for compiling src files. The lib subdirectory contains any precompiled class files you will need to compile this project. (The files are actually configured as an Eclipse project, so you can also import the project into Eclipse at your convenience.)

All commands below will assume that you have first set your current directory to the p2/src subdirectory using the command:

        cd p2/src

The framework for building the AST (and printing out the results) is available in mojo/Absyn.java. You do not need to edit this file, but you will be building the AST from the classes in this file.

You can run the parser and print out the AST it builds using the command:

        java mojo.Absyn file.mj

Before starting this project, familiarize yourself with Chapters 3 & 4 of the textbook. In addition to the lectures, this will give you a solid foundation for starting your parser.

Turnin

You should turn in just your JavaCC file, which implements your parser, using the turnin command available on CS Unix machines.

Grading

We will create a set of test cases, and then compare the output of your solution to our reference implementation. Grading test cases are intended to test separable functionality of your parser.

There will be a reconciliation period after initial grading when you will be able to compare outputs of your parser with those of the reference implementation, and you may then offer simple fixes for the TAs to apply to your implementation to improve your grade. These fixes will be accepted only at the discretion of the TAs and the instructor (we will judge what "simple" means!)

The reconciliation period is only intended for you to be able to fix simple problems that you may have mistakenly overlooked. Thus, you must make sure to test your implementation thoroughly.