blob: d6fb4cf52d85e56de14392a2e5498194b7eb25b8 (
plain)
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
|
package com.jantuomi.interpreter.main.core.parser.ast;
import com.jantuomi.interpreter.main.core.parser.datatype.BooleanDataContainer;
import com.jantuomi.interpreter.main.core.parser.datatype.DataContainer;
import com.jantuomi.interpreter.main.core.tokenizer.token.Token;
import com.jantuomi.interpreter.main.exception.InterpreterException;
import java.util.Arrays;
import java.util.List;
/**
* Created by jan on 17.6.2016.
*/
public class BranchNode extends ASTNode {
private ASTNode expression;
private BlockBodyNode branch;
public BranchNode(Token token, ASTNode expression, BlockBodyNode branch) {
super(token);
this.expression = expression;
this.branch = branch;
}
@Override
public DataContainer evaluate() throws InterpreterException {
DataContainer ev = expression.evaluate();
boolean returnValue = false;
if (ev instanceof BooleanDataContainer) {
returnValue = ((BooleanDataContainer) ev).getData();
if (returnValue) {
branch.evaluate();
}
}
return new BooleanDataContainer(returnValue);
}
@Override
List<ASTNode> getChildren() {
return Arrays.asList(expression, branch);
}
}
|