import java.util.Map;
import java.util.HashMap;

/**
 * Class that models the stack segment of memory.
 *   @author Dave Reed
 *   @version 2/8/15
 */
public class ActivationRecord {
    private Map<Token, DataValue> varTable;
    private ActivationRecord parent;
    
    /**
     * Constructs an empty activation record.
     */
    public ActivationRecord() {
    	this(null);
    }
    
    /**
     * Constructs an empty activation record with specified parent.
     */
    public ActivationRecord(ActivationRecord parent) {
    	this.varTable = new HashMap<Token, DataValue>();
    	this.parent = parent;
    }
    
    /**
     * Stores a data value in the activation record.
     * @param variable the variable name the value is being stored under
     * @param val the data value (either an integer or a String)
     */
    public void store(Token variable, DataValue val) {
    	this.varTable.put(variable,  val); 	
    }
    
    /**
     * Looks up the value associated with a variable in the stack.
     * @param variable the variable name being looked up
     * @return the data value for that variable (either an integer or a String)
     */
    public DataValue lookup(Token variable) {
    	return this.varTable.get(variable);
    }
    
    public ActivationRecord getParent() {
    	return this.parent;
    }
    
    public void setParent(ActivationRecord newParent) {
    	this.parent = newParent;
    }
}
