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

"Ambiguous" left- and right- recursive rules should be an error #56

Open
alexwarth opened this issue Jan 31, 2016 · 1 comment
Open

Comments

@alexwarth
Copy link
Contributor

(See #55 for the backstory.)

Right now it's possible for Ohm programmers to write "ambiguous" left- and right-recursive rules in a grammar, e.g.,

AddExp
  = AddExp "+" AddExp  -- plus
  | AddExp "-" AddExp  -- minus
  | MulExp

This should be a compile-time error.

Why? Because the associativity of the + and - operators (see above) is not obvious, and it easily could have been. For instance, if you want them to associate to the left, then a much better way to write the above rule is:

AddExp
  = AddExp "+" MulExp  -- plus
  | AddExp "-" MulExp  -- minus
  | MulExp

And now the associativity is obvious. (Similarly, if right-associativity is desired, then AddExp should be rewritten to be right-recursive.)

@alexwarth alexwarth added the 1.0 label Jan 31, 2016
@pdubroy pdubroy added the uw label Oct 24, 2016
akeizer added a commit to akeizer/ohm that referenced this issue Nov 14, 2016
…ight associativity ambiguousness. Includes test to check change
@pdubroy
Copy link
Contributor

pdubroy commented Dec 1, 2021

I see a few issues with the implementation in #175:

  • it only detects a specific structure of left- and right- recursion (although it's probably the most common case in Ohm)
  • it doesn't detect some things that don't look like right recursion, but are. E.g., it wouldn't catch the following case:
    G {
      AddExp = AddExp "+" AddExp noop -- rec
             | digit
      noop =
    }
    

A solution for this should probably use the existing mechanism for detecting left recursion, and build on that. Since we do want to detect this statically, we will probably have to live with some limitations.

@pdubroy pdubroy removed 1.0 labels Sep 17, 2022
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