From: Skip Tavakkolian <9nut@9netics.com>
To: 9fans@9fans.net
Subject: Re: [9fans] bison problem, not plan9 related
Date: Wed, 21 Oct 2009 11:46:27 -0700 [thread overview]
Message-ID: <1728cb52259e9e0742678c43f729919a@9netics.com> (raw)
In-Reply-To: <a560a5d00910211052q2995c2afoae585c94f555947b@mail.gmail.com>
i think this is what you want. untested:
pair: REP ATOM
| REP '[' block ']'
block: pair
| block pair
> 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.
next prev parent reply other threads:[~2009-10-21 18:46 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-21 17:52 Rudolf Sykora
2009-10-21 18:03 ` Rudolf Sykora
2009-10-21 18:46 ` Skip Tavakkolian [this message]
2009-10-21 19:44 ` Rudolf Sykora
2009-10-21 18:47 ` Russ Cox
2009-10-21 19:41 ` Rudolf Sykora
2009-10-21 19:48 ` Rudolf Sykora
2009-10-21 20:21 ` Russ Cox
2009-10-21 20:28 ` Rudolf Sykora
2009-10-21 20:03 ` Bakul Shah
2009-10-21 20:18 ` Rudolf Sykora
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1728cb52259e9e0742678c43f729919a@9netics.com \
--to=9nut@9netics.com \
--cc=9fans@9fans.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).