mirror of
https://github.com/DanilaFe/abacus
synced 2024-11-16 23:53:09 -08:00
Move number string parsing from the parser into the reducer.
This commit is contained in:
parent
e0ff229df4
commit
beb583a231
|
@ -143,7 +143,7 @@ public class ShuntingYardParser implements Parser<Match<TokenType>>, 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) {
|
||||
|
|
|
@ -27,7 +27,7 @@ public class NumberReducer implements Reducer<NumberInterface> {
|
|||
@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) {
|
||||
|
|
|
@ -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 <T : Any> reduce(reducer: Reducer<T>): T? {
|
||||
return reducer.reduceNode(this)
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return number.toString()
|
||||
return number
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user