Hi Ashraf,
Ashraf Haddad wrote:
> 1) AS can be seen from the grammar below of joos the ifelse
> production has no short_if in it. This is done to clear ambiguities
> about if stms.
This is a standard grammar-modification technique to eliminate the well
known "dangling else" ambiguity from a grammar (without modifying the
language accepted by the grammar).
> 2) How do I integrate this in my grammar shown below?
Note that it would be much easier, in general, if you:
1- removed CST->AST directives from the grammar (usually, one adds
CST->AST directives once the grammar is stable), and
2- provided the (cleaned) grammar file as attachment when asking for
help, so that people can play with your grammar to seek solutions
This being said, I'll try helping you. See below.
> stm =
> ...
> {if} T.if l_par exp r_par l_brace stm+ r_brace identifiers
> {ifelse} T.if l_par exp r_par [firstl]:l_brace [if_stm]:stm+ [firstr]:r_brace T.else [secondl]:l_brace [else_stm]stm+ [secondr]:r_brace identifiers
> ...
By adding explicit "l_brace" and "r_brace" around the "stm+", you have
modified the language and eliminated the well known "dangling else"
ambiguity from the grammar. So, you don't need the stm_no_if production
anymore.
[Assuming you are taking / have taken a compiler course, you should ask
prof. Hendren to re-explain to you the dangling-else ambiguity and its
solution; it could be useful to understand it for future projects of yours].
> reduce/reduce conflict in state [stack: PMitrionStm PTypes TIdentifier TLPar PArguments TRPar TLBrace PIdentifiers TAssign TIf TLPar PExp TRPar TLBrace PExp TSemicolon *] on TInt in {
> [ P$Stm = PExp TSemicolon * ] followed by TInt (reduce),
> [ P$StmNoif = PExp TSemicolon * ] followed by TInt (reduce)
> }
I guess that you have a production that expands to both stm and
stm_no_if. This would effectively be ambiguous and raise the above
reduce/reduce conflict.
Simply get rid of the *_no_if productions and everything should start
working.
Have fun!
Etienne
>
>
>
> * Any Ideas please? *
>
>
>
>
>
>
>
> Many thanks,
>
> Ashraf Haddad
>
>
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> SableCC-user mailing list
> SableCC-user@xxxxxxxxxxx
> http://sablecc.org/lists/control/listinfo/sablecc-user
--
Etienne M. Gagnon, Ph.D. http://www.info2.uqam.ca/~egagnon/
SableVM: http://www.sablevm.org/
SableCC: http://www.sablecc.org/
Attachment:
signature.asc
Description: OpenPGP digital signature