Extra Credit Assignment 2

CS 550 Programming Languages
Instructor: Jeremy Johnson 

Object Oriented Mini Language (100 points)

In this extra credit assignment you will implement an object oriented (classes and methods and inheritence) version of the mini language.

Consider the extended mini language and interpreter from assignment 6. (i.e. lists are supported and functions are first class values that can be assigned to variables, passed to functions and returned by function) and nested scope is supported in a similar way to the scheme interpreter discussed in the lecture on the scheme interpreter. Environments are stored as a list of frames, where frames contain a list of bindings. Static scope is used so functions store the environment in which they were defined.

In this assignment you are to further extend the language and interpreter to support classes and object oriented programming. A class definition should have the following syntax.


class name (p1,...,pn)
  <stmt-list>
end

The statement list defines the methods (method_1,...,method_n) and attributes in the class. The class definition provides a constructor with parameters p1,...,pn, called by name(p1,...,pn). The constructor returns an object which can access the methods and attributes of the class initialized by the constructor using the familiar dot notation. Class methods can access the attributes. Here is an example:


       class list(init)
       L := init;
       Cons := proc(x) L := cons(x,L); return := L end;
       Car := proc() return := car(L) end;
       Cdr := proc() return := cdr(L) end;
       end;

       L := list([]);
       T := L.Cons(3);
       T := L.Cons(2);
       T := L.Cons(1);
       x := L.Car();  // = 1
       M := L.Cdr(); // = [2,3]

Note, you should probably allow lower- and upper-case letters in your identifiers. In the example, above the cons method modified the attribute L. It is not necessary that it return a value, but I have it returning a value for consistency. This has the disadvantage of having to assign the result to a temporary variable T even though it is not used. It would be possible to have an expression statement that ignores the result so that this is not necessary. I am not sure which is better.

Note, also, that there are procs with no formal parameters.

Inheritance should be supported using the syntax

class name (p1,...,pn) : supername
  <stmt-list>
end

There is no multiple inheritance in this language; Only single inheritance must be supported. Objects in the subclass (derived class) should be able to access methods and attributes from its superclass, however, they can be redefined in the subclass.

What to do

Modify the mini language interpreter from Extra Credit Assignment 1 (the one with support for first class functions) to

  1. A description of the syntax and semantics of your object oriented mini language
  2. An overview of your implementation
  3. Documented source code
  4. Sample input and output files

You must test your interpreter on several mini language programs which define and use classes (including inheritance).

How to submit

Students should submit their solution electronically via Blackboard Vista. Extra credit assignments must be done individually. You will only be graded on the parts that are working.

There were too many decisions to pin down, so, we're going to rely on your documentation, and your test cases.

There should be just a few short test cases. At a minimum:

If there are other features you'd like to demonstrate, great. Describe them well in your documentation.

The README file should describe all files that are included, contain instructions how to build [you should use make or Ant to build you program and make sure it successfully builds and runs on the CS compute server tux] and use the code, and outline how the code works. The README file should also contain a list of all group members and the group leader for the submitted assignment. You should also indicate how you tested your code. If your program is not working, you should clearly state this in the README file. Code should be documented (clear specifications and comments for any tricky parts of the code).

Since you can do this in a number of languages, submit a makefile . Here is a sample makefile. Please ask for help w/makefiles.

Submit the following files to Bb Vista:

Submit a gzipped tar file, called Aoom.tar.gz (the tar file should contain a directory called Af which contains the files). The tar file should contain source code, instructions how to run your programs, sample input and output files, and a README file.

Note: Please pay attention to file names. E.g., makefile is not Makefile, and README is not README.txt.