Trouble with %prec in yacc

ned ned at h-three.UUCP
Thu Jul 14 05:32:46 AEST 1988


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.  For example,

/* start of works */
%token NAME
%left ADD
%left MULT
%start expr

%%

expr	:	expr MULT expr
	|	expr ADD expr
	|	NAME
	;
/* end of works */

works (and compiles with no shift/reduce conflicts), but

/* start of doesn't work */
%token NAME MULT ADD
%left PREC_ADD
%left PREC_MULT
%start expr

%%

expr	:	expr MULT expr %prec PREC_MULT
	|	expr ADD expr %prec PREC_ADD
	|	NAME
	;
/* end of doesn't work */

doesn't (and compiles with 4 shift/reduce conflicts).  Anyone know
what I'm doing wrong?  Thanks in advance.

-- Ned Robie



More information about the Comp.unix.wizards mailing list