Reputation: 359
I have this grammar in EBNF notation:
expr -> expr (opt1 | opt2 | opt3) expr
And i want to convert it to BNF to use it in Bison but i get shift/reduce errors in this:
expr : expr opt1 expr | expr opt2 expr | expr opt3 expr
I guess i misunderstood something along the way. Any help?
Thanks
Upvotes: 0
Views: 939
Reputation: 28782
How about
expr: expr optexpr expr
optexpr: opt1 | opt2 | opt3
The shift/reduce erros are due to the overlapping expr prefixes. By introducing another definition, the parsing of expr becomes unambiguous.
Upvotes: 3