1
0
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:
Danila Fedorin 2017-08-18 14:26:33 -07:00
parent e0ff229df4
commit beb583a231
3 changed files with 4 additions and 4 deletions

View File

@ -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) {

View File

@ -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) {

View File

@ -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
}
}