Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!nosc!ucsd!rutgers!mailrus!tut.cis.ohio-state.edu!bloom-beacon!mit-eddie!uw-beaver!uw-june!ka
From: ka@june.cs.washington.edu (Kenneth Almquist)
Newsgroups: comp.unix.wizards
Subject: Re: Trouble with %prec in yacc
Keywords: yacc %prec
Message-ID: <5290@june.cs.washington.edu>
Date: 15 Jul 88 17:43:33 GMT
References: <237@h-three.UUCP>
Organization: U of Washington, Computer Science, Seattle
Lines: 19

ned@h-three.UUCP writes:
> I can't seem to override the default precedence for rules
> with the %prec keyword.  However, if I set the precedences for the
> terminal tokens involved in the declarations section, then they
> take effect.
>
> [examples deleted]

The %prec keyword sets the precedences of the rules just fine.  In
Yacc, both rules and terminal tokens can have precedences.  When Yacc
has to decide between shifting the next input token or reducing a
rule, it compares the precedence of the input token with the precedence
of the rule.  For this comparison to to be made, both the rule and
the input token must have a precedence.  In the example you give that
works, you have assigned precedences to both of these.  In the example
that does not work, you have assigned precedences to the rules, but
have neglected to assign precedences to the terminal tokens ADD and
MULT.  This explanation is rather brief; for a full explanation of
how Yacc handles precedences see the the Yacc manual.
				Kenneth Almquist