-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Pratt parsing or precedence climbing #358
Comments
Parsing precedence is done in the combine-language extension crate https://docs.rs/combine-language/latest/combine_language/fn.expression_parser.html (via shunting yard). |
Thank you! This does seem a bit less powerful than Pratt parsing, since it doesn't handle prefix or postfix operators. For example, if I want |
I think pratt and shunting yard are the same algorithm (https://matklad.github.io/2020/04/15/from-pratt-to-dijkstra.html) the only difference is that pratt is generally presented by using the normal program stack whereas shunting yard uses an explicit stack. In the case of https://docs.rs/combine-language/latest/combine_language/fn.expression_parser.html it may be closer to pratt parsing in that case since it uses the program stack. Thus it may just be a case of extending it to support pre and postfix operators. |
Sounds good, I'll move this issue to the combine-language repository then. I don't think I have an immediate need for it, so I'm fine with the issue over there remaining open. If I ever need it, I might contribute a PR. Otherwise I'll leave implementing it to other people who need it. |
I believe that implementing pratt parsing (or precedence climbing, which is supposedly the same algorithm) could be useful. It makes parsing mathematical expressions much simpler, since one no longer has to bend their parsing rules to fit, and can instead simply specify the binding power and associativity.
There are other libraries that have implemented this, for example
The text was updated successfully, but these errors were encountered: