diff options
author | bd-912 <bdunahu@colostate.edu> | 2024-03-16 22:06:32 -0600 |
---|---|---|
committer | bd-912 <bdunahu@colostate.edu> | 2024-03-16 22:06:32 -0600 |
commit | 6a24c69232901de51f50beab9c3d3b3760dee334 (patch) | |
tree | 70c71b9ec25d3f6085d71c83e2be3719fe638ae9 /minijava/SymTableVis.java | |
parent | 5b09fb3697f4b1cc1f2f3781f10e1334ada69c22 (diff) |
(Nonfunctional) Implemented many type-checking rules
Diffstat (limited to 'minijava/SymTableVis.java')
-rw-r--r-- | minijava/SymTableVis.java | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/minijava/SymTableVis.java b/minijava/SymTableVis.java new file mode 100644 index 0000000..3d8003b --- /dev/null +++ b/minijava/SymTableVis.java @@ -0,0 +1,43 @@ +package minijava; + +import syntaxtree.*; +import visitor.*; +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<R,A> implements GJVisitor<R,A> { + + public HashMap<String,String> symt = new HashMap<>(); + + private void print_filter(String message) { + boolean debug = true; + if (debug) + System.out.println(message); + } + + public R visit(VarDeclaraction n, A argu) { + R _ret=null; + + this.print_filter("Processing declaration"); + + String type = ""; + switch (n.f0.f0.which) { + case 2: + type = "Int"; break; + default: + this.print_filter("Unsupported case"); + } + + String id = n.f1.f0.tokenImage; + + this.printfilter("Inserting " + id + " => " + type); + // Safe? + symt.put(id, type); + + return _ret; + } + +} |