Re: An Odd Grammar Question (John McEnerney)
23 May 1998 00:41:58 -0400

          From comp.compilers

Related articles
An Odd Grammar Question (1998-05-15)
Re: An Odd Grammar Question (Vadim Maslov) (1998-05-17)
Re: An Odd Grammar Question (Joachim Durchholz) (1998-05-18)
Re: An Odd Grammar Question (Chris Dodd) (1998-05-18)
Re: An Odd Grammar Question (1998-05-23)
| List of all articles for this month |

From: (John McEnerney)
Newsgroups: comp.compilers
Date: 23 May 1998 00:41:58 -0400
Organization: Metrowerks, Inc.
References: 98-05-088 98-05-113
Keywords: parse, yacc, comment

Chris Dodd <> wrote:

> > 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.

I think the easiest solution is to define the READ/IF/etc -without- any
terminators, make END-READ, END-IF, and END-ALL top-level statements, and
use the semantic actions to match the ENDs or generate an error.

(There's no law that says syntax errors must detected by the parser, and
you can actually give a better error message this way)

This will avoid introducing any (additional) shift-reduce conflicts.

John McEnerney (
[I agree. You'll also be able to produce better error messages than
"syntax error". -John]

Post a followup to this message

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