-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAssignmentNode.java
34 lines (30 loc) · 1.06 KB
/
AssignmentNode.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
package icsi311;
public class AssignmentNode extends StatementNode{
Node Target;
OperationNode Expression;
public AssignmentNode(Node t, OperationNode e){
// If t is VariableReferenceNode, then set it to target
Target = t;
Expression = e;
}
public String toString(){
if(Target instanceof VariableReferenceNode) {
VariableReferenceNode t = (VariableReferenceNode) Target;
if (Expression.getOperation() == OperationNode.PossibleOperations.ASSIGN)
return t.getName() + " = " + Expression.getRightValue().get();
}
else if(Target instanceof OperationNode){
OperationNode opNode = (OperationNode) Target;
String fin = opNode.getLeftValue().toString();
if(fin.contains(".")){
String[] change = fin.split(".");
fin = change[0];
}
return "$" + opNode.getLeftValue().toString();
}
return Expression.toString();
}
public Node getTarget(){
return Target;
}
}