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

Find non-reachable expression in prioritized choice #26

Open
ptal opened this issue Jul 14, 2014 · 3 comments
Open

Find non-reachable expression in prioritized choice #26

ptal opened this issue Jul 14, 2014 · 3 comments

Comments

@ptal
Copy link
Owner

ptal commented Jul 14, 2014

For this simple example, the neq rule will never match because lt will always match first and so the rule comparison will succeed and > will not be matched. We could find a way to statically analyse such situation and report the error to the user.

comparison = le / lt / ge / gt / eq / neq
lt = "<" spacing
le = "<=" spacing
gt = ">" spacing
ge = ">=" spacing
eq = "==" spacing
neq = "<>" spacing
@ptal
Copy link
Owner Author

ptal commented Jul 14, 2014

A solution might be to check if sub-rules of a choice are overlapping. We need to define what overlapping means for all PEG operators.

@ptal ptal changed the title Find non-reachable rule in prioritize choice Find non-reachable rule in prioritized choice Jul 20, 2015
@ptal ptal changed the title Find non-reachable rule in prioritized choice Find non-reachable expression in prioritized choice Aug 11, 2015
@ptal ptal modified the milestone: Static analysis and misc. Jul 28, 2016
@ptal
Copy link
Owner Author

ptal commented Feb 5, 2018

Such an analysis can draw some inspiration in the FIRST/FOLLOW analysis of LL(1) grammar. An optimization could be to detect such LL(1) cases and to optimize the code accordingly (using match instead of nested if, and avoiding backtracking in this case: it would also improve the error reporting since we do not the try the other (not relevant) alternatives).

@ptal
Copy link
Owner Author

ptal commented Dec 29, 2020

A first draft has been wrote by Chao Lin & William Sergeant. See unreachable_rule.rs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant