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

Associating %prec with a rule without any occurrences of tokens #101

Open
sgraf812 opened this issue May 22, 2023 · 0 comments
Open

Associating %prec with a rule without any occurrences of tokens #101

sgraf812 opened this issue May 22, 2023 · 0 comments

Comments

@sgraf812
Copy link

I want to parse ML-style whitespace sensitive function application using operator precedence, so I'd start from a grammar like

%left APP
%%
e : "f" 
  | e e %prec APP

and I would hope that this would be accepted without conflict by parsing chains of whitespace-separated "f" tokens as left-associated lists.
Alas, it appears that %prec declarations only work if the rule starts with a terminal, or some other hidden condition:

$ bison -v test.y -Wcounterexamples
test.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
test.y: warning: shift/reduce conflict on token "f" [-Wcounterexamples]
  Example: e e • "f"
  Shift derivation
    e
    ↳ 2: e e
           ↳ 2: e e
                  ↳ 1: • "f"
  Reduce derivation
    e
    ↳ 2: e          e
         ↳ 2: e e • ↳ 1: "f"

If I use an arbitrary infix operator @ instead and specify %left @, all conflicts can be resolved.

Is there some technical reason why the operator-less use case can't be supported?

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