yacc with multiple attributes
Jim Blandy
blandy at marduk.cs.cornell.edu
Tue Jul 5 22:56:28 AEST 1988
In article <859 at garth.UUCP> smryan at garth.UUCP (Steven Ryan) writes:
>>Yacc will choke on:
>>
>>prod:
>> a { fiddle something } b c { first result }
>> | b { identical fiddle } b c { different result }
>> ;
>
>Do you mean?
>
> prod -> a {sem1} b {sem2} | a {sem3} c {sem4}
No, I don't think so. Yacc will produce parsers for all LALR(1) grammars;
if I said that yacc would choke because something was not LR, that was
wrong. LALR(1) is the class of grammars we're accepting here.
The original poster was complaining about the inability of yacc to cope
with situations like the above, where one wants to take the same action
near the beginning of several productions; it comes up quite often.
If you realize that the two fiddles are identical, then you generate
prod -> a $1 b c { first result }
| b $1 b c { first result }
;
$1 -> /* empty rule */ { fiddle zwingli }
;
which is fine by yacc. His problem was that yacc DOESN'T realize that
the two fiddles are the same, and thus has a conflict, since the one-
token lookahead won't solve this problem. Note that, yes, I do want
the same token after the { fiddle } s.
--
Jim Blandy - blandy at crnlcs.bitnet
"insects were insects when man was just a burbling whatisit." - archie
More information about the Comp.lang.c
mailing list