-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperationNode.java
More file actions
127 lines (107 loc) · 3.21 KB
/
OperationNode.java
File metadata and controls
127 lines (107 loc) · 3.21 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package icsi311;
import java.util.Optional;
public class OperationNode extends StatementNode {
private Node Left;
private Optional<Node> Right;
private PossibleOperations Operation;
public enum PossibleOperations{
EQ,
NE,
LT,
LE,
GT,
GE,
AND,
OR,
NOT,
MATCH,
NOTMATCH,
DOLLAR,
PREINC,
PREDEC,
POSTINC,
POSTDEC,
UNARYPOS,
UNARYNEG,
IN,
EXPONENT,
ADD,
SUBTRACT,
MULTIPLY,
DIVIDE,
MODULO,
CONCATENATION,
REGEXP,
TILDE,
ASSIGN
}
public OperationNode(Node l, PossibleOperations o){
Left = l;
Operation = o;
Right = Optional.empty();
}
public OperationNode(Node l, PossibleOperations o, Node r){
Left = l;
Operation = o;
Right = Optional.of(r);
}
public String toString(){
if(Operation == PossibleOperations.DOLLAR){
String fin = Left.toString();
if(fin.contains(".")){
String[] change = fin.split("[.]");
fin = change[0];
}
return "$" + fin;
}
if(!Right.isEmpty())
return Left.toString() + " " + Operation.toString() + " " + Right.get().toString();
else
return Left.toString() + "(" + Operation.toString() + ")";
}
public OperationNode.PossibleOperations getOperation(){
return Operation;
}
public Optional<Node> getRightValue(){
return Right;
}
public Node getLeftValue(){return Left;}
public boolean isMathematic(){
PossibleOperations op = getOperation();
if(op == PossibleOperations.ADD || op == PossibleOperations.SUBTRACT || op == PossibleOperations.MULTIPLY || op == PossibleOperations.DIVIDE || op == PossibleOperations.EXPONENT || op == PossibleOperations.MODULO)
return true;
return false;
}
public boolean isPreIncremental(){
if(getOperation() == PossibleOperations.PREDEC || getOperation() == PossibleOperations.PREINC)
return true;
return false;
}
public boolean isPostIncremental(){
if(getOperation() == PossibleOperations.POSTDEC || getOperation() == PossibleOperations.POSTINC)
return true;
return false;
}
public boolean isBoolOperator(){
PossibleOperations op = getOperation();
if(op == PossibleOperations.AND || op == PossibleOperations.OR || op == PossibleOperations.NOT)
return true;
return false;
}
public boolean isCompOperater(){
PossibleOperations op = getOperation();
if(op == PossibleOperations.EQ || op == PossibleOperations.NE || op == PossibleOperations.LT || op == PossibleOperations.GT || op == PossibleOperations.GE || op == PossibleOperations.LE)
return true;
return false;
}
public Node VeryLeftNode(){
Node fin;
if(Left instanceof OperationNode){
OperationNode left = (OperationNode) Left;
fin = left.VeryLeftNode();
return fin;
}
else
return Left;
}
}