NEED HELP W/ IF-THEN-ELSE IN YACC

lbplum@csuchico.edu
Thu, 26 Apr 90 23:48:20 GMT

          From comp.compilers

Related articles
NEED HELP W/ IF-THEN-ELSE IN YACC lbplum@csuchico.edu (1990-04-26)
| List of all articles for this month |

Newsgroups: comp.compilers
From: lbplum@csuchico.edu
From: lbplum@csuchico.edu
Organization: California State University, Chico
Date: Thu, 26 Apr 90 23:48:20 GMT

we have it defined as:


conditional: IF
                                    boolean
                                    THEN
                                    statement_list
                                    else_statement
;


else_statement: empty
                                    |ELSE
                                    statement_list
;


Does anybody know a way to fix it so it does not give us a shift/reduce error?
(Right now, we get one shift/reduce error with the method mentioned above.)


[This is the dangling else ambiguity, the absolute most classic and well-known
syntactic ambiguity encountered in common programming languages. Aho, Sethi,
and Ullman discuss it a length in chapter 4 of their Compilers book. The
short answer is that you can either leave it alone, since yacc's resolution of
the conflict happens to be the right one, or else add more productions. -John]





Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.