From 20b2e77ee138d143249821031ebc2ef036901bc9 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 25 Aug 2017 18:48:05 -0700 Subject: [PATCH] Add reduction of TreeValue operators. --- .../org/nwapw/abacus/tree/NumberReducer.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/nwapw/abacus/tree/NumberReducer.java b/core/src/main/java/org/nwapw/abacus/tree/NumberReducer.java index c744195..fa73958 100644 --- a/core/src/main/java/org/nwapw/abacus/tree/NumberReducer.java +++ b/core/src/main/java/org/nwapw/abacus/tree/NumberReducer.java @@ -1,10 +1,7 @@ package org.nwapw.abacus.tree; import org.nwapw.abacus.Abacus; -import org.nwapw.abacus.function.NumberFunction; -import org.nwapw.abacus.function.NumberOperator; -import org.nwapw.abacus.function.Operator; -import org.nwapw.abacus.function.TreeValueFunction; +import org.nwapw.abacus.function.*; import org.nwapw.abacus.number.NumberInterface; /** @@ -60,6 +57,18 @@ public class NumberReducer implements Reducer { abacus.getPluginManager().treeValueFunctionFor(callNode.getCallTo()); if(function == null) return null; return function.applyWithReducer(this, realChildren); + } else if (node instanceof TreeValueBinaryNode) { + BinaryNode binaryNode = (BinaryNode) node; + TreeValueOperator operator = abacus.getPluginManager() + .treeValueOperatorFor(binaryNode.getOperation()); + if(operator == null) return null; + return operator.applyWithReducer(this, binaryNode.getLeft(), binaryNode.getRight()); + } else if(node instanceof TreeValueUnaryNode) { + UnaryNode unaryNode = (UnaryNode) node; + TreeValueOperator operator = abacus.getPluginManager() + .treeValueOperatorFor(unaryNode.getOperation()); + if(operator == null) return null; + return operator.applyWithReducer(this, unaryNode.getApplyTo()); } return null; }