import java.util.ArrayList;
import java.util.HashMap;

/**
 * Class that stores variable bindings in the SILLY language.
 *   @author Dave Reed
 *   @version 2/8/12
 */
public class Bindings {
    private HashMap<Token, Value> variableTable;

    /**
     * Constructor for objects of class Bindings
     */
    public Bindings()
    {
         this.variableTable = new  HashMap<Token, Value>();
    }
    
    /**
	 * Assigns a new value to a variable in the table.
	 *   @param var the variable (Token) to be assigned to
	 *   @param val the value to be assigned to var
	 */
	public void assign(Token var, Value val) {
	    this.variableTable.put(var, val);
	}
	
	/**
	 * Looks up the value of a variable.
	 *   @param var the variable (Token) to be looked up
	 *   @return the value associated with that variable (Exception thrown if not defined)
	 */
	public Value lookup(Token var) throws Exception {
	    if (variableTable.get(var) == null) {
	        throw new Exception("RUNTIME ERROR: Undefined variable");
	    }
	    return variableTable.get(var);
	}
}
