Skip to content
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

Operator precedence climbing parser #86

Open
stevefan1999-personal opened this issue Sep 24, 2023 · 2 comments
Open

Operator precedence climbing parser #86

stevefan1999-personal opened this issue Sep 24, 2023 · 2 comments
Assignees
Milestone

Comments

@stevefan1999-personal
Copy link
Contributor

Consider what peg (https://docs.rs/peg/latest/peg/#precedence-climbing) was doing, I think it is suitable for us to implement precedence climbing for easier design of expression grammar

@woutersl woutersl self-assigned this Sep 25, 2023
@woutersl
Copy link
Member

From my understanding, precedence climbing is a way to fix the inefficiency of pure recursive-descent parsers for grammars that describe expressions with operators. This incidentally allows writing simpler grammars rules.

Hime use bottom-up parsing algorithms (LR and GLR) that do not suffer from this inefficiency. So precedence climbing is not really required per-se. It is true that we still have to write grammars that explicitly encode the operators precedence, as shown on Wikipedia.

My conclusion is then that the support for precedence climbing would then be only a way to alleviate the tediousness of writing grammar rules for this case, as shown in the peg crate doc. Writing grammar rules this way for expressions leads to ambiguous grammars for LR parsing techniques.

LR parsing techniques are very different from PEG; the implementation of precedence climbing would be very different. I'll have to do some research. Maybe we can have some higher-level syntax for grammar rules with operator precedence that translates to usual grammar rules that can be used by LR techniques.

@stevefan1999-personal
Copy link
Contributor Author

From my understanding, precedence climbing is a way to fix the inefficiency of pure recursive-descent parsers for grammars that describe expressions with operators. This incidentally allows writing simpler grammars rules.

Hime use bottom-up parsing algorithms (LR and GLR) that do not suffer from this inefficiency. So precedence climbing is not really required per-se. It is true that we still have to write grammars that explicitly encode the operators precedence, as shown on Wikipedia.

My conclusion is then that the support for precedence climbing would then be only a way to alleviate the tediousness of writing grammar rules for this case, as shown in the peg crate doc. Writing grammar rules this way for expressions leads to ambiguous grammars for LR parsing techniques.

LR parsing techniques are very different from PEG; the implementation of precedence climbing would be very different. I'll have to do some research. Maybe we can have some higher-level syntax for grammar rules with operator precedence that translates to usual grammar rules that can be used by LR techniques.

https://inst.eecs.berkeley.edu/~cs164/fa20/lectures/lecture8.pdf
but it seems like bison have it...

@woutersl woutersl added this to the 5.0.0.release milestone Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants