문제

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