/**
 * Abstract class for representing a statement in the SILLY language.
 *   @author Dave Reed
 *   @version 2/8/12
 */
public abstract class Statement {
    public abstract void execute(Bindings bindings) throws Exception;
    public abstract Statement.Type getType();
    public abstract String toString();
    
    public static enum Type {
        OUTPUT, ASSIGNMENT, IF, QUIT
    }
    
    /**
     * Static method that reads in an arbitrary Statement.
     *   @param input the TokenStream from which the program is read
     *   @return the next Statement in the program
     */
    public static Statement getStatement(TokenStream input) throws Exception {
        Token first = input.lookAhead(); 

        if (first.toString().equals("output")) {
            return new Output(input);
        }
        else if (first.toString().equals("quit")) {
            return new Quit(input);
        }
        else if (first.toString().equals("if")) {
            return new If(input);
        }        
        else if (first.getType() == Token.Type.IDENTIFIER) {
            return new Assignment(input);
        }
        else {
            throw new Exception("SYNTAX ERROR: Unknown statement type (" + first + ")");
        }
    }
}
