1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-12-23 16:00:09 -08:00

Rename nodes to more general names.

This commit is contained in:
Danila Fedorin 2017-08-02 10:41:52 -07:00
parent 9eaeb079b7
commit 31a4234d9b
4 changed files with 13 additions and 13 deletions

View File

@ -127,11 +127,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 BinaryInfixNode(operator, left, right);
else return new BinaryNode(operator, left, right);
} else {
TreeNode applyTo = constructRecursive(matches);
if (applyTo == null) return null;
else return new UnaryPrefixNode(operator, applyTo);
else return new UnaryNode(operator, applyTo);
}
} else if (matchType == TokenType.NUM) {
return new NumberNode(abacus.numberFromString(match.getContent()));

View File

@ -3,7 +3,7 @@ package org.nwapw.abacus.tree;
/**
* A tree node that represents an operation being applied to two operands.
*/
public class BinaryInfixNode extends TreeNode {
public class BinaryNode extends TreeNode {
/**
* The operation being applied.
@ -18,7 +18,7 @@ public class BinaryInfixNode extends TreeNode {
*/
private TreeNode right;
private BinaryInfixNode() {
private BinaryNode() {
}
/**
@ -27,7 +27,7 @@ public class BinaryInfixNode extends TreeNode {
*
* @param operation the operation.
*/
public BinaryInfixNode(String operation) {
public BinaryNode(String operation) {
this(operation, null, null);
}
@ -39,7 +39,7 @@ public class BinaryInfixNode extends TreeNode {
* @param left the left node of the expression.
* @param right the right node of the expression.
*/
public BinaryInfixNode(String operation, TreeNode left, TreeNode right) {
public BinaryNode(String operation, TreeNode left, TreeNode right) {
this.operation = operation;
this.left = left;
this.right = right;

View File

@ -28,15 +28,15 @@ 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 BinaryInfixNode) {
} else if (node instanceof BinaryNode) {
NumberInterface left = (NumberInterface) children[0];
NumberInterface right = (NumberInterface) children[1];
Function function = abacus.getPluginManager().operatorFor(((BinaryInfixNode) node).getOperation()).getFunction();
Function function = abacus.getPluginManager().operatorFor(((BinaryNode) node).getOperation()).getFunction();
if (function == null) return null;
return function.apply(left, right);
} else if (node instanceof UnaryPrefixNode) {
} else if (node instanceof UnaryNode) {
NumberInterface child = (NumberInterface) children[0];
Function functionn = abacus.getPluginManager().operatorFor(((UnaryPrefixNode) node).getOperation()).getFunction();
Function functionn = abacus.getPluginManager().operatorFor(((UnaryNode) node).getOperation()).getFunction();
if (functionn == null) return null;
return functionn.apply(child);
} else if (node instanceof FunctionNode) {

View File

@ -1,6 +1,6 @@
package org.nwapw.abacus.tree;
public class UnaryPrefixNode extends TreeNode {
public class UnaryNode extends TreeNode {
/**
* The operation this node will apply.
@ -16,7 +16,7 @@ public class UnaryPrefixNode extends TreeNode {
*
* @param operation the operation for this node.
*/
public UnaryPrefixNode(String operation) {
public UnaryNode(String operation) {
this(operation, null);
}
@ -26,7 +26,7 @@ public class UnaryPrefixNode extends TreeNode {
* @param operation the operation for this node.
* @param applyTo the node to apply the function to.
*/
public UnaryPrefixNode(String operation, TreeNode applyTo) {
public UnaryNode(String operation, TreeNode applyTo) {
this.operation = operation;
this.applyTo = applyTo;
}