How do I trace down source of shift/reduce error

View: New views
5 Messages — Rating Filter:   Alert me  

How do I trace down source of shift/reduce error

by roger_p :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am having a problem tracking down a shift reduce error I'm
getting with my grammar.

The error is
java.lang.RuntimeException:

shift/reduce conflict in state [stack: TLBkt TIdentifier TQmark *]
on TIdentifier in {
        [ PPrimaryExpression = TIdentifier TQmark * TIdentifier TBlank ] (shift),
        [ PPrimaryExpression = TIdentifier TQmark * TIdentifier ] (shift),
        [ PPrimaryExpression = TIdentifier TQmark * ] followed by TIdentifier (reduce)
}
and so, based on the stack contents, I have been trying to find
ways that the PPrimaryExpression production could be ambiguous in
this case.  As I read the error message, it means that it is possible to have a case
where I have a TIdentifer TQMark followed by another TIdentifier and that is ambigous.  
My problem is I don't see that from the grammar; it seems like that should not be ambigous.
(Which of course means I'm reading it wrong; as much as I hate to admit it, I have
yet to be smarter than SableCC when it comes to this :)  )
  So, I'd like some help with 2 things.  First, from a pragmatic point of
view can anyone identify where the problem is?  Secondly, and more
importantly, please help explain to me the reasoning you took or
the clues you looked at in order to see the problem, based on the
output from sable  so that I can learn how to track these down
myself.

The problem arose only after i added in the grammar a "WildObject"
production that is supposed to allow the user to specify names of a
form like:
    ABC?
    ?ABC
    ?ABC?
    ABC?DEF

in addition to the previous allowance for names just like ABC, etc.
   wild_object =
      {start}   identifier qmark
    | {endwith} qmark identifier
    | {both}    qmark identifier [q2]:qmark
    | {middle}  identifier qmark [i2]:identifier
    ;

The grammar is attached; any help would be appreciated!

Thanks!

Roger


--
Be Yourself @ mail.com!
Choose From 200+ Email Addresses
Get a Free Account at www.mail.com



_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

Syntax12.sablecc (87K) Download Attachment

Re: How do I trace down source of shift/reduce error

by Etienne M. Gagnon :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Roger,

Hmm... That's not a simple grammar. I have difficulty, too, seeing where
one can put an identifier (or something that starts with one) right
after an expression. I will need SableCC 4 to solve this one. SableCC 4
will soon give me precise conflict information (e.g. two full trees with
common prefix and lookahead, illustrating the two conflicting choices).
SableCC 3 already helped you a little by inlining your wild object
production, so that you know that it is an expression related problem.
But, obviously, the SableCC 4 approach is what we need here.

Maybe you could try a different syntax, for wild objects. Maybe you
could you use some delimiters, such as "{" or "'" e.g. {ABC?DEF} .

Etienne
PS: As soon as the engine allows for it, I'll throw your grammar into it
and report back about it. Thanks for the interesting test case. :-)

Roger Pomeroy a écrit :

> I am having a problem tracking down a shift reduce error I'm
> getting with my grammar.
>
> The error is
> java.lang.RuntimeException:
>
> shift/reduce conflict in state [stack: TLBkt TIdentifier TQmark *]
> on TIdentifier in {
> [ PPrimaryExpression = TIdentifier TQmark * TIdentifier TBlank ] (shift),
> [ PPrimaryExpression = TIdentifier TQmark * TIdentifier ] (shift),
> [ PPrimaryExpression = TIdentifier TQmark * ] followed by TIdentifier (reduce)
> }[...]
>  
--
Etienne M. Gagnon, Ph.D.
SableCC:                                            http://sablecc.org




_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

signature.asc (265 bytes) Download Attachment

Parent Message unknown Re: How do I trace down source of shift/reduce error

by roger_p :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for looking at it.  I'm looking forward to when you can use SableCC 4 on it as well, since it will have features that will help a lot with this grammar.  And while I agree it is not a simple grammar, this has been SOOO much easier than trying to do this with any other grammar/compiler tool I've tried!


