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

Complex conflicts handling if we need to peek more than 1 token. #24

Open
DiscreteTom opened this issue Oct 9, 2023 · 2 comments
Open
Labels

Comments

@DiscreteTom
Copy link
Owner

E.g. when we parsing javascript:

f(({a, b}) => a + b);

with the following grammar rules:

exp := '(' '{' identifier (',' identifier)* '}' ')' '=>' exp
exp := '(' exp ')'
exp := object
object := '{' (object_entry (',' object_entry)*)? '}'
object_entry := identifier (':' exp)?

when we digest f(({ a we don't know whether the a is an object entry or an arrow function param. We have to peek maybe many tokens to judge that.

Solution for this issue:

  • Re-parse, see Re-parse for unresolved conflict? #19 . Not recommended.
  • Optimize grammar rules to prevent this to happen. Introducing more intermediate NT. Bad user experience.
  • Allow grammar rule to do more than reduce AST nodes. E.g. override parser buffer.
@DiscreteTom
Copy link
Owner Author

Maybe we can write an algorithm to check if a conflict can be safely resolved by re-parse.

For the above conflict, it can be safely resolved by re-parse without early accept.

DiscreteTom added a commit that referenced this issue Oct 12, 2023
@DiscreteTom
Copy link
Owner Author

Another idea: subset construction (子集构造法) to turn the NFA into DFA?

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

No branches or pull requests

1 participant