Re: Solving a shift/reduce conflict with an explicit precedence

haberg@matematik.su.se (Hans Aberg)
25 Jul 2003 21:14:48 -0400

          From comp.compilers

Related articles
Solving a shift/reduce conflict with an explicit precedence mdhe51@dial.pipex.com (Paul Davis) (2003-07-23)
Re: Solving a shift/reduce conflict with an explicit precedence haberg@matematik.su.se (2003-07-25)
Re: Solving a shift/reduce conflict with an explicit precedence derkgwen@HotPOP.com (Derk Gwen) (2003-07-25)
| List of all articles for this month |

From: haberg@matematik.su.se (Hans Aberg)
Newsgroups: comp.compilers
Date: 25 Jul 2003 21:14:48 -0400
Organization: Mathematics
References: 03-07-170
Keywords: parse
Posted-Date: 25 Jul 2003 21:14:48 EDT

Paul Davis <mdhe51@dial.pipex.com> wrote:


>I'm having a problem getting rid of a shift/reduce conflict in Bison,
>and would appreciate advice on how to set some precedences to do this.
>My basic problem is that, for simplicity, I have an ambiguous syntax.
>This will never cause a problem in real usage, but I can't convince
>Bison of that. ...


The way LR algorithms, like the LALR(1) used by Bison, resolves
shift/reduce conflicts is by looking at the precedences/associativity of
the two tokens before/after the . in the conflicting shift/reduce items.


Thus, a look at the state with the shift/reduce conflict below suggests
that you should try to set a precedence relation between the '=' and NAME
token. For some reason, you seem to not have tried that one.


I described the details of this conflict resolving method in a recent post
in this newsgroup.


> I have rules of the form:
...
>%nonassoc NAME
>%nonassoc EXPCONST
>%nonassoc EXPNAME
...
>>>>-----------------------------------------------------
bison.output:


State 282 contains 1 shift/reduce conflict.


state 282


        dummy -> NAME '=' . const_expr (rule 115)
        dummy -> NAME '=' . NAME (rule 116)


        NAME shift, and go to state 346


        NAME [reduce using rule 221 (@15)]
        $default reduce using rule 221 (@15)


        const_expr go to state 347
        @15 go to state 60


______________________________________
<<<<


    Hans Aberg * Anti-spam: remove "remove." from email address.
                                    * Email: Hans Aberg <remove.haberg@member.ams.org>
                                    * Home Page: <http://www.math.su.se/~haberg/>
                                    * AMS member listing: <http://www.ams.org/cml/>


Post a followup to this message

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