forked from michellegao715/SimpleJava-Compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAATPrintTree.java
More file actions
111 lines (91 loc) · 2.3 KB
/
AATPrintTree.java
File metadata and controls
111 lines (91 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import java.util.Vector;
public class AATPrintTree implements AATVisitor {
static final int indentstep = 3;
int indentlevel = 0;
void Print(String word) {
int i;
for (i=0; i < indentstep * indentlevel; i++)
System.out.print(" ");
System.out.println(word);
}
public Object VisitCallExpression(AATCallExpression call) {
int i;
Print("Call Expression: "+call.label());
indentlevel++;
for (i=0; i<call.actuals().size(); i++)
((AATExpression) call.actuals().elementAt(i)).Accept(this);
indentlevel--;
return null;
}
public Object VisitCallStatement(AATCallStatement call) {
Print("Call Statement: "+call.label());
indentlevel++;
for (int i=0; i<call.actuals().size(); i++)
((AATExpression) call.actuals().elementAt(i)).Accept(this);
indentlevel--;
return null;
}
public Object VisitConditionalJump(AATConditionalJump cjump) {
Print("Conditional Jump: " + cjump.label());
indentlevel++;
cjump.test().Accept(this);
indentlevel--;
return null;
}
public Object VisitConstant(AATConstant constant) {
Print(Integer.toString(constant.value()));
return null;
}
public Object VisitEmpty(AATEmpty empty) {
Print("Empty");
return null;
}
public Object VisitHalt(AATHalt halt) {
Print("Halt");
return null;
}
public Object VisitJump(AATJump jump) {
Print("Jump: " + jump.label());
return null;
}
public Object VisitLabel(AATLabel label) {
Print("Label: " + label.label());
return null;
}
public Object VisitMemory(AATMemory mem) {
Print("Memory");
indentlevel++;
mem.mem().Accept(this);
indentlevel--;
return null;
}
public Object VisitMove(AATMove move) {
Print("Move");
indentlevel++;
move.lhs().Accept(this);
move.rhs().Accept(this);
indentlevel--;
return null;
}
public Object VisitOperator(AATOperator oper) {
Print(AATOperator.names[oper.operator()]);
indentlevel++;
oper.left().Accept(this);
oper.right().Accept(this);
indentlevel--;
return null;
}
public Object VisitRegister(AATRegister reg) {
Print("Register: " + reg.register());
return null;
}
public Object VisitReturn(AATReturn ret) {
Print("Return");
return null;
}
public Object VisitSequential(AATSequential seq) {
seq.left().Accept(this);
seq.right().Accept(this);
return null;
}
}