An Odd Grammar Question

wlm@panix3.panix.com (William Moran)
15 May 1998 22:35:08 -0400

          From comp.compilers

Related articles
An Odd Grammar Question wlm@panix3.panix.com (1998-05-15)
Re: An Odd Grammar Question vadik@siber.com (Vadim Maslov) (1998-05-17)
Re: An Odd Grammar Question joachim.durchholz@munich.netsurf.de (Joachim Durchholz) (1998-05-18)
Re: An Odd Grammar Question chrisd@etcons.com (Chris Dodd) (1998-05-18)
Re: An Odd Grammar Question johnmce@world.std.com (1998-05-23)
| List of all articles for this month |

From: wlm@panix3.panix.com (William Moran)
Newsgroups: comp.compilers
Date: 15 May 1998 22:35:08 -0400
Organization: PANIX Public Access Internet and Unix, NYC
Keywords: parse, question, yacc

I have the following odd Yacc problem. Assume that we have three kinds of
productions (key words are in caps):


read -> READ some_stuff END-READ
if -> IF some-stuff END-IF
foo -> END-ALL FOO some-stuff END-FOO


the problem is that the END-ALL terminates and replaces all of the other
ENDs one would expect. So,


READ ...
READ ...
READ ...
END-ALL


i.e. we would have been expecting 3 END-READs, and instead we got 1 END-ALL,
and this is legal. Anyone know of an easy way to express this sort of
thing in Yacc (I have thought about pushing the token back on the stream
the appropriate number of times).


The grammar becomes something like:


read -> READ some_stuff (END-READ|END-ALL)
if -> IF some-stuff (END-IF|END-ALL)
foo -> END-ALL FOO ...


One horrible thing I have though of is to have the lexer act as if it
had gotten N END-ALL tokens (where N is the nesting level). I'd be
interested in hearing any suggestions for how to handle this - aside
from shooting the person who designed this language.


Thanks in advance.


Bill Moran
[Yuck. I suspect that the lexical counting hack is about as good as
you're likely to do. -John]




--


Post a followup to this message

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