diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-03-23 21:09:05 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-03-23 21:09:05 -0600 |
commit | 762acb336997d43e15d64ff591103614abe4806f (patch) | |
tree | f2f02cc09b4ca81f6b06bc67d2f90df4a2fc9e81 /minijava/SymTableVis.java | |
parent | 7a26f1108fb412daa4495628fc5136da2bb0ee34 (diff) |
Added minor classname functionality to ST
Diffstat (limited to 'minijava/SymTableVis.java')
-rw-r--r-- | minijava/SymTableVis.java | 66 |
1 files changed, 62 insertions, 4 deletions
diff --git a/minijava/SymTableVis.java b/minijava/SymTableVis.java index 65e511f..6f03c45 100644 --- a/minijava/SymTableVis.java +++ b/minijava/SymTableVis.java @@ -10,7 +10,7 @@ import java.util.*; */ public class SymTableVis<R,A> extends GJDepthFirst<R,A> { - public HashMap<String,TypeEnum> symt = new HashMap<>(); + public HashMap<String,TypeInstance> symt = new HashMap<>(); private void print_filter(String message) { boolean debug = true; @@ -19,6 +19,45 @@ public class SymTableVis<R,A> extends GJDepthFirst<R,A> { } /** + * f0 -> "class" + * f1 -> Identifier() + * f2 -> "{" + * f3 -> "public" + * f4 -> "static" + * f5 -> "void" + * f6 -> "main" + * f7 -> "(" + * f8 -> "String" + * f9 -> "[" + * f10 -> "]" + * f11 -> Identifier() + * f12 -> ")" + * f13 -> "{" + * f14 -> ( VarDeclaration() )* + * f15 -> ( Statement() )* + * f16 -> "}" + * f17 -> "}" + */ + public R visit(MainClass n, A argu) { + + n.f1.accept(this, argu); + n.f11.accept(this, argu); + n.f14.accept(this, argu); + n.f15.accept(this, argu); + + this.print_filter("Processing main"); + + String id = n.f1.f0.tokenImage; + + TypeInstance type = new TypeInstance(id, TypeEnum.classname); + this.print_filter("Inserting " + id + " => " + type); + symt.put(id, type); + + return null; + + } + + /** * f0 -> Type() * f1 -> Identifier() * f2 -> ";" @@ -27,23 +66,42 @@ public class SymTableVis<R,A> extends GJDepthFirst<R,A> { this.print_filter("Processing declaration"); - TypeEnum type = TypeEnum.ERROR; + String id = n.f1.f0.tokenImage; + TypeInstance type = new TypeInstance("ERROR", TypeEnum.ERROR); switch (n.f0.f0.which) { case 0: - type = TypeEnum.int_array; break; + type = new TypeInstance("int_array", TypeEnum.int_array); break; + case 1: + type = new TypeInstance("bool", TypeEnum.bool); break; case 2: - type = TypeEnum.integer; break; + type = new TypeInstance("int", TypeEnum.integer); break; + case 3: + type = new TypeInstance(id, TypeEnum.classname); break; default: this.print_filter("Unsupported case"); } + this.print_filter("Inserting " + id + " => " + type); + // Safe? + symt.put(id, type); + + return null; + } + + public R visit(ClassDeclaration n, A argu) { + + this.print_filter("Processing class"); + String id = n.f1.f0.tokenImage; + TypeInstance type = new TypeInstance(id, TypeEnum.classname); this.print_filter("Inserting " + id + " => " + type); // Safe? symt.put(id, type); return null; + } + } |