package table;

import sexpression.SExpression;

public class ExecutionContext {

    private static ExecutionContext uniqueInstance = new ExecutionContext();

    public static ExecutionContext getInstance() {
        return uniqueInstance;
    }

    private SymbolTable scope;

    private ExecutionContext() {
        this.scope = new SymbolTable();
    }

    public SymbolTable getScope() {
        return scope;
    }

    public void setScope(SymbolTable scope) {
        this.scope = scope;
    }

    public void clearContext() {
        this.scope = new SymbolTable();
    }

    public SExpression lookupSymbolValue(String symbolName) {
        for (SymbolTable t = scope; t != null; t = t.getParent())
            if (t.contains(symbolName))
                return t.get(symbolName);

        return null;
    }

}
