@Override public void execute() { if (table.exists(name)) stack.push(table.get(name)); else { Errors.error("Variable does not exist.", table); } }
/** * Run a "compiled" program by executing in order each instruction contained therein. Report on * the final size of the stack (should normally be empty) and the contents of the symbol table. * * @param program a list of Machine instructions */ public static void execute(List<Instruction> program) { reset(); System.out.println("Executing compiled code..."); for (Instruction instr : program) { instr.execute(); } System.out.println( "Machine: execution ended with " + stack.size() + " items left on the stack."); System.out.println(); table.dump(); }
/** Run the microsteps for the STORE instruction. */ @Override public void execute() { table.put(this.name, stack.pop()); }