import java.io.*; import java_cup.runtime.*; /**** * * Test program for CSC 330 Assignment 4. The main method constructs an * EJayLexer with a FileReader. It then constructs an EJayParser, sending it * the lexer. Then it calls EJayParser.parse to obtain a parse tree and symbol * table for the input program. Then it constructs an EJayInterprerter, * sending it the memory size for the symbol table and a stack size of 10000. * Next, the test program constructs a parse tree for a parameterless * invocation of the program's main function, and sends that tree to the * interpreter's eval method. Finally, the test program dumps out the * interpreter's memory after program execution. * */ public class EJayInterpreterTest { /** * See the class comment for documentation. */ public static void main(String[] args) { TreeNode tree; SymbolTable symtab = null; // Assignment to null to such up javac try { EJayParser parser = new EJayParser( new EJayLexer(new FileReader(args[0]))); parser.initSymbolTable(500); tree = (TreeNode) parser.parse().value; symtab = parser.getSymbolTable(); EJayInterpreter interp = new EJayInterpreter(symtab.memorySize, 10000); interp.eval(buildMainCall(), symtab); interp.dumpMemory(); } catch (Exception e) { System.out.println("Exception " + e); e.printStackTrace(); } } /** * Construct the parse tree to invoke the main method. */ protected static TreeNode buildMainCall() { return new TreeNode2(sym.LEFT_PAREN, new LeafNode(sym.VOID, "main"), null); } }