Starting from:

$34.99

CSE-PPL Assignment 2- AST Generator Solution



Contents
1 Specification 2
2 Submission 3
3 Change Log 3


After completing this assignment, you will be able to
• explain the stucture of parser generated by ANTLR
• manipulate (traverse, create) on tree, which has different types of node, using Visitor
• write a short program in Python to generate intermediate code (AST) for a valid MP program
1 Specification
A parser will check if the input is grammatically correct or not. If the input is grammatically wrong, an error message is released. This is what you did in the assignment 1. In the case the input is grammatically correct, an intermediate code is generated. This is the requirement of this assignment. As AST is selected to be the intermediate code, you are required to write an AST generator for a program written in BKOOL. To complete this assignment, you need to watch the lecture of AST to:
• investigate the structure of a parser generated by ANTLR • try to find out how to generate an AST from a parse tree.
• investigate the AST classes defined in Python.
• modify ASTGeneration.py to generate an AST.
• check your code to make sure it right.
To complete this assignment, you need to:
• download initial code (assignment2.zip) and unzip it.
• copy your BKOOL.g4, your solution of assignment 1, into folder src/main/mp/parser.
• have a look at folder src/main/bkool/utils in the code of assignment 2 where there are 2 files AST.py and Visitor.py. In these two files, just only AST.py is used in this assignment while the other file will be used in the next one. AST.py defines all classes in AST which is the output of this assignment. You are NOT allowed to modify all these files.
• modify ASTGeneration.py in folder src/main/bkool/astgen to generate AST from a parse tree, i.e. the result of assignment 2, generated from ANTLR.
• modify ASTGenSuite.py in folder src/test/ to create 100 tests in total for this assignment.
2 Submission
This assignment requires you submit your code in theses files: BKOOL.g4, ASTGeneration.py and ASTGenSuite.py together with the files generated in folder target or its subfolder. BKOOL.g4 is often modified to complete this assignment but even when it is not modified, it must also be submitted.
All the testcases for this assignment are correctly grammatically correct.
The submission files must be in plain text. Note that you must NOT compress your files when submit them.
3 Change Log

More products