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) |
From: | Gene <gene.ressler@gmail.com> |
Newsgroups: | comp.compilers |
Date: | Fri, 3 Dec 2010 19:20:36 -0800 (PST) |
Organization: | Compilers Central |
References: | 10-12-004 10-12-006 10-12-007 |
Keywords: | parse, LR(1) |
Posted-Date: | 03 Dec 2010 22:52:54 EST |
On Dec 3, 8:49 am, JohnSmith <csnew...@gmail.com> wrote:
> 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 herehttp://www.sendspace.com/file/kp8qz2
> [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]
Here's one way that works, though this will use stack proportional to
the input length. You could use the original approach if you have the
lexer return a single token for comma followed by input keyword.
%token K_input K_LEFTPAREN K_COMMA K_RIGHTPAREN IDENTIFIER
%%
top_rule: K_LEFTPAREN function_port_list K_RIGHTPAREN
function_port_list
: K_input IDENTIFIER function_port_list_tail
;
function_port_list_tail
: /* nothing */
| K_COMMA IDENTIFIER function_port_list_tail
| K_COMMA function_port_list
;
Return to the
comp.compilers page.
Search the
comp.compilers archives again.