summaryrefslogtreecommitdiffstats
path: root/code/Interpreter2/src/Interpreter/Environment.java
diff options
context:
space:
mode:
authorAlfie Eagleton <67986414+TheAlfanator@users.noreply.github.com>2021-11-03 16:56:38 +0000
committerAlfie Eagleton <67986414+TheAlfanator@users.noreply.github.com>2021-11-03 16:56:38 +0000
commit85345d7d80eeb950ab64633ae1cb1f1c5dc87269 (patch)
treeb353c985d4cdf51517a907efd9c6968a62db5655 /code/Interpreter2/src/Interpreter/Environment.java
parent85e2726ddedd2981425c5ac07f7257bce1a6ddbf (diff)
downloadesotericFORTRAN-85345d7d80eeb950ab64633ae1cb1f1c5dc87269.tar.gz
esotericFORTRAN-85345d7d80eeb950ab64633ae1cb1f1c5dc87269.zip
New Project Working + Report
Diffstat (limited to 'code/Interpreter2/src/Interpreter/Environment.java')
-rw-r--r--code/Interpreter2/src/Interpreter/Environment.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/code/Interpreter2/src/Interpreter/Environment.java b/code/Interpreter2/src/Interpreter/Environment.java
new file mode 100644
index 0000000..d191bde
--- /dev/null
+++ b/code/Interpreter2/src/Interpreter/Environment.java
@@ -0,0 +1,30 @@
+package Interpreter;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Environment {
+ private final Map<String,Object> variableMap = new HashMap<>();
+
+ //Maybe check if variable is already defined?
+ public void defineVariable(String name,Object value){
+ variableMap.put(name, value);
+ }
+
+ public Object getVariable(String name){
+ if(variableMap.containsKey(name)){
+ return variableMap.get(name);
+ }
+ Language.displayError("Undefined Variable");
+ throw new Error();
+ }
+
+ public void assignVariable(String name,Object value){
+ if(variableMap.containsKey(name)){
+ variableMap.put(name, value);
+ return;
+ }
+ Language.displayError("Variable undefined");
+ throw new Error();
+ }
+}