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

Lex and parse variables.

This commit is contained in:
Danila Fedorin 2017-08-18 14:21:14 -07:00
parent 0a15043b63
commit 1c751353f1
2 changed files with 4 additions and 1 deletions

View File

@ -34,6 +34,7 @@ public class LexerTokenizer implements Tokenizer<Match<TokenType>>, PluginListen
register(" ", TokenType.WHITESPACE);
register(",", TokenType.COMMA);
register("[0-9]*(\\.[0-9]+)?", TokenType.NUM);
register("[a-zA-Z]+", TokenType.VARIABLE);
register("\\(", TokenType.OPEN_PARENTH);
register("\\)", TokenType.CLOSE_PARENTH);
}};

View File

@ -61,7 +61,7 @@ public class ShuntingYardParser implements Parser<Match<TokenType>>, PluginListe
Match<TokenType> match = from.remove(0);
previousType = matchType;
matchType = match.getType();
if (matchType == TokenType.NUM) {
if (matchType == TokenType.NUM || matchType == TokenType.VARIABLE) {
output.add(match);
} else if (matchType == TokenType.FUNCTION) {
output.add(new Match<>("", TokenType.INTERNAL_FUNCTION_END));
@ -144,6 +144,8 @@ public class ShuntingYardParser implements Parser<Match<TokenType>>, PluginListe
}
} else if (matchType == TokenType.NUM) {
return new NumberNode(abacus.numberFromString(match.getContent()));
} else if (matchType == TokenType.VARIABLE) {
return new VariableNode(match.getContent());
} else if (matchType == TokenType.FUNCTION) {
String functionName = match.getContent();
FunctionNode node = new FunctionNode(functionName);