if-then-else problem, help.

View: New views
3 Messages — Rating Filter:   Alert me  

if-then-else problem, help.

by Hisashi Nakai :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi Etienne,

  I think C-like if-then-else production rule makes shift/reduce
conflict. Do you think that whether the conflict happens or not
is depend on the statement-part ?

  My student translated a yacc grammar to sablecc's one.
  At first, he deleted the if-then-else rule and the sablecc
accepted his grammar. Then he added the if-then-else rule.
But sablecc accepted it.

  I am wondering that it may happen.
  I cut out and simplify the if-then-else part for testing
whether it makes the conflict or not.

Productions
  stmt = {if} if lpar expr rpar stmt |
         {if_else} if lpar expr rpar [stmt1]:stmt else [stmt2]:stmt |
         {print}   while;

  expr = const;


  Sablecc issues the messages of the conflict.
  But his grammar contains if-then-else rule but sablecc does not
issue any message for conflict.

  Please give me some hints or your opinion about this.
  I use sablecc 3.2.

  I put the grammar on

http://nakataf.slis.tsukuba.ac.jp/~nakai/c2.grammar

  Thanks in advance.
--
Nakai, Hisashi
University of Tsukuba
E-mail: nakai@...

_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

Re: if-then-else problem, help.

by Etienne M. Gagnon :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Hisashi,

The first production, in the Productions section, is used as start production by SableCC. In your c2.grammar file, the start production is primary_expr, which is obviously not an appropriate start production to the full C syntax. By adding an appropriate start production, you will definitely get a shift/reduce conflict on the if statement ambiguity.

Have fun!

Etienne

Hisashi Nakai wrote:
Hi Etienne,

  I think C-like if-then-else production rule makes shift/reduce
conflict. Do you think that whether the conflict happens or not
is depend on the statement-part ?
[...]
  But his grammar contains if-then-else rule but sablecc does not
issue any message for conflict.

  Please give me some hints or your opinion about this.
  I use sablecc 3.2.

  I put the grammar on

http://nakataf.slis.tsukuba.ac.jp/~nakai/c2.grammar
  

-- 
Etienne M. Gagnon, Ph.D.
SableCC:                                            http://sablecc.org


_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion

signature.asc (265 bytes) Download Attachment

Re: if-then-else problem, help.

by Hisashi Nakai :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi Etienne,

  Thank you very much!

In Message-ID: <4979E1F2.50509@...>
"Etienne M. Gagnon" <egagnon@...> wrote  :

> Hi Hisashi,
>
> The first production, in the /Productions/ section, is used as start
> production by SableCC. In your c2.grammar file, the start production is
> primary_expr, which is obviously not an appropriate start production to
> the full C syntax. By adding an appropriate start production, you will
> definitely get a shift/reduce conflict on the /if/ statement ambiguity.
>
> Have fun!
>
> Etienne
>
> Hisashi Nakai wrote:
> > Hi Etienne,
> >
> >   I think C-like if-then-else production rule makes shift/reduce
> > conflict. Do you think that whether the conflict happens or not
> > is depend on the statement-part ?
> > [...]
> >   But his grammar contains if-then-else rule but sablecc does not
> > issue any message for conflict.
> >
> >   Please give me some hints or your opinion about this.
> >   I use sablecc 3.2.
> >
> >   I put the grammar on
> >
> > http://nakataf.slis.tsukuba.ac.jp/~nakai/c2.grammar
> >  
>
> --
> Etienne M. Gagnon, Ph.D.
> SableCC:                                            http://sablecc.org
>
--
Nakai, Hisashi
University of Tsukuba
E-mail: nakai@...

_______________________________________________
SableCC-Discussion mailing list
SableCC-Discussion@...
http://lists.sablecc.org/listinfo/sablecc-discussion