質問

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

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top