Assignments 11 and 12

Assignment 11 Due Date: 2015-4-12, 11:59pm

Assignment 12 Due Date: 2015-4-19, 11:59pm

Objective

The goal of these assignments is to be able to translate any arbitrary Jack program into a valid VM program. These projects build off of your Assignment 10 code, and should generate the VM program from your syntax tree. To guide your translation, you are provided with 11 test programs, which should be completed in order.
  1. Empty - Smallest valid program. Requires translation of
    • class
    • subroutineDec with void type
    • statements
    • returnStmt with no expression
  2. FortyTwo Prints the number 42. Requires translation of
    • doStmt
    • subroutineCall
    • expressionList
    • expression (partially)
    • term / integerConstant
  3. Seven Prints seven with a couple different complex expressions. Requires translation of
    • expression with multiple terms/ops
    • term / ( expression )
    • term / - term
    • term / ~ term
    • op
  4. Static Test some static variables. Requires translation of
    • classVarDec
    • type
    • letStmt
    • term / identifier
    • term / true false null
  5. Quadratic Modified version of Quadratic from A10. Requires translation of
    • subroutineDec (with type)
    • parameterList
    • varDec
    • term / subroutineCall
    • returnStmt with actual return value
  6. ConvertToBin Converts numbers to binary. Requires translation of
    • ifStmt
    • whileStmt
  7. HelloWorld Requires translation of
    • term / stringConstant
  8. Square Our old friend the Square game. Requires translation of
    • constructor
    • fields
    • methods
    • this
    • subroutineCall with this
    • subroutineCall with instance of a class
  9. Average Compute the average of input numbers. Requires translation of
    • letStmt with brackets
    • term / identifier with brackets
  10. WackyArrays A bunch of harder tests with array brackets. If all previous parts were implemented correctly, should not require additional functionality.
  11. Pong If all previous parts were implemented correctly, should not require additional functionality.

Programs 1-5 should be completed by the Project 11 deadline. Programs 6-11 should be completed by the Project 12 deadline. Your final code should match either the code generated by the provided JackCompiler or the supplied vm.alt files. The alternate files have a different set of label names.

Software

This assignment requires you to write code. Stubs for Java and Python are provided in your repos. Your code will be run with one of the following commands:

  • Java - java JackCompiler Something.jack
  • Python - python jack_compiler.py Something.jack
  • C/C++ - ./jack_compiler Something.jack
Please turn in all the files needed to run your compiler, including those from A10 and files that you have not modified. There is no need to create a separate folder for A12; just complete the code in the 11 folder.

The repos also contain a Jack parser that reads the XML files in the Data1112 folder. You can use it or your own parser.

Hints

  • Note that the grammar for this class and the "official" grammar in the book differ slightly.
  • When processing subroutineDeclarations, until Quadratic, you can assume that there are 0 locals, and the type is void.
  • There is a test file for 6_ConvertToBin for you to test logic. You can create additional test files for the other tests.
  • The code originally had a typo in both the Java and Python versions. In the JackCompiler/jack_compiler constructor, it called the compile_class method of the parser. It should have said parse_class. The zip file has been updated.
  • The simpler way to handle let a[i] = statements has been integrated into test programs 9 and A, with new/altered vm.alt files.