help-bison
[Top][All Lists]
Advanced

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

GLR ambiguity


From: Alessandro Di Marco
Subject: GLR ambiguity
Date: Thu, 14 Jun 2007 12:48:16 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1.50 (gnu/linux)

Hi all.

I was trying to create a GLR grammar for natural languages when I stuck on the
following s/r ambiguity.

Ambiguity detected.
Option 1,
  text -> <Rule 2, tokens 1 .. 6>
    text -> <Rule 2, tokens 1 .. 3>
      text <empty>
      sentence -> <Rule 4, tokens 1 .. 3>
        DOUBLEQ <tokens 1 .. 1>
        WORD <tokens 2 .. 2>
        EOL <tokens 3 .. 3>
    sentence -> <Rule 4, tokens 4 .. 6>
      DOUBLEQ <tokens 4 .. 4>
      WORD <tokens 5 .. 5>
      EOL <tokens 6 .. 6>

Option 2,
  text -> <Rule 2, tokens 1 .. 6>
    text -> <Rule 2, tokens 1 .. 4>
      text <empty>
      sentence -> <Rule 5, tokens 1 .. 4>
        DOUBLEQ <tokens 1 .. 1>
        WORD <tokens 2 .. 2>
        EOL <tokens 3 .. 3>
        DOUBLEQ <tokens 4 .. 4>
    sentence -> <Rule 3, tokens 5 .. 6>
      WORD <tokens 5 .. 5>
      EOL <tokens 6 .. 6>

ERROR!
Cleanup: popping token $end ()
Cleanup: popping unresolved nterm text ()
Cleanup: popping unresolved nterm sentence ()
Cleanup: popping token EOL ()
Cleanup: popping token WORD ()
Cleanup: popping token DOUBLEQ ()
Cleanup: popping unresolved nterm text ()
Cleanup: popping unresolved nterm sentence ()
Cleanup: popping token EOL ()
Cleanup: popping token WORD ()
Cleanup: popping token DOUBLEQ ()
Cleanup: popping nterm text ()
Cleanup: popping token $end ()

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
        ;

where:

[[:alnum:]]+ return WORD;

\" return DOUBLEQ;

\. return EOL;

I've also attached a q&d demo of the problem; simply untar, make and execute
'./demo'. Tested both on bison 2.2 and 2.3... won't work! :-)

Thanks in advance.

Best,
Alessandro

--
A problem is a chance for you to do your best. - Duke Ellington





reply via email to

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