Re: shift/reduce problem

JohnSmith <csnews77@gmail.com>
Fri, 3 Dec 2010 05:49:00 -0800 (PST)

          From comp.compilers

Related articles
shift/reduce problem csnews77@gmail.com (JohnSmith) (2010-12-02)
Re: shift/reduce problem haberg-news@telia.com (Hans Aberg) (2010-12-03)
Re: shift/reduce problem csnews77@gmail.com (JohnSmith) (2010-12-03)
Re: shift/reduce problem haberg-news@telia.com (Hans Aberg) (2010-12-03)
Re: shift/reduce problem gene.ressler@gmail.com (Gene) (2010-12-03)
Re: shift/reduce problem chakaram@auth.gr (Chariton Karamitas) (2010-12-05)
Re: shift/reduce problem seimarao@gmail.com (Seima) (2010-12-30)
Re: shift/reduce problem kaz@kylheku.com (Kaz Kylheku) (2011-10-20)
| List of all articles for this month |

From: JohnSmith <csnews77@gmail.com>
Newsgroups: comp.compilers
Date: Fri, 3 Dec 2010 05:49:00 -0800 (PST)
Organization: Compilers Central
References: 10-12-004 10-12-006
Keywords: parse
Posted-Date: 03 Dec 2010 10:46:48 EST

On Dec 3, 12:44 am, Hans Aberg <haberg-n...@telia.com> wrote:
> On 2010/12/02 21:29, JohnSmith wrote:
>
> > I'm using bison and flex. Bison reports shift/reduce conflict:
> > probably because cannot decide on "," when "input" coming (is this an
> > error or should reduce). How to resolve this problem? Probably I have
> > to use %left, %right, %prec but I dont know how.
>
> Use the flags
> bison --verbose --report=all
> to get the .output file. Look for the state, and in it, the conflicting
> rules, and in those, the two tokens immediately before and after the
> parsing position ".". The token precedences %left, ..., set preferences
> between those pairs.
>
> Hans


State 483 conflicts: 1 shift/reduce


state 483


    165 input_declaration0: K_input opt_range list_of_variables .
[K_COMMA, K_RIGHTPAREN]
    181 list_of_variables: list_of_variables . K_COMMA name_of_variable


        K_COMMA shift, and go to state 210


        K_COMMA [reduce using rule 165 (input_declaration0)]
        $default reduce using rule 165 (input_declaration0)


I set this preference
%left K_IDENTIFIER K_COMMA K_RIGHTPAREN
(tried %left K_COMMA K_RIGHTPAREN also)


But still got shift/reduce conflict, and syntax error when parsing the
file.


The full ouput file is here
http://www.sendspace.com/file/kp8qz2


Thanks
  John
[Hmmn. This is an LR(2) grammar. There must be a way to rewrite it as LR(1) but I have to say
I don't immediately see what it is. -John]



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.