mirror of
https://github.com/DanilaFe/abacus
synced 2024-11-17 08:03:09 -08:00
Lex and parse variables.
This commit is contained in:
parent
0a15043b63
commit
1c751353f1
|
@ -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);
|
||||
}};
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user