package Compiler;
import java.util.HashMap;
import java.util.Map;

public class Environment {
    private final Map<String,Object> variableMap = new HashMap<>();

    //Define a variable inside the current environment
    //Maybe check if variable is already defined?
    public void defineVariable(String name,Object value){
        variableMap.put(name, value);
    }

    //Get a variable if it is defined, or report an error
    public Object getVariable(String name){
        if(variableMap.containsKey(name)){
            return variableMap.get(name);
        }
        Language.displayError("Undefined Variable");
        throw new Error();
    }

    //Assign a value to an existing variable
    public void assignVariable(String name,Object value){
        if(variableMap.containsKey(name)){
            variableMap.put(name, value);
            return;
        }
        Language.displayError("Variable undefined");
        throw new Error();
    }
}