diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-04-06 19:02:21 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-04-06 19:02:21 -0600 |
commit | b03859dce5991169b07d1d5040c8faf7ba82e5b5 (patch) | |
tree | 5a1217d441c9323976aef6e45018c9c2522930a6 /Playground.java | |
parent | 0ae01301d572b2e69585c4d1cb753ed7fc89dfe3 (diff) |
Rewrite SymbolTable again P1
Diffstat (limited to 'Playground.java')
-rw-r--r-- | Playground.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Playground.java b/Playground.java new file mode 100644 index 0000000..aae1af6 --- /dev/null +++ b/Playground.java @@ -0,0 +1,44 @@ +import java.util.*; +import st.*; + +/** + * A small method to test the basic functionality + * of the st Instance library + */ +public class Playground { + + public static String HashMapToString(Map<String, AbstractInstance> map) { + StringBuilder mapAsString = new StringBuilder("{"); + for (String key : map.keySet()) { + mapAsString.append(key + "=" + map.get(key) + ", "); + } + mapAsString.delete(mapAsString.length()-2, mapAsString.length()).append("}"); + return mapAsString.toString(); + } + + public static void main(String[] args) { + HashMap<String,AbstractInstance> symt = new HashMap<>(); + + symt.put("x", new TypeInstance("x", TypeEnum.integer)); + symt.put("a", new MethodInstance("a", TypeEnum.intarray)); + symt.put("A", new ClassInstance("A", new ClassInstance("B"))); + System.out.println("Our symbol table has lots of symbols: " + HashMapToString(symt)); + System.out.println("It seems class A extends B, but B isn't in the table... " + + ((ClassInstance) symt.get("A")).getExtend()); + + SymbolTable ssymt = new SymbolTable(); + + ssymt.put("x", new TypeInstance("x", TypeEnum.integer)); + ssymt.put("A", new ClassInstance("A")); + System.out.println("A smarter approach. Here's type 'x':" + + ssymt.getType("x")); + System.out.println("Null class 'x':" + + ssymt.getClass("x")); + System.out.println("Null method 'x':" + + ssymt.getMethod("x")); + System.out.println("Null type 'y':" + + ssymt.getType("y")); + System.out.println("Null type 'A':" + + ssymt.getType("A")); + } +} |