Question: We've seen VM Code and how that can be translated to Assembly and Machine code, but these languages are represented as basic sequences of instructions

We've seen VM Code and how that can be translated to Assembly and Machine code, but these languages are represented as basic sequences of instructions -- how do we handle the nested and varied structures of high-level programming languages?
Using your preferred programming language (Python, C++ or Java) implement the CompilerParser as described below.
This practical assignment follows a similar approach to the Nand2Tetris Compilation Engine.
Template files are provided for each of these programming languages.
Download the Python version HERE Download HERE.
Download the Java version HERE Download HERE.
Download the C++ version HERE Download HERE.
You will need to complete the methods provided in the CompilerParser class.
The provided ParseTree & Token classes should not be modified.
Only submit files for 1 programming language.
Getting Started
Start by reviewing chapter 10 of the textbook.
Each of the methods listed below needs to apply the corresponding set of grammar rules to the series of tokens given.
For each set of these grammar rules:
A new parse tree is created.
The tokens are processed 1-by-1.
Tokens matching the grammar rule are added to a ParseTree for that rule.
If the rules are broken (i.e. the sequence of tokens does not match the rules), a ParseException should be thrown/raised.
Otherwise the ParseTree data structure is returned.
Some of the sets grammar rules require other sets of grammar rules.
For example, the whileStatement rule requires the rules for expression and statements.
These rule sets should be applied recursively.
A ParseTree data structure is returned
Tokens
Each token has a type and corresponding value.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!