From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: References: Date: Wed, 21 Oct 2009 11:47:36 -0700 Message-ID: Subject: Re: [9fans] bison problem, not plan9 related From: Russ Cox To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Topicbox-Message-UUID: 8da09dba-ead5-11e9-9d60-3106f5b1d025 > %token =C2=A0ATOM > %left =C2=A0 '+' > %left =C2=A0 REP > > block: =C2=A0 =C2=A0ATOM > =C2=A0 =C2=A0 =C2=A0 =C2=A0| REP block > =C2=A0 =C2=A0 =C2=A0 =C2=A0| block block %prec '+' > =C2=A0 =C2=A05 block: REP block . > =C2=A0 =C2=A06 =C2=A0 =C2=A0 =C2=A0| block . block > > =C2=A0 =C2=A0ATOM =C2=A0shift, and go to state 3 > > =C2=A0 =C2=A0ATOM =C2=A0 =C2=A0 =C2=A0[reduce using rule 5 (block)] This says that yacc isn't sure how to decide, having read REP block, between shifting ATOM or applying the REP block reduction. > 6 block: block . block > 6 | block block . > > ATOM shift, and go to state 3 > > ATOM [reduce using rule 6 (block)] This says that yacc isn't sure how to decide, having read block block, between shifting ATOM or applying the block block reduction. To know how to decide, yacc needs a precedence for the thing being shifted and the rule. You've given precedences for each rule (REP block has REP's precedence, and block block has +'s thanks to the override) but not to ATOM. Concretely, when yacc sees REP block ATOM it isn't sure whether that's (REP block) ATOM or REP (block ATOM). Instead of > %token ATOM > %left '+' > %left REP you probably want %left '+' %left REP %nonassoc ATOM This wasn't an issue in the first grammar because the shift/reduce decision had to be made when looking at the '+' instead of when looking at ATOM, and the '+' did have a precedence. Russ