/** * Abstract class for representing a statement in the SILLY language. * * @author Dave Reed * @version 2/9/07 */ public abstract class Statement { public abstract void read(SourceCode program); public abstract void execute(VariableTable variables); public abstract Statement.Type getType(); public abstract String toString(); public static enum Type { OUTPUT, IF, ASSIGNMENT } /** * Static method that reads in an arbitrary Statement. * @param program the Source code of the program to be read from * @return the next Statement in the program */ public static Statement getStatement(SourceCode program) { Statement stmt; Token lookAhead = program.peek(); if (lookAhead.toString().equals("output")) { stmt = new Output(); } else if (lookAhead.toString().equals("if")) { stmt = new If(); } else if (lookAhead.getType() == Token.Type.IDENTIFIER) { stmt = new Assignment(); } else { System.out.println("SYNTAX ERROR: Unknown statement type"); System.exit(0); stmt = new Output(); } stmt.read(program); return stmt; } }