Related articles |
---|
ANSI C grammar without shift-reduce conflict on 'ELSE' ggrares@yahoo.com (Rares GalaN) (2007-12-09) |
Re: ANSI C grammar without shift-reduce conflict on 'ELSE' cbarron3@ix.netcom.com (2007-12-09) |
Re: ANSI C grammar without shift-reduce conflict on 'ELSE' gah@ugcs.caltech.edu (glen herrmannsfeldt) (2007-12-09) |
Re: ANSI C grammar without shift-reduce conflict on 'ELSE' anton@mips.complang.tuwien.ac.at (2007-12-10) |
Re: ANSI C grammar without shift-reduce conflict on 'ELSE' anton@mips.complang.tuwien.ac.at (2007-12-10) |
Re: ANSI C grammar without shift-reduce conflict on 'ELSE' monnier@iro.umontreal.ca (Stefan Monnier) (2007-12-12) |
From: | cbarron3@ix.netcom.com (Carl Barron) |
Newsgroups: | comp.compilers |
Date: | Sun, 9 Dec 2007 17:39:50 -0500 |
Organization: | Posted via Supernews, http://www.supernews.com |
References: | 07-12-021 |
Keywords: | C, yacc |
Posted-Date: | 09 Dec 2007 20:55:27 EST |
Rares GalaN <ggrares@yahoo.com> wrote:
> Hello,
>
> I'm trying to use the ANSI C Grammar from
> http://www.lysator.liu.se/c/ANSI-C-grammar-y.html and I'm getting a
> "shift - reduce on ELSE" error. I'm quite new with this, so it would
> really be useful if I could get a grammar that's conflict free. Any
> suggestions will help.
If you are using bison ,yacc or a work-alike then the generator
defaults to shift, as per the usual semantics of C,Pascal,Modula2 etc.
of the dangling else problem. So either ignore the warning or if using
Bison there is a %expect N declaration that says there are N shift
reduce conflicts where shifting is desired. See bison.info-3.
--quote--
Since the parser prefers to shift the `ELSE', the result is to attach
the else-clause to the innermost if-statement, making these two inputs
equivalent:
if x then if y then win (); else lose;
if x then do; if y then win (); else lose; end;
But if the parser chose to reduce when possible rather than shift,
the result would be to attach the else-clause to the outermost
if-statement, making these two inputs equivalent:
if x then if y then win (); else lose;
if x then do; if y then win (); end; else lose;
--end quote
Return to the
comp.compilers page.
Search the
comp.compilers archives again.