Homework 4
Goal
Implement the Type Checking program on p. 127 (both parts (a) and (b)).
Due November 11 before class. Start EARLY!!
Help material
You will need to refer to the following:
- Chapter 5 of the book.
- Help files in the directory type. These
are slightly different from the ones Appel provides. The help files include
the bytecodes for my lexical analyzer and my parser that produces abstract syntax trees. Use them if yours do not work.
Helpful Hints
- I have added some functionality to the files in the Types package,
and the class Entry and its subclasses, that you might find useful.
- P.120 of the book has a couple of bad typos in the code for the
class Semant. The code should be:
package Semant;
import ErrorMsg.ErrorMsg;
public class Semant {
Env env;
public Semant (ErrorMsg err) { this (new Env(err)); }
Semant (Env env) { this.env = env; }
ExpTy transVar (Absyn.Var v) { ... }
ExpTy transExp (Absyn.Exp e) { ... }
Translate.Exp transDec (Absyn.Dec d) { ... }
Types.Type transTy (Absyn.Ty t) { ... }
}
- The code for variable declarations on p. 124 should be:
Translate.Exp transDec (Absyn.VarDec d) {
env.venv.put (d.name, new VarEntry (transExp(d.init).ty));
return null;
}
The code for type declarations on the same page should be:
Translate.Exp transDec (Absyn.TypeDec d) {
env.tenv.put(d.name, transTy(d.ty));
return null;
}
The code for function declarations on the next page (p.125) has an extra
occurrence of `null' as the first argument to VarEntry in the first
line of the for-loop.
Deliverables
Due date is November 11 before class. Turn in at
least the following two files: Semant/Semant.java and
Semant/Env.java. Test your type checker on the 49 testcases that Appel
provides with the book's software.
For extra credit, do Exercise 5.3 on p.129.
Page visited
times since September 14, 1998.
Last modified: 10/08/1998 22:19:35
sabry@cs.uoregon.edu