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

Any other approach to handle left recursion #1708

Open
Chiichen opened this issue Nov 9, 2023 · 0 comments
Open

Any other approach to handle left recursion #1708

Chiichen opened this issue Nov 9, 2023 · 0 comments

Comments

@Chiichen
Copy link

Chiichen commented Nov 9, 2023

Knowing that I can handle left recursion cases by rewriting the grammar. But I am wondering if there is any other approach (since rewriting might greatly reduce the code readability beacause we can not easily infer the usage of a single combinator literraly) in some simple cases like recursively parsing an arithmetic grammar(I believe threre is no a general method to handle left recursion without rewriting grammar at current version).

Here is an example:

We have a left recuesive grammar :

  • E -> E op E (op = {'+','-','*','/','&','|',"==","!="})
  • E -> T (BuiltInType)
  • E -> F (Function Call)
  • E -> (E)

We rewrite it into:

  • E -> (E)E'
  • E -> TE'
  • E -> FE'
  • E'-> op E E' | ε

Before we rewrite it,each production can be clearly and easily described by a single combinator.But after rewriting the grammar, each production is coupling with E' which greatly reduces the self-explanation of combinators

#445 is a previous issue

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

1 participant