From 1eac68a0e5fd00ee563ac43cb6f4dac3a4fb2c33 Mon Sep 17 00:00:00 2001 From: bd-912 Date: Sat, 6 Apr 2024 21:39:15 -0600 Subject: Added SymTableFirst, the completed first visitor --- Typecheck.java | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'Typecheck.java') diff --git a/Typecheck.java b/Typecheck.java index 23f2efc..070b71e 100644 --- a/Typecheck.java +++ b/Typecheck.java @@ -21,28 +21,23 @@ public class Typecheck { // Build the symbol table. Top-down visitor, inherits from // GJDepthFirst. R=Void, A=Integer. - SymTableVis pv = new SymTableVis(); - root.accept(pv, new ArrayList()); - HashMap symt = pv.symt; + SymbolTable st = new SymbolTable(); + root.accept(new SymTableFirst(), st); + // root.accept(new SymTableSecond(), st); PrintFilter.print("===================================================", true); - // Do type checking. Bottom-up visitor, also inherits from - // GJDepthFirst. Visit functions return MyTpe (=R), and - // take a symbol table (HashMap) as - // argument (=A). You may implement things differently of - // course! - TypeCheckSimp ts = new TypeCheckSimp(); - TypeInstance res = root.accept(ts, symt); + // 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"); + // // 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()); -- cgit v1.2.3