|An Odd Grammar Question firstname.lastname@example.org (1998-05-15)|
|Re: An Odd Grammar Question email@example.com (Vadim Maslov) (1998-05-17)|
|Re: An Odd Grammar Question firstname.lastname@example.org (Joachim Durchholz) (1998-05-18)|
|Re: An Odd Grammar Question email@example.com (Chris Dodd) (1998-05-18)|
|Re: An Odd Grammar Question firstname.lastname@example.org (1998-05-23)|
|From:||email@example.com (William Moran)|
|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,
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.
[Yuck. I suspect that the lexical counting hack is about as good as
you're likely to do. -John]
Return to the
Search the comp.compilers archives again.