diff options
Diffstat (limited to 'main/core/runtime/Scope.java')
| -rw-r--r-- | main/core/runtime/Scope.java | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/main/core/runtime/Scope.java b/main/core/runtime/Scope.java deleted file mode 100644 index 0bf8907..0000000 --- a/main/core/runtime/Scope.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.jantuomi.interpreter.main.core.runtime; - -import com.jantuomi.interpreter.main.core.parser.datatype.DataContainer; -import com.jantuomi.interpreter.main.exception.InterpreterException; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Created by jan on 20.6.2016. - */ -public class Scope { - private Scope parent = null; - - private Map<String, DataContainer> variables = new HashMap<>(); - private Map<String, Function> functions = new HashMap<>(); - - public void addVariable(String symbol) { - variables.put(symbol, null); - } - - public void setVariableValue(String symbol, DataContainer value) { - variables.replace(symbol, value); - } - - public DataContainer resolveSymbol(String symbol, List<DataContainer> params) throws InterpreterException { - if (functions.containsKey(symbol)) { - DataContainer r = functions.get(symbol).evaluate(params); - return r; - } - if (variables.containsKey(symbol)) { - return variables.get(symbol); - } - else if (parent != null) { - return parent.resolveSymbol(symbol, params); - } - else { - return null; - } - } - - public void setParent(Scope parent) { - this.parent = parent; - } - - public void addFunction(String symbol, Function func) { - functions.put(symbol, func); - } -} |
