use of suite.node.Tree in project suite by stupidsing.
the class TreeUtil method evaluate.
public static int evaluate(Node node) {
Tree tree = Tree.decompose(node);
int result;
if (tree != null) {
Operator op = tree.getOperator();
IntInt_Int fun;
int lhs, rhs;
if (op == TermOp.TUPLE_) {
Tree rightTree = Tree.decompose(tree.getRight());
lhs = evaluate(tree.getLeft());
rhs = evaluate(rightTree.getRight());
fun = evaluateOp(rightTree.getLeft());
} else {
lhs = evaluate(tree.getLeft());
rhs = evaluate(tree.getRight());
fun = evaluateOp(op);
}
result = fun.apply(lhs, rhs);
} else if (node instanceof Int)
result = ((Int) node).number;
else
result = Fail.t("cannot evaluate expression: " + node);
return result;
}
use of suite.node.Tree in project suite by stupidsing.
the class TreeUtil method nElements.
public static int nElements(Node node) {
int n = 1;
Tree tree;
while ((tree = Tree.decompose(node, TermOp.TUPLE_)) != null) {
node = tree.getRight();
n++;
}
return n;
}
Aggregations