|
CMSC 330, Summer 2016Organization of Programming LanguagesProject 4 Part B - Small C InterpreterErrata:IntroductionIn project 4 Part A, you parsed SmallC code. In this part, you will write an interpreter for SmallC. Your interpreter can execute the SmallC code represented as an AST, which is generated by the parser in part A. This is a new project. If you find any error in the description or in the test files, report it to the instructor. Make sure you check the piazza announcements and errata section of the project periodically. Getting StartedDownload the following archive file p4b.zip and extract its contents.Along with files used to make direct submissions to the submit server (submit.jar, .submit, submit.rb), you will find the following project files:
SmallC InterpreterPut your solution to this part in the to do section of file evalate.ml. Your task is to write an interpreter for SmallC program, which in this case will be a function that evaluates a SmallC abstract syntax tree (AST). What you will do: You will write a function eval that, given an environment and an AST, executes the SmallC function corresponding to that AST in the given environment. The type of eval is env -> ast ->env, where the first argument env is an environment, the second is the AST, and the result is an environment. The environment can be (string * value) list or (string, value_type) Hashtbl. It holds all defined variables and their values. You can use OCaml HashTbl module. When you implement your interpreter:
Note that what you will implement for this part corresponds very closely to the operational semantics for OCaml-like programs give in lecture, so that may serve as a good reference (and this project may serve as a good way to understand that lecture better). For example, int main(){
int a;
a = 10;
int b;
b = 1;
int c;
c = a + b;
printf(c);
}
output is 11 Testing and SubmissionWe will test your project by calling your parsing and evaluation functions directly, so be sure to give those functions the types we expect, as given above. You can work on the interpreter and parser in any order, we will test each part independently.All your code for this project should be in one file, evaluate.ml. You also have to iclude the smallc.ml from your project 4A. Solution must include eval.ml, smallc.ml, and evaluate.ml. You can submit your project in two ways:
Academic IntegrityThe Campus Senate has adopted a policy asking students to include the following statement on each assignment in every course: "I pledge on my honor that I have not given or received any unauthorized assistance on this assignment." Consequently your program is requested to contain this pledge in a comment near the top. Please carefully read the academic honesty section of the course syllabus. Any evidence of impermissible cooperation on projects, use of disallowed materials or resources, or unauthorized use of computer accounts, will be submitted to the Student Honor Council, which could result in an XF for the course, or suspension or expulsion from the University. Be sure you understand what you are and what you are not permitted to do in regards to academic integrity when it comes to project assignments. These policies apply to all students, and the Student Honor Council does not consider lack of knowledge of the policies to be a defense for violating them. Full information is found in the course syllabus---please review it at this time. [an error occurred while processing this directive] Copyright NoticeThis course project is copyright of Dr. Anwar Mamat. ©Anwar Mamat [2016]. All rights reserved. Any redistribution or reproduction of part or all of the contents in any form is prohibited without the express consent of the author. |