From 33359862f5455dc7003ebbe5357c611298042cee Mon Sep 17 00:00:00 2001 From: "chris.sutcliffe" Date: Mon, 29 Nov 2021 16:46:56 +0000 Subject: clean repo (remove code dir, add UI dir) --- .../sableCCCalculator/SymbolTable.java | 63 ---------------------- 1 file changed, 63 deletions(-) delete mode 100644 code/simpleSableCCCalulator/sableCCCalculator/SymbolTable.java (limited to 'code/simpleSableCCCalulator/sableCCCalculator/SymbolTable.java') diff --git a/code/simpleSableCCCalulator/sableCCCalculator/SymbolTable.java b/code/simpleSableCCCalulator/sableCCCalculator/SymbolTable.java deleted file mode 100644 index 992e873..0000000 --- a/code/simpleSableCCCalulator/sableCCCalculator/SymbolTable.java +++ /dev/null @@ -1,63 +0,0 @@ -package sableCCCalculator; -import java.util.HashMap; -import sableCCCalculator.types.*; - -public class SymbolTable { - - public interface SymbolTableIndex {} - - public abstract class Name implements SymbolTableIndex { - // can be used for functions too hopefully one day... - 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 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 void updateVariable(Type newItem, SymbolTableIndex index) { - theSymbolTable.replace(index, newItem); - } - - public Type get(SymbolTableIndex index) { - return theSymbolTable.get(index); - } - - public static void main(String[] args) { - SymbolTable symbolTable = new SymbolTable(); - symbolTable.addConstant(new Int(3)); - SymbolTableIndex i_var = symbolTable.addVariable(new Int(0), "i"); - System.out.println(symbolTable.get(i_var)); - symbolTable.updateVariable(symbolTable.get(i_var).add(new Int(1)), i_var); - System.out.println(symbolTable.get(i_var)); - } -} - \ No newline at end of file -- cgit v1.2.3