From b03859dce5991169b07d1d5040c8faf7ba82e5b5 Mon Sep 17 00:00:00 2001 From: bd-912 Date: Sat, 6 Apr 2024 19:02:21 -0600 Subject: Rewrite SymbolTable again P1 --- Playground.java | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Playground.java (limited to 'Playground.java') 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 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 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")); + } +} -- cgit v1.2.3