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 librariesmodules 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 recursivedescent parser uses the scanner, how it constructs the AST, and how the indented methods of the AST classes work.
The classes ProgramAST, IdentifierAST represent the AST. Read some of these classes and understand the purpose of the methods initrepr and indented. Introduce a new class IfElseAST for ifthenelseend statements and implement the methods initrepr and indented. The class will be similar to IfAST. The method IfElseAST.indented should output the label IfElse followed by the condition, the thenpart and the elsepart.
The functions program, identifier implement the recursivedescent parser. Read and understand this part of the code. Extend the function ifstatement so that it can parse both ifthenend and ifthenelseend statements. The function should construct the appropriate syntax tree in each case.
Extend the recursivedescent 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 WriteAST.
Extend the recursivedescent 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 ReadAST.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
