summaryrefslogtreecommitdiffstats
path: root/code/simpleSableCCCalulator
diff options
context:
space:
mode:
Diffstat (limited to 'code/simpleSableCCCalulator')
-rw-r--r--code/simpleSableCCCalulator/sableCCCalculator/SymbolTable.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/code/simpleSableCCCalulator/sableCCCalculator/SymbolTable.java b/code/simpleSableCCCalulator/sableCCCalculator/SymbolTable.java
new file mode 100644
index 0000000..435e48d
--- /dev/null
+++ b/code/simpleSableCCCalulator/sableCCCalculator/SymbolTable.java
@@ -0,0 +1,48 @@
+package sableCCCalculator;
+import java.util.HashMap;
+import sableCCCalculator.types.*;
+
+public class SymbolTable {
+
+ public interface SymbolTableIndex {}
+
+ public abstract class Name implements SymbolTableIndex {
+ protected String name;
+
+ String getName() {
+ return this.name;
+ }
+ }
+
+ public class Constant implements SymbolTableIndex {
+ int index;
+
+ public Constant(int index) {
+ this.index = index;
+ }
+ }
+
+ public class Variable extends Name {
+ public Variable(String name) {
+ this.name = name;
+ }
+ }
+
+ private HashMap<SymbolTableIndex, Type> theSymbolTable = new HashMap<>();
+
+ public SymbolTableIndex addConstant(Type item) {
+ SymbolTableIndex index = new Constant(item.hashCode());
+ theSymbolTable.put(index, item);
+ return index;
+ }
+
+ public SymbolTableIndex addVariable(Type item, String name) {
+ SymbolTableIndex index = new Variable(name);
+ theSymbolTable.put(index, item);
+ return index;
+ }
+
+ public Type get(SymbolTableIndex index) {
+ return theSymbolTable.get(index);
+ }
+}