summaryrefslogtreecommitdiff
path: root/Typecheck.java
diff options
context:
space:
mode:
authorbd-912 <bdunahu@colostate.edu>2024-03-04 22:57:07 -0700
committerbd-912 <bdunahu@colostate.edu>2024-03-04 22:57:07 -0700
commit5b09fb3697f4b1cc1f2f3781f10e1334ada69c22 (patch)
tree439559c79594a5647c4b2450b78699e826176266 /Typecheck.java
parent9dfeb14f493c9fa4bc2b50ca644e90c16bec05f3 (diff)
Added the main class file
Diffstat (limited to 'Typecheck.java')
-rw-r--r--Typecheck.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/Typecheck.java b/Typecheck.java
new file mode 100644
index 0000000..039e94d
--- /dev/null
+++ b/Typecheck.java
@@ -0,0 +1,50 @@
+// Helper for HW2/CS453.
+import java.io.*;
+import visitor.*;
+import syntaxtree.*;
+import java.util.*;
+// Files are stored in the minijava directory/package.
+import minijava.*;
+
+public class Typecheck {
+ public static void main(String[] args) {
+ Node root = null;
+ try {
+ root = new MiniJavaParser(System.in).Goal();
+
+ // Pretty-print the tree. PPrinter inherits from
+ // GJDepthFirst<R,A>. R=Void, A=String.
+ // PPrinter<Void,String> pp = new PPrinter<Void,String>();
+ // root.accept(pp, "");
+
+ // // Build the symbol table. Top-down visitor, inherits from
+ // // GJDepthFirst<R,A>. R=Void, A=Integer.
+ // SymTableVis<Void, Integer> pv =
+ // new SymTableVis<Void,Integer>();
+ // root.accept(pv, 0);
+ // HashMap<String, String> symt = pv.symt;
+
+ // // Do type checking. Bottom-up visitor, also inherits from
+ // // GJDepthFirst. Visit functions return MyTpe (=R), and
+ // // take a symbol table (HashMap<String,String>) as
+ // // argument (=A). You may implement things differently of
+ // // course!
+ // TypeCheckSimp ts = new TypeCheckSimp();
+ // MyType res = root.accept(ts, symt);
+
+ // // Ugly code not to be inspired from: "my" way of storing
+ // // type info / typecheck property: if some of my internal
+ // // structure is empty, then things don't typecheck for
+ // // me. This is specific to my own implementation.
+ // if (res != null && res.type_array.size() > 0)
+ // System.out.println("Program type checked successfully");
+ // else
+ // System.out.println("Type error");
+ System.out.println("Type error");
+ }
+ catch (ParseException e) {
+ System.out.println(e.toString());
+ System.exit(1);
+ }
+ }
+}