Project 1

Due: 11:59pm, Friday February 3rd, 2012

Useful Links

Description

Your task is to implement the front-end of a compiler for the CJ language, which has surface syntax similar to C and Java, but takes inspiration from Modula-3 for its semantics.

Getting Started

Source code to get started with is available via svn on the XINU machines using the command:

  svn co file:///homes/cs502/project/svn/p1
or remotely using the repository URL:
  svn+ssh://xinu1.cs.purdue.edu/homes/cs502/project/svn/p1
You can freely replace the machine name xinu1 with any of the machines in the XINU lab (e.g., xinu2).

You will now have a working copy of the project files in the directory p1. This contains src and lib subdirectories. The src subdirectory contains source files for this project. 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 using svn.

If you are using the lab machines then you should be sure to set up your environment as in the file /homes/cs502/SETUP.sh (or /homes/cs502/SETUP.csh if you use the C shell). The easiest way is to source the appropriate file from either your sh/bash .profile/.bash_profile or csh/tcsh .login shell startup script.

From here on we will assume that you have first set your current directory to the p1/src subdirectory using the command:

  cd p1/src
to enter the src subdirectory.

The file cj/CJ.jj contains the javacc specification for the CJ scanner and parser. You will work entirely on this file for this project.

You generate the scanner and parser Java source code from this file with the command:

  javacc CJ.jj
This will produce Java source code files into the directory cj/parse. If you are using Eclipse and have the JavaCC plugin installed then when you save changes to this file then the javacc command should run automatically to produce the Java source code files.

You must compile these files (and all the other Java files) using the javac Java-to-bytecode compiler. If you are using Eclipse this should happen automatically.

You can run the scanner with the command:

  java cj.parse.ParserTokenManager file
where file is a file containing CJ tokens.

You can run the parser with the command:

  java cj.parse.Parser file
where file is a CJ source code file.

You can print out the abstract syntax tree generated by the parser with the command:

  java cj.Absyn file

You should turn in all code you add/modify as well as a written report (README) describing your implementation. Use the turnin command on the XINU lab machines to do so.