From beb583a231c31131f0669bb2323ab8a15c20a358 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Fri, 18 Aug 2017 14:26:33 -0700 Subject: [PATCH] Move number string parsing from the parser into the reducer. --- .../java/org/nwapw/abacus/parsing/ShuntingYardParser.java | 2 +- core/src/main/java/org/nwapw/abacus/tree/NumberReducer.java | 2 +- core/src/main/kotlin/org/nwapw/abacus/tree/NumberNode.kt | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/nwapw/abacus/parsing/ShuntingYardParser.java b/core/src/main/java/org/nwapw/abacus/parsing/ShuntingYardParser.java index af9936b..86684ce 100644 --- a/core/src/main/java/org/nwapw/abacus/parsing/ShuntingYardParser.java +++ b/core/src/main/java/org/nwapw/abacus/parsing/ShuntingYardParser.java @@ -143,7 +143,7 @@ public class ShuntingYardParser implements Parser>, PluginListe else return new UnaryNode(operator, applyTo); } } else if (matchType == TokenType.NUM) { - return new NumberNode(abacus.numberFromString(match.getContent())); + return new NumberNode(match.getContent()); } else if (matchType == TokenType.VARIABLE) { return new VariableNode(match.getContent()); } else if (matchType == TokenType.FUNCTION) { 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 1cda9a5..4dae775 100644 --- a/core/src/main/java/org/nwapw/abacus/tree/NumberReducer.java +++ b/core/src/main/java/org/nwapw/abacus/tree/NumberReducer.java @@ -27,7 +27,7 @@ public class NumberReducer implements Reducer { @Override public NumberInterface reduceNode(TreeNode node, Object... children) { if (node instanceof NumberNode) { - return ((NumberNode) node).getNumber(); + return abacus.numberFromString(((NumberNode) node).getNumber()); } else if(node instanceof VariableNode) { return abacus.numberFromString("0"); } else if (node instanceof BinaryNode) { diff --git a/core/src/main/kotlin/org/nwapw/abacus/tree/NumberNode.kt b/core/src/main/kotlin/org/nwapw/abacus/tree/NumberNode.kt index 03b299d..de6597a 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/tree/NumberNode.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/tree/NumberNode.kt @@ -10,14 +10,14 @@ import org.nwapw.abacus.number.NumberInterface * * @number the number value of this node. */ -data class NumberNode(val number: NumberInterface) : TreeNode() { +data class NumberNode(val number: String) : TreeNode() { override fun reduce(reducer: Reducer): T? { return reducer.reduceNode(this) } override fun toString(): String { - return number.toString() + return number } } \ No newline at end of file