help-bison
[Top][All Lists]
Advanced

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

Re: GLR ambiguity


From: Tim Van Holder
Subject: Re: GLR ambiguity
Date: Thu, 14 Jun 2007 14:17:26 +0200
User-agent: Thunderbird 2.0.0.0 (Windows/20070326)

Alessandro Di Marco wrote:
> Hi all.
>
> It seems that both the options above are valid, so they need
> disambiguation. I've tried '%dprec' (as also suggested in bison
manual), but
> without any success.
>
> For your convenience I have stripped down the grammar to the below few
lines,
> which produce the above result.
>
> text:
>         /* empty */
>       | text sentence
>       ;
>
> sentence:
>         WORD EOL
>       | DOUBLEQ WORD EOL
>       | DOUBLEQ WORD EOL DOUBLEQ
>       ;

Well, without a clearer idea of what your grammar is supposed to allow,
it's hard to suggest ways around this. As it stands now, the parser
cannot know how to proceed after seeing DOUBLEQ WORD EOL when the next
token is DOUBLEQ -- that could either initiate a new sentence, or
terminate the current one, and what's worse, both cases lead to valid
productions in your example. Your example input ("DOUBLEQ WORD EOL
DOUBLEQ WORD EOL") can be split into sentences in 2 ways: 2 "DOUBLEQ
WORD EOL" groupings, or "DOUBLEQ WORD EOL DOUBLEQ" + "WORD EOL".
So your grammar is broken.

Your intent seems to be to allow sentences to be quoted; would something
like this work for you?

text
: /* empty */
| text sentence
| text DOUBLEQ sentences DOUBLEQ
;

sentences
: sentence
| sentences sentence
;





reply via email to

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