Assignment 7
Due Tuesday by 23:59
Points 80
Submitting an external tool
Assessment Overview
Weighting: 80 Points (8% of course grade)
Due date: Tuesday 4 Jun, 11:59pm
Task
description:
Develop a Parser to convert high-level programming language into a
parse tree. Doing so should help you to:
Practice applying grammar rules
Understand how complex and nested code structures can be
broken down to their component parts.
Understand the basics of Recursive Descent Parsing.
Please post your questions on Piazza or ask during your workshop.
Academic
Integrity
Checklist
Do
Discuss/compare high level approaches
Discuss/compare program output/errors
Regularly submit your work as you progress
Be careful
Using online resources to find the solutions rather than
understanding them yourself won't help you learn.
Do NOT
Submit code not solely authored by you.
Use a public GitHub repository (use a private one instead).
Post/share complete VM/Assembly/Machine code in
Piazza/Discord or elsewhere on the Internet etc.
Give/show your code to others
Assignment 7
1/13
Your Task
Your task for this practical assignment is to write a parser to convert high-level language
programs into a parse tree that can be later converted to VM Code.

  1. Complete the Parser as described and as outlined below.
    Submit your写 parse tree high-level programming work regularly to Gradescope as you progress.
    Additional resources and help will be available during your workshop sessions.
  2. Test your code.
    We're know that things are tight at the end of semester, so we've kept this assignment short
    (and hopefully simple).
    Part 1 - Recursive Descent Parser (80 points)
    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.

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.
Assignment 7
2/13
Getting Started

  1. Start by reviewing chapter 10 of the textbook.
  2. 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.
  3. A ParseTree data structure is returned
    Tokens
    Each token has a type and corresponding value.
    Tokens can have the following types and possible values:
    Token Type Value
    keyword
    symbol
    integerConstant A decimal integer in the range 0..32767
    stringConstant A sequence of characters not including double quote or newline
    identifier A sequence of letters, digits, and underscore ( ), not starting with a digit.
    We can read the type of the token with the Token.getType() method, and its value with
    Token.getValue()
    You can assume that all tokens have been correctly tokenized (i.e. you will not have to check for
    and handle bad tokens)
    Parse Trees
    Each node in the ParseTree has a type, a value, and a list of children (parse trees nested inside
    this tree).
    Assignment 7
    3/13
    When creating a ParseTree, we set the type and value in the constructor. We can then add
    parse trees via the ParseTree.addChild(ParseTree) method. If needed, we can read the type of
    the ParseTree with the ParseTree.getType() method, and its value with ParseTree.getValue() .
    To review the structure of a ParseTree object, it can be printed; this will output a human
    readable representation.
    ParseTrees can have the following types which correspond with a set of grammar rules:
    Parse Tree
    Type
    Grammar Rule
    class
    classVarDec
    subroutine
    parameterList
    subroutineBody
    varDec
    statements where statement matches the following rule:
    letStatement
    ifStatement
    whileStatement
    doStatement
    Assignment 7
    4/13
    returnStatement
    expression
    Note the addition of the skip keyword
    term
    expressionList
    Which match the methods we're implementing.
    They can also have the same types as listed above for Tokens (and Tokens can be added
    as children to ParseTrees via typecasting)
    You may have noticed that some grammar elements shown above and in the Jack
    WX:codinghelp

kidukokr
1 声望0 粉丝