From mboxrd@z Thu Jan 1 00:00:00 1970 To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> In-reply-to: Your message of "Wed, 21 Oct 2009 19:52:41 +0200." References: From: Bakul Shah Date: Wed, 21 Oct 2009 13:03:48 -0700 Message-Id: <20091021200349.40BFF5B2E@mail.bitblocks.com> Subject: Re: [9fans] bison problem, not plan9 related Topicbox-Message-UUID: 8dd09fc4-ead5-11e9-9d60-3106f5b1d025 Is this what you are trying to do? $ cat b.y <<'EOF' %token ATOM REP %% blocks: block | block blocks; block: ATOM | REP block | '[' blocks ']'; %% EOF $ bison b.y $ On Wed, 21 Oct 2009 19:52:41 +0200 Rudolf Sykora wrote: > Hello, > sorry for an off-topic thing. But I guess somebody here could help me... > I have a problem with bison grammer > > Having > > %token ATOM > %left '+' > %left REP > > and a grammar: > > block: ATOM > | REP block > | block '+' block > ; > > is ok. Having another grammer: > > block: ATOM > | REP block > | block block %prec '+' > ; > > has 2 shift/reduce conflicts, similar to > state 7 > > 5 block: REP block . > 6 | block . block > > ATOM shift, and go to state 3 > > ATOM [reduce using rule 5 (block)] > $default reduce using rule 5 (block) > > block go to state 9 > > or > state 9 > > 6 block: block . block > 6 | block block . > > ATOM shift, and go to state 3 > REP shift, and go to state 4 > > ATOM [reduce using rule 6 (block)] > $default reduce using rule 6 (block) > > block go to state 9 > > What I want is to have a parser that can read e.g. (the spaces are > left out by lex, they are not in what bison sees; I only write them > here for better readability) > 12 Au 13 Cu 2 Ag > the former grammer (REP is for repetition) is able to read > 12 Au + 13 Cu + 2 Ag > but I don't like those pluses, which are redundant. > > Also important: I have those 'block' non-terminals there, since I want > to add another rule > block: '[' block ']' > so that I can use brackets and can parse things like > 12 [ 2 Cu 3 Co] > > Could anyone explain to me what goes wrong? > I can't figure it out... > > Thanks a lot > Ruda > > PS.: the grammer is actually identical to a grammer that can evaluate > expressions with +, *, and brackets, with usual operator precedence. >