Pregunta

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

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top