|existential yacc question (spoiler) firstname.lastname@example.org (1997-10-16)|
|From:||email@example.com (Christopher Seiwald)|
|Date:||16 Oct 1997 00:17:44 -0400|
I came across an interesting yacc problem, due to the differences in
the error handling between berkeley yacc and at&t yacc. I had looked
here for answers and, finding none, figured I should provide one.
The existential question is: if you have something that can't reduce
empty but can reduce as an error, and that something is missing from
the input stream, is it really there? That it, does yacc reduce that
something as an error and then shift the parent rule, or does it fail
the parent rule because that something is missing?
An example helps: you have a "program":
program : program statement
statement : (a variety of possibilities)
| BEGIN program END
And you see the input:
Does the "program" between BEGIN and END reduce as an error, and the
resulting "program" get shifted in the "statement" rule, or does the
"statement" rule get an error because the "program" is missing?
The answer depends on whether you're using the AT&T yacc or the Berkeley
yacc: the AT&T yacc, being a procedural beast, goes and reduces "program"
as an error. The Berkeley yacc, being table driven and more direct,
just finds an error in the surrounding "statement".
So beware if you ever move a large grammar among yaccs. This one will
bite your ankles!
Christopher Seiwald Perforce Software 1-510-864-7400
firstname.lastname@example.org f-f-f-fast SCM http://www.perforce.com
[Many versions of AT&T yacc have a bug in handling error rules, and this
sounds like it. -John]
Return to the
Search the comp.compilers archives again.