/** * Interpreter.java * * A skeleton of the interpreter for the "straight-line" language of * Appel chapter 1. * Programs to be interpreted are declared as abstract syntax trees in * the Program class. * * @author Dennis Brylow * @version 1.1 */ public class Interpreter{ private boolean debug = false; java.util.Hashtable table = new java.util.Hashtable(); public static void main(String[] args) { Interpreter interpreter = new Interpreter(); System.out.println("Evaluating program."); interpreter.visit(new Program().program); } //////////////////////////////// // Visit methods. // // This is where all the REAL // // interpreter action takes // // place. // //////////////////////////////// ///////////////////////////////////////// // Stm parent class. // // See Appel, Section 1.3. // ///////////////////////////////////////// int visit(Stm stm) { if (debug) System.err.println("DEBUG: visit(Stm)"); if (stm instanceof CompoundStm) return this.visit((CompoundStm)stm); else if (stm instanceof AssignStm) return this.visit((AssignStm)stm); else if (stm instanceof PrintStm) return this.visit((PrintStm)stm); else { System.err.println("ERROR: Unknown Stm concrete class - " + stm); return -1; } } ///////////////////////////////////////// // Stm -> Stm ; Stm (CompoundStm) // // See Appel, Section 1.3. // ///////////////////////////////////////// int visit(CompoundStm stm) { if (debug) System.err.println("DEBUG: visit(CompoundStm)"); // Interpreter code return 0; } ///////////////////////////////////////// // Stm -> id := Exp (AssignStm) // // See Appel, Section 1.3. // ///////////////////////////////////////// int visit(AssignStm stm) { if (debug) System.err.println("DEBUG: visit(AssignStm)"); // Interpreter code return 0; } ///////////////////////////////////////// // Stm -> print ( ExpList ) (PrintStm) // // See Appel, Section 1.3. // ///////////////////////////////////////// int visit(PrintStm stm) { if (debug) System.err.println("DEBUG: visit(PrintStm)"); // Interpreter code return 0; } ///////////////////////////////////////// // Exp parent class. // // See Appel, Section 1.3. // ///////////////////////////////////////// int visit(Exp exp) { if (debug) System.err.println("DEBUG: visit(Exp)"); // Interpreter code return 0; } ///////////////////////////////////////// // Exp -> id (IdExp) // // See Appel, Section 1.3. // ///////////////////////////////////////// int visit(IdExp exp) { if (debug) System.err.println("DEBUG: visit(IdExp)"); // Interpreter code return 0; } ///////////////////////////////////////// // Exp -> num (NumExp) // // See Appel, Section 1.3. // ///////////////////////////////////////// int visit(NumExp exp) { if (debug) System.err.println("DEBUG: visit(NumExp)"); // Interpreter code return 0; } ///////////////////////////////////////// // Exp -> Exp Binop Exp (OpExp) // // See Appel, Section 1.3. // ///////////////////////////////////////// int visit(OpExp exp) { if (debug) System.err.println("DEBUG: visit(OpExp)"); // Interpreter code return 0; } ///////////////////////////////////////// // Exp -> ( Stm , Exp ) (EseqExp) // // See Appel, Section 1.3. // ///////////////////////////////////////// int visit(EseqExp exp) { if (debug) System.err.println("DEBUG: visit(EseqExp)"); // Interpreter code return 0; } ///////////////////////////////////////// // ExpList parent class. // // See Appel, Section 1.3. // ///////////////////////////////////////// int visit(ExpList list) { if (debug) System.err.println("DEBUG: visit(ExpList)"); // Interpreter code return 0; } ///////////////////////////////////////////// // ExpList -> Exp , ExpList (PairExpList) // // See Appel, Section 1.3. // ///////////////////////////////////////////// int visit(PairExpList list) { if (debug) System.err.println("DEBUG: visit(PairExpList)"); // Interpreter code return 0; } ///////////////////////////////////////// // ExpList -> Exp (LastExpList) // // See Appel, Section 1.3. // ///////////////////////////////////////// int visit(LastExpList list) { if (debug) System.err.println("DEBUG: visit(LastExpList)"); // Interpreter code return 0; } } // Interpreter