The Interpreter

Due:
11:00 pm, Wednesday May 5, 2021

Max grace days: 0

Overview

For this assignment you will write an interpreter. Among other things, this involves implementing the operational semantics specification of Cool. You will track enough information to generate legitimate run-time errors (for example, dispatch on void). You do not have to worry about "malformed input" because the semantic analyzer has already ruled out bad programs.

The Specification

You must create three artifacts:

  1. A program that takes a single command-line argument (for example, file.cl-type). That argument will be an ASCII text Cool class map, implementation map, and AST file. Your program must execute (that is, interpret) the Cool program described by that input. If your program is called interp, invoking interp file.cl-type should yield the same output as cool file.cl. Your program will consist of a number of OCaml files.

    You will only be given .cl-type files from programs that pass the semantic analysis phase of the reference interpreter. You are not responsible for correctly handling (1+\"hello\") programs.

  2. A plain ASCII text file called README describing your design decisions. See the grading rubric. A few paragraphs should suffice.

Error Reporting

To report an error, write the string

ERROR: line_number: Exception: message

to standard output and terminate the program. You may write whatever you want in the message, but it should be fairly indicative. Example erroneous input:

class Main inherits IO {\
  my_void_io : IO ; -- no initializer => void value
  main() : Object {
    my_void_io.out_string("Hello, world.\n")
  } ;
} ;

Corresponding example error report output:

ERROR: 4: Exception: dispatch on void

Commentary

You will have to handle all of the internal functions, for example, IO.out_string.

You can do basic testing as follows:

linux> cool --type file.cl
linux> cool file.cl >& reference-output
linux> my-interp file.cl-type >& my-output
linux> diff my-output reference-output

Note that this time, whitespace and newlines matter for normal output. This is because you are specifically being asked to implement IO and substring functions.

You should implement all of the operational semantics rules in the Reference Manual. You will also have to implement all of the built-in functions on the five Basic Classes.

Getting the Assignment

The starter code for the assignment is on the Linux server at the path:

/export/home/public/schwesin/csc310/interpreter-handout

Turning in the Assignment

You must turn in a zip file containing these files:

  1. README — your README file
  2. source_files — your implementation, including
    • main.ml
    • TODO

There is a makefile provided with this assignment. To submit the assignment, execute the command:

    make submit

from within the assignment directory.

Grading Criteria

Grading (out of 100 points):

Extra Credit

You can receive extra credit for your final course grade by passing more than 50% of the test cases: