diff options
Diffstat (limited to 'Typecheck.java')
-rw-r--r-- | Typecheck.java | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/Typecheck.java b/Typecheck.java index 8e970be..6d202eb 100644 --- a/Typecheck.java +++ b/Typecheck.java @@ -8,45 +8,45 @@ import minijava.*; public class Typecheck { public static void main(String[] args) { - Node root = null; - try { - root = new MiniJavaParser(System.in).Goal(); + 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, ""); - System.out.println("==================================================="); + // 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, ""); + System.out.println("==================================================="); - // // 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, TypeEnum> symt = pv.symt; + // // 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, TypeInstance> 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(); - TypeInstance res = root.accept(ts, 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(); + 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); - } + // 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); + } } } |