1
0
mirror of https://github.com/DanilaFe/abacus synced 2026-09-25 21:02:38 +00:00

Abstract some Binary and Unary node logic.

This commit is contained in:
2017-08-25 17:46:25 -07:00
parent 73075c57b9
commit 07d7343339
6 changed files with 47 additions and 17 deletions

View File

@@ -130,11 +130,11 @@ public class ShuntingYardParser implements Parser<Match<TokenType>>, PluginListe
TreeNode right = constructRecursive(matches);
TreeNode left = constructRecursive(matches);
if (left == null || right == null) return null;
else return new BinaryNode(operator, left, right);
else return new NumberBinaryNode(operator, left, right);
} else {
TreeNode applyTo = constructRecursive(matches);
if (applyTo == null) return null;
else return new UnaryNode(operator, applyTo);
else return new NumberUnaryNode(operator, applyTo);
}
} else if (matchType == TokenType.NUM) {
return new NumberNode(match.getContent());

View File

@@ -33,12 +33,12 @@ public class NumberReducer implements Reducer<NumberInterface> {
return abacus.numberFromString(((NumberNode) node).getNumber());
} else if(node instanceof VariableNode) {
return abacus.numberFromString("0");
} else if (node instanceof BinaryNode) {
} else if (node instanceof NumberBinaryNode) {
NumberInterface left = (NumberInterface) children[0];
NumberInterface right = (NumberInterface) children[1];
NumberOperator operator = abacus.getPluginManager().operatorFor(((BinaryNode) node).getOperation());
return operator.apply(left, right);
} else if (node instanceof UnaryNode) {
} else if (node instanceof NumberUnaryNode) {
NumberInterface child = (NumberInterface) children[0];
NumberOperator operator = abacus.getPluginManager().operatorFor(((UnaryNode) node).getOperation());
return operator.apply(child);