> ----- Original Message -----
> From: "Etienne M. Gagnon" <egagnon@...>
> To: "Discussion mailing list for the SableCC project" <sablecc-discussion@...>
> Subject: Re: How do I trace down source of shift/reduce error
> Date: Fri, 06 Mar 2009 10:55:47 -0500
>
>
> Hi Roger,
>
> Hmm... That's not a simple grammar. I have difficulty, too, seeing where
> one can put an identifier (or something that starts with one) right
> after an expression. I will need SableCC 4 to solve this one. SableCC 4
> will soon give me precise conflict information (e.g. two full trees with
> common prefix and lookahead, illustrating the two conflicting choices).
> SableCC 3 already helped you a little by inlining your wild object
> production, so that you know that it is an expression related problem.
> But, obviously, the SableCC 4 approach is what we need here.
>
> Maybe you could try a different syntax, for wild objects. Maybe you
> could you use some delimiters, such as "{" or "'" e.g. {ABC?DEF} .
>
> Etienne
> PS: As soon as the engine allows for it, I'll throw your grammar into it
> and report back about it. Thanks for the interesting test case. :-)
>
> Roger Pomeroy a écrit :
> > I am having a problem tracking down a shift reduce error I'm
> > getting with my grammar.
> >
> > The error is
> > java.lang.RuntimeException:
> >
> > shift/reduce conflict in state [stack: TLBkt TIdentifier TQmark
> > *] on TIdentifier in {
> > [ PPrimaryExpression = TIdentifier TQmark * TIdentifier TBlank ] (shift),
> > [ PPrimaryExpression = TIdentifier TQmark * TIdentifier ] (shift),
> > [ PPrimaryExpression = TIdentifier TQmark * ] followed by
> > TIdentifier (reduce)
> > }[...]
> >
>
> --
> Etienne M. Gagnon, Ph.D.
> SableCC:                                            http://sablecc.org
> << signature.asc >>
>
> _______________________________________________
> SableCC-Discussion mailing list
> SableCC-Discussion@...
> http://lists.sablecc.org/listinfo/sablecc-discussion

>


--
Be Yourself @ mail.com!
Choose From 200+ Email Addresses
Get a Free Account at www.mail.com


_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

Re: How do I trace down source of shift/reduce error

by roger_p :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Etienne...
I found the error (by trial and error eliminating statements till I got one that worked).  I had specified in the grammar:

 function_statement {->statement} =
        function [name]:function_call  [blank1]:blank?
                         [description]:description_text?
                         [args]:formal_arg_list*    //  <-------------heres the line causing the problem
                   r_par [blank2]:blank?  as_type? new_line
                     [body]:statement*
                   endfunction [nl2]:new_line

But what I should have had was the [args]:formal_arg_list?  (that is, I wanted 0 or 1, not 0 or more) and that was where the shift/reduce conflict was coming from.

So, found one problem... but I am still looking forward to when I can try SableCC 4 on this!  

Thanks
Roger



Etienne M. Gagnon wrote:
Hi Roger,

Hmm... That's not a simple grammar. I have difficulty, too, seeing where
one can put an identifier (or something that starts with one) right
after an expression. I will need SableCC 4 to solve this one. SableCC 4
will soon give me precise conflict information (e.g. two full trees with
common prefix and lookahead, illustrating the two conflicting choices).
SableCC 3 already helped you a little by inlining your wild object
production, so that you know that it is an expression related problem.
But, obviously, the SableCC 4 approach is what we need here.

Maybe you could try a different syntax, for wild objects. Maybe you
could you use some delimiters, such as "{" or "'" e.g. {ABC?DEF} .

Etienne
PS: As soon as the engine allows for it, I'll throw your grammar into it
and report back about it. Thanks for the interesting test case. :-)

Roger Pomeroy a écrit :
> I am having a problem tracking down a shift reduce error I'm
> getting with my grammar.
>
> The error is
> java.lang.RuntimeException:
>
> shift/reduce conflict in state [stack: TLBkt TIdentifier TQmark *]
> on TIdentifier in {
> [ PPrimaryExpression = TIdentifier TQmark * TIdentifier TBlank ] (shift),
> [ PPrimaryExpression = TIdentifier TQmark * TIdentifier ] (shift),
> [ PPrimaryExpression = TIdentifier TQmark * ] followed by TIdentifier (reduce)
> }[...]
>  

--
Etienne M. Gagnon, Ph.D.
SableCC:                                            http://sablecc.org



 
_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@lists.sablecc.org
http://lists.sablecc.org/listinfo/sablecc-discussion

Re: How do I trace down source of shift/reduce error

by Etienne M. Gagnon :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Roger,

Thanks for the update! I'll keep you informed when I get SableCC 4
conflict information on your original grammar.

Have fun!

Etienne

roger_p wrote:
> Etienne...
> I found the error (by trial and error eliminating statements till I got one
> that worked).  I had specified in the grammar:
> [...]
>  

--
Etienne M. Gagnon, Ph.D.
SableCC:                                            http://sablecc.org




_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

signature.asc (265 bytes) Download Attachment