mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-23 07:50:09 -08:00
Rename OpNode to BinaryInfixNode.
This commit is contained in:
parent
51f2c15542
commit
c1bf308d6d
|
@ -3,7 +3,7 @@ package org.nwapw.abacus.tree;
|
|||
/**
|
||||
* A tree node that represents an operation being applied to two operands.
|
||||
*/
|
||||
public class OpNode extends TreeNode {
|
||||
public class BinaryInfixNode extends TreeNode {
|
||||
|
||||
/**
|
||||
* The operation being applied.
|
||||
|
@ -18,14 +18,14 @@ public class OpNode extends TreeNode {
|
|||
*/
|
||||
private TreeNode right;
|
||||
|
||||
private OpNode() {}
|
||||
private BinaryInfixNode() {}
|
||||
|
||||
/**
|
||||
* Creates a new operation node with the given operation
|
||||
* and no child nodes.
|
||||
* @param operation the operation.
|
||||
*/
|
||||
public OpNode(String operation){
|
||||
public BinaryInfixNode(String operation){
|
||||
this(operation, null, null);
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ public class OpNode extends TreeNode {
|
|||
* @param left the left node of the expression.
|
||||
* @param right the right node of the expression.
|
||||
*/
|
||||
public OpNode(String operation, TreeNode left, TreeNode right){
|
||||
public BinaryInfixNode(String operation, TreeNode left, TreeNode right){
|
||||
this.operation = operation;
|
||||
this.left = left;
|
||||
this.right = right;
|
|
@ -27,10 +27,10 @@ public class NumberReducer implements Reducer<NumberInterface> {
|
|||
public NumberInterface reduceNode(TreeNode node, Object... children) {
|
||||
if(node instanceof NumberNode) {
|
||||
return ((NumberNode) node).getNumber();
|
||||
} else if(node instanceof OpNode){
|
||||
} else if(node instanceof BinaryInfixNode){
|
||||
NumberInterface left = (NumberInterface) children[0];
|
||||
NumberInterface right = (NumberInterface) children[1];
|
||||
Function function = manager.operatorFor(((OpNode) node).getOperation()).getFunction();
|
||||
Function function = manager.operatorFor(((BinaryInfixNode) node).getOperation()).getFunction();
|
||||
if(function == null) return null;
|
||||
return function.apply(left, right);
|
||||
} else if(node instanceof UnaryPrefixNode) {
|
||||
|
|
|
@ -163,7 +163,7 @@ public class TreeBuilder {
|
|||
TreeNode right = fromStringRecursive(source, matches);
|
||||
TreeNode left = fromStringRecursive(source, matches);
|
||||
if(left == null || right == null) return null;
|
||||
else return new OpNode(operator, left, right);
|
||||
else return new BinaryInfixNode(operator, left, right);
|
||||
} else {
|
||||
TreeNode applyTo = fromStringRecursive(source, matches);
|
||||
if(applyTo == null) return null;
|
||||
|
|
Loading…
Reference in New Issue
Block a user