Pergunta

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

Foi útil?

Solução

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 em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top