Related articles |
---|
How to convert LR(1) to LL(k) ? Patrickl@macau.ctm.net (1997-03-16) |
From: | Patrickl@macau.ctm.net |
Newsgroups: | comp.compilers |
Date: | 16 Mar 1997 23:36:46 -0500 |
Organization: | Macau CTM InterNetNews site |
Keywords: | parse, LL(1), LR(1) |
Hi
I am a new user of PCCTS and am trying to write a translator with it.
However I found the following productions which goes well with
yacc/bison have generated ambiguities with the PCCTS:
/* the dangling else problem */
stmt : matched_stmt
| unmatched_stmt
;
matched_stmt: IF EXPR THEN matched_stmt ELSE matched_stmt
| OTHER_STMT
;
unmatched_stmt: IF EXPR THEN stmt
| IF EXPR THEN matched_stmt ELSE unmatched_stmt
;
ANTLR gives me the following Warring message
for stmt : Warning warning: alts 1 and 2 of the rule itself ambiguous
upon {IF }, { EXPR }, { THEN }, { IF OTHER_STMT }
for unmatched_stmt : Warning warning: alts 1 and 2 of the rule itself
ambiguous upon {IF }, { EXPR }, { THEN }, { IF OTHER_STMT }
How can I change the grammer and/or add predicate to avoid the warning
message!?
Is there any guideline that can be used to change the LR(1) grammar to
LL(k)?
Many thanks
Patrick Lee
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.