From acb209e4bef36186744ee09c67fcad77550e78d2 Mon Sep 17 00:00:00 2001 From: bd-912 Date: Sun, 17 Mar 2024 21:37:38 -0600 Subject: Pretty printing for TypeCheckSimp, start for symbol table --- minijava/SymTableVis.java | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'minijava/SymTableVis.java') diff --git a/minijava/SymTableVis.java b/minijava/SymTableVis.java index 3d8003b..e0854f0 100644 --- a/minijava/SymTableVis.java +++ b/minijava/SymTableVis.java @@ -8,9 +8,9 @@ import java.util.*; * Provides default methods which visit each node in the tree in depth-first * order. Your visitors may extend this class. */ -public class SymTableVis implements GJVisitor { +public class SymTableVis extends GJDepthFirst { - public HashMap symt = new HashMap<>(); + public HashMap symt = new HashMap<>(); private void print_filter(String message) { boolean debug = true; @@ -18,26 +18,30 @@ public class SymTableVis implements GJVisitor { System.out.println(message); } - public R visit(VarDeclaraction n, A argu) { - R _ret=null; + /** + * f0 -> Type() + * f1 -> Identifier() + * f2 -> ";" + */ + public R visit(VarDeclaration n, A argu) { this.print_filter("Processing declaration"); - String type = ""; + TypeEnum type = TypeEnum.ERROR; switch (n.f0.f0.which) { case 2: - type = "Int"; break; + type = TypeEnum.integer; break; default: this.print_filter("Unsupported case"); } String id = n.f1.f0.tokenImage; - this.printfilter("Inserting " + id + " => " + type); + this.print_filter("Inserting " + id + " => " + type); // Safe? symt.put(id, type); - return _ret; + return null; } } -- cgit v1.2.3