質問

I have the following grammar in a Bison file:

lst: ID COMMA lst
   | ID
   | /*empty*/

plst: lst SEMICOLON lst
    | SEMICOLON lst
    | lst

WHere the first rule actually tries to map a list of identifiers like id1,id2,id3...

And the second wants to map a posible couple of lists separated by a semicolon. Allowed possibilities are: id11,id12,id13...;id21,id22,id23..., id1,id2,id3... or ;id1,id2,id3....

I was wondering if this is a correct set of rules as Bison is returning many conflicts. I thought one of possible problems might be not well formed rules. So my question is: the aforementioned set of rules, is a good one or it is coflict-prone? Thankyou.

役に立ちましたか?

解決

The problem is that you allow lst to be empty. So there is no way to distinguish between:

lst ';' lst

and

';' lst

In other words, is the lst empty or absent? The grammar is ambiguous.

I'd remove the empty production for lst, but there are other solutions.

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