import java.io.*; import visitor.*; import parse.*; import syntaxtree.*; import java.util.*; import st.*; import misc.*; import typecheck.library.*; 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=Void, A=String. PPrinter pp = new PPrinter(); root.accept(pp, ""); PrintFilter.print("===================================================", true); // Build the symbol table. Top-down visitor, inherits from // GJDepthFirst. R=Void, A=Integer. SymbolTable st = new SymbolTable(); root.accept(new SymTableFirst(), st); // root.accept(new SymTableSecond(), st); PrintFilter.print("===================================================", true); // TypeCheckSimp ts = new TypeCheckSimp(); // TypeInstance 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) // if (res.get_type() != TypeEnum.ERROR) // System.out.println("Program type checked successfully"); // else // System.out.println("Type error"); } catch (ParseException e) { System.out.println(e.toString()); System.exit(1); } } }