Question: Deliverables Please download the parser template. Note: You must not import any libraries / modules besides those already imported in the template. Copy the changes

Deliverables
Please download the parser template. Note: You must not import any libraries/modules besides those already imported in the template.
Copy the changes to the scanner template you made in the previous quiz into the parser template. Note that the scanner is now called from the parser, which is different to how it was tested in the previous quiz. This might uncover errors in your scanner which went unnoticed so far; you will need to fix such errors.
Read and understand the parser template. In particular, you need to understand how it represents the abstract syntax tree (AST), how the recursive-descent parser uses the scanner, how it constructs the AST, and how the indented methods of the AST classes work.
The classes Program_AST, ..., Identifier_AST represent the AST. Read some of these classes and understand the purpose of the methods __init__,__repr__, and indented. Introduce a new class If_Else_AST for if-then-else-end statements and implement the methods __init__,__repr__, and indented. The class will be similar to If_AST. The method If_Else_AST.indented should output the label If-Else followed by the condition, the then-part and the else-part.
The functions program, ..., identifier implement the recursive-descent parser. Read and understand this part of the code. Extend the function if_statement so that it can parse both if-then-end and if-then-else-end statements. The function should construct the appropriate syntax tree in each case.
Extend the recursive-descent parser by the new statement write e that prints the value of the expression e. To this end, modify the function statement and introduce a new function write which constructs the syntax tree using Write_AST.
Extend the recursive-descent parser by the new statement read i that reads a value and stores it in the variable with identifier i. To this end, modify the function statement and introduce a new function read which constructs the syntax tree using Read_AST.

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 Programming Questions!