Docsity

CS421 Machine Problem Set 5 at UIUC, Department of Computer Science, Assignments of Computer Science

Toggle sidebar
bg1
UIUC, Department of Computer Science Spring 2006
CS421 Programming Languages Machine Problem Set 5
Machine Problem Set 5
Assigned: April 03, 2006
Due: April 21, 2006 9:00pm
Objectives and Background
Upon completion of this MP, you should understand:
•How to create your own types, and how they interact with data abstraction boundaries.
•How to write interpreters for object-oriented languages
Problem 1
In this problem, you will add the ability to define your own types to a (provided) typed
interpreter.
The suggested steps are:
•Make sure you understand the provided code, especially the way letrec works. It is
similar to the interpreter you worked with in the previous MP.
•Add a typedef-record to the type-environment datatype, modify apply-tenv to ignore
typedef-records, and add a function find-typedef to map type names to types by search-
ing through the environment.
•Add lettype to the grammar definition.
•Modify expand-type-expression (and expand-type-expressions) to convert new type-
expressions to the actual types.
•Extend type-of-expression to handle lettype-exp. This is the biggest change you have
to make. This must check the expression types actually match the declared types. You
should treat the new type as the implementation type in the function definitions of
lettype, and as a new atomic type in the body of lettype.
1
pf3

Partial preview of the text

Download CS421 Machine Problem Set 5 at UIUC, Department of Computer Science and more Assignments Computer Science in PDF only on Docsity!

UIUC, Department of Computer Science Spring 2006 CS421 Programming Languages Machine Problem Set 5

Machine Problem Set 5

Assigned: April 03, 2006 Due: April 21, 2006 9:00pm

Objectives and Background

Upon completion of this MP, you should understand:

  • How to create your own types, and how they interact with data abstraction boundaries.
  • How to write interpreters for object-oriented languages

Problem 1

In this problem, you will add the ability to define your own types to a (provided) typed interpreter. The suggested steps are:

  • Make sure you understand the provided code, especially the way letrec works. It is similar to the interpreter you worked with in the previous MP.
  • Add a typedef-record to the type-environment datatype, modify apply-tenv to ignore typedef-records, and add a function find-typedef to map type names to types by search- ing through the environment.
  • Add lettype to the grammar definition.
  • Modify expand-type-expression (and expand-type-expressions) to convert new type- expressions to the actual types.
  • Extend type-of-expression to handle lettype-exp. This is the biggest change you have to make. This must check the expression types actually match the declared types. You should treat the new type as the implementation type in the function definitions of lettype, and as a new atomic type in the body of lettype.

Example:

(run " lettype ff = (int -> int) ff zero-ff () = proc (int k) 0 ff extend-ff (int k, int val, ff old-ff) = proc (int k1) if zero?(-(k1,k)) then val else (old-ff k1) int apply-ff ( ff f, int k) = (f k) in let ff1 = (extend-ff 1 11 (extend-ff 2 22 (zero-ff))) in (apply-ff ff1 2)" ) 22

Problem 2

This problem is only required for all the graduate students. Undergraduates may do this problem for extra credit. Exercise 5.22 in the book.

Problem 3

Exercise 5.23 In the book. We will not test the case where a static field in the derived class overrides a field in the base class. A solution can be written by adding/changing around 25 lines of code to the starter code. Example:

(run " class c1 extends object static next serial number = 5 field my serial number method get serial number () my serial number method initialize () begin set my serial number = next serial number; set next serial number = add1(next serial number) end class c2 extends c static next to last ser num = sub1(next serial number) method get next to last ser num() next to last ser num let o1 = new c1() o2 = new c1() o3 = new c2()