diff options
author | Alfie Eagleton <67986414+TheAlfanator@users.noreply.github.com> | 2021-11-03 16:56:38 +0000 |
---|---|---|
committer | Alfie Eagleton <67986414+TheAlfanator@users.noreply.github.com> | 2021-11-03 16:56:38 +0000 |
commit | 85345d7d80eeb950ab64633ae1cb1f1c5dc87269 (patch) | |
tree | b353c985d4cdf51517a907efd9c6968a62db5655 /code/Interpreter2/src/Interpreter/Environment.java | |
parent | 85e2726ddedd2981425c5ac07f7257bce1a6ddbf (diff) | |
download | esotericFORTRAN-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.java | 30 |
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(); + } +} |