help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: shift/reduce and reduce/reduce conflicts


From: Hans Aberg
Subject: Re: shift/reduce and reduce/reduce conflicts
Date: Fri, 23 Jan 2004 20:04:29 +0100

At 19:16 +0100 2004/01/23, wim delvaux wrote:
>       Conflicts occur when your parser cannot determine the next move to
>take in a
>presice manner
>
>       example
>
>       a : Token1 Token2
>           | Token1 Token3
>       ;
>
>       when the scanner finds token1 what comes next a 2 or 3 token ?
>Answer : it
>depends on the input syntax.

Even though the idea is right, the example is poorly chosen: The LALR(1)
parsing algorithm that Bison uses will produce items which are sets of
rules with a dot in the RHS, indicating how far the parsing has progressed.
So in the example above, one would get a state containing
    a -> Token1 . Token2
    a -> Token1 . Token3
Then, when at the "." in the parsing, it is easy to see which rule to
reduce, depending on whether the lookahead is Token2 or Token3, assuming
these tokens are different.

  Hans Aberg






reply via email to

[Prev in Thread] Current Thread [Next in Thread]