// StaticTypeCheck.java // // This file is from Tucker and Noonan's web site (Appendix B and Chapter 3), // except that the following changes have been made: // (1) Modifications to take advantage of the use of Java Generics in the // AbstractSyntax.java file from the previous lab. // (2) Modification of TypeMap to also use Java Generics. // (3) Addition of a main method to run the type checker. import java.util.*; import java.io.IOException; // Static type checking for Jay is defined by the functions // V and the auxiliary functions typing and typeOf. These // functions use the classes in the Abstract Syntax of Jay. class TypeMap extends Hashtable { // TypeMap is implemented as a Java Hashtable. // It has a 'display' method added to facilitate experimentation. public void display () { System.out.print("{ "); for (Enumeration e = this.keys(); e.hasMoreElements(); ) { Variable key = e.nextElement(); Type t = this.get(key); System.out.print("<" + key.id + ", " + t.id + ">"); if (e.hasMoreElements()) System.out.print(", "); } System.out.println(" }"); } } class StaticTypeCheck { public TypeMap typing (Declarations d) { // put the variables and their types into a new // Dictionary (symbol table) and return it. TypeMap map = new TypeMap(); for (int i=0; i