From 7c6c79a437a4c1e7cf85964d005a3cdeb59809f1 Mon Sep 17 00:00:00 2001 From: bd-912 Date: Fri, 26 Apr 2024 17:01:49 -0600 Subject: Added skeleton files in "heat" libary, successor to TypeCheckSimp --- Typecheck.java | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'Typecheck.java') diff --git a/Typecheck.java b/Typecheck.java index 8c4559b..d153f7a 100644 --- a/Typecheck.java +++ b/Typecheck.java @@ -5,7 +5,7 @@ import syntaxtree.*; import java.util.*; import st.*; import misc.*; -import typecheck.*; +import heat.*; public class Typecheck { public static void main(String[] args) { @@ -17,27 +17,29 @@ public class Typecheck { // GJDepthFirst. R=Void, A=String. PPrinter pp = new PPrinter(); root.accept(pp, ""); - MinimalLogger.info("==================================================="); // Build the symbol table. Top-down visitor, inherits from // GJDepthFirst. R=Void, A=Integer. SymbolTable symt = new SymbolTable(); - root.accept(new SymTableBottomUp(), symt); - root.accept(new SymTableTopDown(), symt); - MinimalLogger.info("==================================================="); + MinimalLogger.info("Populating classes..."); + root.accept(new SymTableClasses(), symt); + MinimalLogger.info("Populating methods..."); + root.accept(new SymTableMethods(), symt); + MinimalLogger.info("Populating variables..."); + root.accept(new SymTableVars(), symt); + MinimalLogger.info("Populating extensions..."); + root.accept(new SymTableExtend(), symt); + MinimalLogger.info(symt.toString()); - TypeCheckSimp ts = new TypeCheckSimp(); - TypeInstance res = root.accept(ts, symt); + HeatVisitor hv = new HeatVisitor(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.getType() != TypeEnum.ERROR) + try { + root.accept(hv, null); System.out.println("Program type checked successfully"); - else + } catch (TypecheckException e) { System.out.println("Type error"); + } + } catch (ParseException e) { System.out.println(e.toString()); -- cgit v1.2.3