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

Issue with reduce/reduce conflicts #40

Open
TorbenMogensen opened this issue Jun 19, 2015 · 0 comments
Open

Issue with reduce/reduce conflicts #40

TorbenMogensen opened this issue Jun 19, 2015 · 0 comments

Comments

@TorbenMogensen
Copy link

Consider this grammar file:

%token ONE MINUS MIN

%left MINUS
%right UMINUS
%right MIN

%start Exp
%type Exp

%%

Exp:
ONE { 1 }
| Exp MINUS Exp { $1 - $3) }
| MINUS Exp %prec UMINUS { - $2 }
| MIN Exp Exp { min $2 $3 }
;

%%

With mosmlyac, this generates no conflict, but with fsyacc, it generates three reduce/reduce conflicts:

state 4: reduce/reduce error on ONE
state 4: reduce/reduce error on MINUS
state 4: reduce/reduce error on MIN

State 4 has the following items:

Exp -> Exp . 'MINUS' Exp
Exp -> Exp 'MINUS' Exp . 
Exp -> 'MINUS' Exp .

Given that the unary minus has higher precedence than the infix minus, there should be no conflict: There should be a reduce on the last production in the item set. So it seems that precedence declarations are ignored when resolving reduce/reduce conflicts.

Peter Sestoft tells me that he resolved this issue in mosmlyac (which is also based on ocamlyacc), as well as an isse with %nonassoc, around 10 years ago.

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

2 participants