Assignment 10
Due Date: 2015-4-5, 11:59pm
Objective
This assignment continues our work on the compiler by writing a parser for our tokens. You will be working with the same 4 test programs from last time, stored in the Data910 folder. You will need to check the output of your parser against the desired output (Square.xml).
Like the last assignment, the code for generating the XML is included in the provided source files, as long as you fill out the given data structures. The are main method in the parser will output the XML for a given Jack file. However, there is also the BigAssignment10 test file, which, given any list of folders and jack files, will find all jack files therein, and tokenize and parse each, and say whether your output matches. Your outputs will be written to files with the "my" prefix, i.e. mySquare.xml.
To compare your output to the given output, Linux/Mac users can use the command-line tool diff. Windows users can use TextComparer.bat, included with cse365bin. I also highly recommend visual diff tools, like meld.
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 JackParser Something.jack
- Python - python jack_parser.py Something.jack
- C/C++ - ./jack_parser Something.jack
Hints
- Note that the grammar for this class and the "official" grammar from the nand2tetris website differ slightly, as do the outputs.
- Here is the grammar to use in this assignment.
class | class identifier { classVarDec* subroutineDec* }
|
---|
classVarDec | (static | field) type identifier (, identifier)* ;
|
---|
type | int | char | boolean | identifier
|
---|
subroutineDec | (constructor | function | method) (void | type) identifier ( parameterList ) { varDec* statements }
|
---|
parameterList | ((type identifier)(, type identifer)*)?
|
---|
varDec | var type identifier (, identifier)* ;
|
---|
statements | (let_stmt | if_stmt | while_stmt | do_stmt | return_stmt)*
|
---|
let_stmt | let identifier brackets? = expression ;
|
---|
while_stmt | while ( expression ) { statements }
|
---|
if_stmt | if ( expression ) { statements } (else { statements } )?
|
---|
do_stmt | do subroutineCall ;
|
---|
return_stmt | return expression? ;
|
---|
expression | term (op term)*
|
---|
op | + | - | * | / | & | | | < | > | =
|
---|
term | integerConstant |
stringConstant |
true | false | null | this |
identifier brackets? |
subroutineCall |
( expression ) |
- term | ~ term
|
---|
brackets | [ expression ]
|
---|
subroutineCall | identifier (. identifier)? ( expressionList )
|
---|
expressionList | (expression (, expression)* )?
|
---|
- If you are having trouble with a part of the grammar, you can always write your own Jack file to test one specific part.
- The XML output is already implemented, and you shouldn't need to adjust it.
- Once again, you do not have to check for errors.
- Unlike previous coding assignments, this assignment has no flexibility in the output. The output of your tokenizer and parser must match those given.
|