[SOLVED] Ocaml-compiler: CMSC 330 project 4 Part B Small C Interpreter

$25

File Name: Ocaml-compiler:_CMSC_330_project_4_Part_B__Small_C_Interpreter.zip
File Size: 584.04 KB

5/5 - (1 vote)

Project 4 Part B Small C Interpreter

Due 11:59pm April 12th, 2016 (Tuesday)

Errata:

  • Updated on 04/06: When you submit your solution evaluate.ml, you also have to include the parser file smallc.ml from your peoject 4A.
  • Updated on 04/07: Some students modified eval.ml to use different data structures for the environment. Now, you will have to submit eval.ml file with your solution. Solution must include eval.ml, smallc.ml, and evaluate.ml.

Introduction

In 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 Started

Download the following archive file p4b.zipand 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 Interpreter

Put your solution to this part in the to do section of file evalate.ml.

Your task is to write an interpreterfor 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 environmentand 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:

  • Variables must be defined and initialized before they are used. Your interpreter throws exception when a variables is used before it is defined and initialized. You can do this by looking up the variable from your environment.
  • A variable cannot be defined twice. Your interpreter throws exception if a variable is defined second time. You can do this by checking if a variable exists in your environment.
  • Only printf statement produces output. printf(x) is equivalent to printf(%d
    ,x) in C. Any SmallC code with no printf does not produce output.

Notethat what you will implement for this part corresponds very closely to the operational semantics for OCaml-like programsgive 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 Submission

We 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 fil, evaluate.ml. You also have to iclude the smallc.ml from your project 4A. You can submit your project in two ways:

  • Submit your smallc.ml and evaluate.ml files directly to the submit server .
    • You can submit multiple files by putting the files in a .zip archive first. On Windows you can select the two files, then right click to select the Send to->Compressed (zipped) Folder option to create a .zip archive. Once your files are in a single zip archive, bring up the upload dialog box by clicking on the submit link in the column web submission. Select your archive file using the Browse button, then press the Submit project! button.
    • The submit server now allows multiple files (from the same directory) to be selected. Bring up the upload dialog box by clicking on the submit link in the column web submission. Browse to the directory containing your project files, then click on both SmallCTest.txt and SmallC.ml. Now press the Submit project! button.

  • You may also submit directly by executing a Java program on a computer with Java and network access. Use the submit.jar file from the archive p4b.zip , To submit, go to the directory containing your project, then either execute submit.rb by typing:
    ruby submit.rb
    or use the java jar directly using the following command:

    java -jar submit.jar
    You will be asked to enter your class account and password, then all files in the directory (and its subdirectories) will be put in a jar file and submitted to the submit server. If your submission is successful you will see the message:

    Successful submission #received for project 4

Academic Integrity

The 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 readthe academic honesty section of the course syllabus. Any evidenceof impermissible cooperation on projects, use of disallowed materials or resources, or unauthorized use of computer accounts, will be submittedto 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 syllabusplease review it at this time. [an error occurred while processing this directive]

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] Ocaml-compiler: CMSC 330 project 4 Part B Small C Interpreter
$25