summaryrefslogtreecommitdiff
path: root/Playground.java
diff options
context:
space:
mode:
Diffstat (limited to 'Playground.java')
-rw-r--r--Playground.java44
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"));
+ }
+}