Workshop In Computer Construction - From Nand to Tetris
Project 10 - The Compiler I: Syntax Analysis
Deadline May 23rd, 2003 at Ross closing time
Description

Objectives: Develop the Tokenizer and Parser parts of the Jack Compiler according to the specification and implementation notes in chapter 10. The Jack Compiler should compile the jack classes to the virtual machine defined earlier.

The contract: Write the Jack analyzer program in two stages, as described in chapter 10. Use it to parse all the .jack files mentioned below. For each source .jack file, your analyzer should generate an .xml output file. The generated files should be identical to the supplied .xml compare-files.

Test programs:
Program Description Source Tokens file Compare File
Array Test A small program the computes the average of numbers in an array Main.jack Main.txt Main.xml
Square Dance A small game in which you move a black square on the screen. Main.jack
Square.jack
SquareGame.jack
Main.txt
Square.txt
SquareGame.txt
Main.xml
Square.xml
SquareGame.xml
Expressionless Square Dance A small game in which you move a black square on the screen. This version has no nested expressions. Main.jack
Square.jack
SquareGame.jack
Main.txt
Square.txt
SquareGame.txt
Main.xml
Square.xml
SquareGame.xml

Important note: The tokens list does not appear in a browser, at it is not legal xml. To fix this, the tokens list should be enclosed within the tags "<tokens>" and "</tokens>". For example, the source text "x=5" should yield the output:

<tokens>
    <identifier> x </identifier>
    <symbol> = </symbol>
    <integerConstant> 5 </integerConstant>
</tokens>
Note however that the <tokens> tags should be used to mark only the tokenizer's output, and should not be used in the output of the final parser. (This change is introduced simply to enable your browser to render/display the Tokenizer's output properly).

Requirements: You should submit an executable called JackAnalyzer that takes path to a jack file or directory, and produce an xml file as the result of the parsing of the jack file. The usage is:

  • Single file: JackAnalyzer path/to/file.jack creates an xml file in path/to/file.xml
  • Directory: JackAnalyzer path/to/dir parses each of the files in the directory, and creates the corresponding xml files in the directory.
You should also supply a makefile to compile your code. Keep your code well organized and documented, as you would in every programming project.

Submission Submit a tar file (created by `tar cvf`) contains all your source files (well documented !), the JackAnalyzer shell script (if needed), the makefile and a README.
Resources
  • project10.zip (download): Extract to an empty directory, and keep the default directory structure as is.
  • Chapter 10 of the book - "The Compiler I: Syntax Analysis".
  • Guidelines.