-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIfNode.java
More file actions
38 lines (33 loc) · 958 Bytes
/
IfNode.java
File metadata and controls
38 lines (33 loc) · 958 Bytes
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
package icsi311;
import java.util.Optional;
public class IfNode extends StatementNode{
Node Condition;
BlockNode Block;
Optional<StatementNode> Next = Optional.empty();
private boolean isElse = false;
public IfNode(Node c, BlockNode b, Optional<StatementNode> n){
Block = b;
Condition = c;
Next = n;
isElse = false;
}
public IfNode(Node c, BlockNode b){
Block = b;
Condition = c;
isElse = false;
}
public IfNode(BlockNode b){
isElse = true;
Block = b;
}
public String toString(){
if(isElse == true)
return "{" + Block.toString() + "}";
if(Next.isEmpty())
return "If(" + Condition.toString() + "){" + Block.toString() + "}";
return "If(" + Condition.toString() + "){" + Block.toString() + "} else " + Next.get().toString();
}
public boolean isElse(){
return isElse;
}
}