-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPrintVisitor.java
More file actions
executable file
·84 lines (73 loc) · 2 KB
/
PrintVisitor.java
File metadata and controls
executable file
·84 lines (73 loc) · 2 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
// Name:PrintVisitor.java
//
// Visitor for "pretty printing" an abstract syntax tree in the ExprLang language
//
public class PrintVisitor implements ExprLangVisitor
{
public Object visit(SimpleNode node, Object data)
{
throw new RuntimeException("Visit SimpleNode");
}
public Object visit(ASTprogram node, Object data)
{
node.jjtGetChild(0).jjtAccept(this, data);
System.out.println(";");
return(data);
}
public Object visit(ASTDecl node, Object data)
{
System.out.print(node.value + " ");
node.jjtGetChild(0).jjtAccept(this, data);
return data;
}
public Object visit(ASTStms node, Object data)
{
node.jjtGetChild(0).jjtAccept(this, data);
System.out.println(";");
node.jjtGetChild(1).jjtAccept(this, data);
return data;
}
public Object visit(ASTAdd_op node, Object data)
{
node.jjtGetChild(0).jjtAccept(this, data);
System.out.print(" " + node.value + " ");
node.jjtGetChild(1).jjtAccept(this, data);
return data;
}
public Object visit(ASTBool_op node, Object data)
{
node.jjtGetChild(0).jjtAccept(this, data);
System.out.print(" " + node.value + " ");
node.jjtGetChild(1).jjtAccept(this, data);
return data;
}
public Object visit(ASTMult_op node, Object data)
{
node.jjtGetChild(0).jjtAccept(this, data);
System.out.print(" " + node.value + " ");
node.jjtGetChild(1).jjtAccept(this, data);
return data;
}
public Object visit(ASTNot_op node, Object data)
{
System.out.print("~");
return(node.jjtGetChild(0).jjtAccept(this, data));
}
public Object visit(ASTExp node, Object data)
{
System.out.print("(");
node.jjtGetChild(0).jjtAccept(this, data);
System.out.print(")");
return(data);
}
public Object visit(ASTidentifier node, Object data)
{
System.out.print(node.value);
return data;
}
public Object visit(ASTnumber node, Object data)
{
System.out.print(node.value);
return data;
}
}