Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!cornell!blandy
From: blandy@marduk.cs.cornell.edu (Jim Blandy)
Newsgroups: comp.lang.c
Subject: Re: yacc with multiple attributes
Message-ID: <18840@cornell.UUCP>
Date: 5 Jul 88 12:56:28 GMT
References: <16345@brl-adm.ARPA> <838@garth.UUCP> <18773@cornell.UUCP> <859@garth.UUCP>
Sender: nobody@cornell.UUCP
Reply-To: blandy@cs.cornell.edu (Jim Blandy)
Organization: Cornell Univ. CS Dept, Ithaca NY
Lines: 35

In article <859@garth.UUCP> smryan@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@crnlcs.bitnet
"insects were insects when man was just a burbling whatisit."  - archie