In this 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 2, 3, and 4. (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 lecture 4. 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)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.End
Class list(init)
L := init;
Cons := proc(x) return cons(x,L) end;
Car := proc() return car(L) end;
Cdr := proc() return cdr(L) end;
end;
L := list([]);
L.Cons(3);
L.Cons(2);
L.Cons(1);
x := L.Car(); // = 1
M := L.Cdr(); // = [2,3]
Inheritance should be supported using the syntax
Class name (p1,...,pn) : supernameThere 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.End