[SOLVED] CS220 Lab#10 -The Jack Compiler 1

$25

File Name: CS220_Lab#10_-The_Jack_Compiler_1.zip
File Size: 310.86 KB

SKU: [Solved] CS220 Lab#10 -The Jack Compiler 1 Category: Tag:
5/5 - (1 vote)
CS220_Lab10

Name: Date:

Syntax Analysis

Tokenizer Questions:

  1. Translate the following Jack code into its tokenized XML code.
Jack Code Tokenized XML
How many tokens are generated?
var int x;let x = 3;
  1. Translate the following Jack code into its tokenized XML code.
Jack Code Tokenized XML
How many tokens are generated?
var int value;if (y > x){let value = x & y;}
  1. How many tokens will be produced by the following Jack code? Do not translate into XML, just count tokens.
Jack Code Answer =
How many tokens are generated?
var int x, y, greatest;let x = 3;let y = 5;if (x > y){let greatest = x;}else{let greatest = y;}do Output.printInt(greatest);do Output.println();

 

Syntax Analyzer Questions:

  1. Translate the following Jack code into its XML parse tree (using the Jack grammar).
Jack Code XML Parse Tree
let greatest = x is greater;
  1. Translate the following Jack code into its XML parse tree (using the Jack grammar).
Jack Code XML Parse Tree
do Output.printInt(greatest);
  1. Translate the following Jack code into its XML parse tree (using the Jack grammar).
Jack Code XML Parse Tree
class Point{field int x, y; constructor Point new(){let x = 0;let y = 0;}}

Summative Questions:

  • Consider the following statements, taken from three different Jack programs. In each one of these programs, the identifier foo represents a different thing:

let x = 5 + foo a // Here foo represents a simple variable.

let y = foo[12] 3 // Here foo represents an array.

let z = 2 * foo.val() // Here foo represents an object.

Suppose that we are parsing any one of these statements (we dont know which), and that

the current token is foo. How many more tokens do we have to read until we can tell

what we have is a simple variable, an array reference, or a method call?

  1. Zero
  2. One
  3. Two
  4. Three
  5. All answers are wrong
  • Consider the following rule, taken from the Jack grammar:

parameterList: ( ( type varName ) ( , type varName ) * ) ?

Select the correct statement(s):

  1. The rule will parse successfully an empty parameter list
  2. The symbol * (in this context) is part of the Jack language
  3. The symbol * means 0 or 1
  4. The symbol * means 0 or more
  5. The symbol ? means 0 or 1
  6. The symbol ? means 0 or more
  7. The rule will parse successfully the parameter list (int x int y)
  8. The rule will parse successfully the parameter list (int x, int y)
  • XML code is structured as a:
    1. Stack
    2. Graph
    3. Tree
    4. Multi-dimensional array

Programming Exercise:

Using Java, complete the JackTokenizer class (JackTokenizer.java, part of the overall compiler) and implement the following enums (TokenType, Kind and Keyword). You may use the following API design to help guide your work, or choose to implement your own design.

Following is an explanation of each of the methods in the JackTokenizer class. Please note the methods keyword(), intVal(), stringVal(), symbol(), tokenType() are really accessor (getter) methods, thus they have been renamed to getKeyword(), getIntVal(), getStringVal(), getSymbol() and getTokenType() accordingly in the class diagram above.

The main method of the JackTokenizer should prompt the user to enter the name of a Jack file (e.g. SquareDance.jack), then the program will produce an XML output file of all the tokens in the file with the extension xxxT.xml (e.g. SquareDanceT.xml).

You can use the TextComparer.bat (or .sh) supplied with the nand2tetris software to test your output against the solution (attached to this lab assignment on Canvas).

Heres a sample input/output of the Jack Tokenizer:

Heres the provided API for the Jack Tokenizer (also on Helper Sheet):

When youre finished, please upload a single Word document (or PDF) containing the following in order on Canvas:

  1. The .xml files from your 2 sample programs (SquareDanceT.xml and ArrayMain.xml)
  2. The source code of your JackTokenizer
  3. The source code of each of your enums (TokenType, Kind and Keyword)

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] CS220 Lab#10 -The Jack Compiler 1
$25