/**
 * Derived class that represents an output statement in the SILLY language.
 * 
 * @author Dave Reed
 * @version 2/9/07
 */
public class Output extends Statement
{
	private Expression expr;
	
	    /**
     * Reads in an output statement from the specified program
     *   @param program the source code of the program to be read from
     */
	public void read(SourceCode program) {
	    Token keyword = program.next();
	    
	    if (!keyword.toString().equals("output")) {
	        System.out.println("SYNTAX ERROR: Malformed expression");
	        System.exit(0);
	    }
	    
	    expr = new Expression();
	    expr.read(program);
	}
	
    /**
	 * Executes the current assignment statement.
	 *   @param variables the table representing the current bindings for all variables
	 */
	public void execute(VariableTable variables) {
	    System.out.println(expr.evaluate(variables));    
	}
		
	/**
	 * Accesses the type of the current statement.
	 *   @return this statement's type, i.e., Statement.Type.OUTPUT
	 */
	public Statement.Type getType() {
	    return Statement.Type.OUTPUT;
	}
	
	/**
	 * Converts the current output statement into a String.
	 *   @return the String representation of this statement
	 */
	public String toString() {
	    return "output " + expr;    
	}
}
