6 ms·
I've found that a super simple way to parse basic expressions is a recursive descent parser. It is very simple to implement. No need to to break into tokenizer/
by ralphb 4y ago
I've found that a super simple way to parse basic expressions is a recursive descent parser. It is very simple to implement. No need to to break into tokenizer/parser, no need to generate an AST, just evaluate the expression while parsing.
- lsferreira42 4y agoDo you have an example of a simple parser like that?
- ralphb 4y agohttps://gist.github.com/revivalizer/935dfcc345b009a0207a033caee0175f https://gist.github.com/revivalizer/935dfcc345b009a0207a033c... Even includes error handling :) At the bottom you can see some test examples of what it can do. Obviously it is a basic calculator.