summaryrefslogtreecommitdiffstats
path: root/code/Interpreter/Environment.java
diff options
context:
space:
mode:
authorAidenRushbrooke <72034940+AidenRushbrooke@users.noreply.github.com>2021-10-25 16:55:22 +0100
committerAidenRushbrooke <72034940+AidenRushbrooke@users.noreply.github.com>2021-10-25 16:55:22 +0100
commit74c5732bded6695eed3aabf125a888fbdf206a40 (patch)
treea429332a21ad595c190cae80264fbaf3bf19ed13 /code/Interpreter/Environment.java
parentcb29252f1e0d29d555fb232f39d343930fc76105 (diff)
downloadesotericFORTRAN-74c5732bded6695eed3aabf125a888fbdf206a40.tar.gz
esotericFORTRAN-74c5732bded6695eed3aabf125a888fbdf206a40.zip
Interpreter capable of handing variables
Diffstat (limited to 'code/Interpreter/Environment.java')
-rw-r--r--code/Interpreter/Environment.java30
1 files changed, 30 insertions, 0 deletions
diff --git a/code/Interpreter/Environment.java b/code/Interpreter/Environment.java
new file mode 100644
index 0000000..d191bde
--- /dev/null
+++ b/code/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();
+ }
+}