yacc with multiple attributes

Mike Sullivan merlin at ucrmath.UUCP
Fri Jul 22 17:04:33 AEST 1988


In article <18840 at cornell.UUCP> blandy at cs.cornell.edu (Jim Blandy) writes:
>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.  
Lots of stuff deleted.
>
>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.

However, in this case yacc doesn't NEED to realize that the two fiddles are
the same, because both these productions appear in different states
(being distinguished by the first token), and so there is no conflict.
Notice that yacc knows which rule it is in by seeing an 'a' for the first
and a 'b' for the second, there is no problem in this case.  
A case to demonstrate the problem in question here is this:
   prod:
      a { fiddle something } b c { first result }
    | a { identical fiddle } b c { different result }
    ;
Now there is a reduce/reduce conflict on 'b', since yacc is in both
rules at the same time (essentially), and 'b' does not distinguish
the two rules.


Mike Sullivan		ucsd!ucrmath!merlin



More information about the Comp.lang.c mailing list