import java.util.*; // ********************************************************************** // The Sym class defines a symbol-table entry; // an object that contains a name (a String) and a type (a Type). // ********************************************************************** // // Methods // ======= // // constructor // ----------- // Sym(String S) -- constructor: creates a Sym with the given name // Sym(String S, Type T) -- constructor: creates a Sym with the given name // and the given type // // accessor // -------- // name() -- returns this symbol's name // type() -- returns this symbol's type // // other // ----- // toString() -- prints the values associated with this Sym class Sym { public Sym(String S) { myName = S; } public Sym(String S, Type T) { myName = S; myType = T; } public String name() { return myName; } public Type type() { return myType; } public String toString() { return ""; } // private fields private String myName; private Type myType; } // ********************************************************************** // The FnSym class is a subclass of the Sym class, just for functions. // The myReturnType field holds the return type, and there are new fields // to hold information about the parameters. // ********************************************************************** class FnSym extends Sym { public FnSym(String S, Type T, int numparams) { super(S, new FnType()); myReturnType = T; myNumParams = numparams; } public void addFormals(LinkedList L) { myParamTypes = L; } public Type returnType() { return myReturnType; } public int numparams() { return myNumParams; } public LinkedList paramTypes() { return myParamTypes; } // new fields private Type myReturnType; private int myNumParams; private LinkedList myParamTypes; // list of Types }