summaryrefslogtreecommitdiff
path: root/minijava/SymTableVis.java
diff options
context:
space:
mode:
Diffstat (limited to 'minijava/SymTableVis.java')
-rw-r--r--minijava/SymTableVis.java20
1 files changed, 12 insertions, 8 deletions
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<R,A> implements GJVisitor<R,A> {
+public class SymTableVis<R,A> extends GJDepthFirst<R,A> {
- public HashMap<String,String> symt = new HashMap<>();
+ public HashMap<String,TypeEnum> symt = new HashMap<>();
private void print_filter(String message) {
boolean debug = true;
@@ -18,26 +18,30 @@ public class SymTableVis<R,A> implements GJVisitor<R,A> {
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;
}
}