-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBinaryNode.java
117 lines (109 loc) · 2.83 KB
/
BinaryNode.java
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
112
113
114
115
116
class BinaryNode extends Ast {
static final int plus = 1;
static final int minus = 2;
static final int times = 3;
static final int divide = 4;
static final int and = 5;
static final int or = 6;
static final int less = 7;
static final int lessEqual = 8;
static final int equal = 9;
static final int notEqual = 10;
static final int greater = 11;
static final int greaterEqual = 12;
static final int leftShift = 13;
static final int remainder = 14;
public BinaryNode (int nt, Type t, Ast l, Ast r) {
super(t);
NodeType = nt;
LeftChild = l;
RightChild = r;
}
public String toString() { return "Binary Node " + NodeType +
"(" + LeftChild + "," + RightChild + ")" + type; }
public void genCode () {
switch (NodeType) {
case plus:
LeftChild.genCode();
RightChild.genCode();
System.out.println("do addition " + type);
break;
case minus:
LeftChild.genCode();
RightChild.genCode();
System.out.println("do subtraction " + type);
break;
case leftShift:
LeftChild.genCode();
RightChild.genCode();
System.out.println("do left shift " + type);
break;
case times:
LeftChild.genCode();
RightChild.genCode();
System.out.println("do multiplication " + type);
break;
case divide:
LeftChild.genCode();
RightChild.genCode();
System.out.println("do division " + type);
break;
case remainder:
LeftChild.genCode();
RightChild.genCode();
System.out.println("do remainder " + type);
break;
case and:
LeftChild.genCode();
RightChild.genCode();
System.out.println("do and " + type);
break;
case or:
LeftChild.genCode();
RightChild.genCode();
System.out.println("do or " + type);
break;
case less:
LeftChild.genCode();
RightChild.genCode();
System.out.println("compare less " + type);
break;
case lessEqual:
LeftChild.genCode();
RightChild.genCode();
System.out.println("compare less or equal" + type);
break;
case equal:
LeftChild.genCode();
RightChild.genCode();
System.out.println("compare equal " + type);
break;
case notEqual:
LeftChild.genCode();
RightChild.genCode();
System.out.println("compare notEqual " + type);
break;
case greater:
LeftChild.genCode();
RightChild.genCode();
System.out.println("compare greater " + type);
break;
case greaterEqual:
LeftChild.genCode();
RightChild.genCode();
System.out.println("compare greaterEqual " + type);
break;
}
}
public void branchIfTrue (Label lab) throws ParseException {
genCode();
System.out.println("Branch if True " + lab);
}
public void branchIfFalse (Label lab) throws ParseException {
genCode();
System.out.println("Branch if False " + lab);
}
public int NodeType;
public Ast LeftChild;
public Ast RightChild;
}