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")); } }