The goal of this project is to modify the Core interpreter from Project 3 to now handle func:on defini:ons and func:on calls.
Your submission should compile and run in the standard environment on stdlinux. If you work in some other environment, it is your responsibility to port your code to stdlinux and make sure it works there.
You will need to modify the parser and executor func:ons to accommodate func:on calls. You should not need to modify the scanner for this project, but you are allowed to so
if you want. You also do not need to modify the exis:ng printer func:ons or add printer func:ons for the new parts of the grammar, but it might help you check your work and troubleshoot bugs if you do implement print func:ons for the new classes.
On the last page is the modified Core grammar to allow func:ons. Here is an example of a Core program that defines and calls a func:on:
For simplicity you may assume func:ons will only accept array variables as actual pa- rameters, and our parameter passing will be done with call by sharing – x and a point to the same record, y and b point to the same record. In this example, as output we should see 3, then 1, then 2.
Your interpreter should support recursion. This will require implemen:ng a call stack. 1
Input to your interpreter
The input to the interpreter will be same as the input from Project 3, a .code and a .data _le
程序代写 CS代考 加QQ: 749389476
Output from your interpreter
All output should go to stdout. This includes error messages – do not print to stderr.
The parser func:ons should only produce output in the case of a syntax error. You
should implement checks to ensure the modified grammar is being followed.
For the executor, each Core output statement should produce an integer printed on a
new line, without any spaces/tabs before or aOer it. Other than that, the executor func:ons should only have output if there is an error.
Invalid Input – Syntax Checks
For this project you will need to modify some exis:ng parse func:ons, and add new classes and new parse func:ons. Your parse func:ons should ensure the syntax rules of the modified grammar are being followed.
Invalid Input – Seman,c Checks
With the addi:on of func:ons to the language you will need to perform some seman:c checks. You DO NOT need to include the seman:c checks from project 2, you only need to handle the new ones described here. You can perform the seman:c checks during parsing, during execu:on, or separately.
Here are the seman:c rules you should be checking:
1. Every func:on should have a unique name (no overloading).
2. Each func:on call has a valid target.
3. Your parser should check that the formal parameters of a func:on are dis:nct from each other. You do not need to implement checks to verify the arguments are all
dis:nct or are all array variables, we will consider using integer variables as arguments
as undefined by the language.
Implementa,on Sugges,ons
Here are my sugges:ons for how to implement the project:
1. Focus first on modifying/crea:ng parse func:ons, and add new print func:ons to verify your modified parser. There is no point in even thinking about the execu:on unless
you are confident in your parse tree!
2. You will need a stack of \frames” to allow recursion. A frame should be the same as your local memory from project 3. You then need a stack of frames, so if you used my sugges:ons for project 3 then for project 4 you will have a stack of stack of maps!
3. Implement the seman:c checks last.
4. During execu:on you will need a way to \jump” across the tree, or in other words when I am in the StmtSeq and I want to call a func:on named \Foo”, I need some
way of finding the part of the tree where \Foo” is defined in the DeclSeq.
5. The hardest part will be implemen:ng the execute func:on for the func:on call. To execute a func:on call, you need to:
(a) Create a new frame
(b) Create the formal parameters in this frame and copy over the values of the argu- ments
(c) Push the frame to the top of the stack
(d) Execute the body (StmtSeq) of the func:on
(e) Pop the frame o_ the stack
Tes,ng Your Project
I will provide some test cases. The test cases I will provide are rather weak. You should do addi:onal tes:ng tes:ng with your own cases. Like the previous projects, I will provide a tester.sh script to help automate your tes:ng.
Please note this is a language like C or Java where whitespaces have no meaning, and whitespace can be
inserted between keywords, identifiers, constants, and specials to accommodate programmer style. This
grammar does not include formal rules about whitespace because that would add immense clutter.
Recall epsilon is the empty string.
| procedure ID is begin
| if
Programming Help
Code Help, Add WeChat: cstutorcs