Trouble with %prec in yacc
Kenneth Almquist
ka at june.cs.washington.edu
Sat Jul 16 03:43:33 AEST 1988
ned at 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
More information about the Comp.unix.wizards
mailing list