Consider the following Bison grammar (this is stripped down from a much larger grammar I'm working on):
%token ident
%left '+'
%left CALLPREC
%%
start: add ';' ;
expr: ident | call | add ;
call: expr '(' ')' %prec CALLPREC ;
add: expr '+' expr ;
Obviously without precedence there's a s/r conflict when parsing an expression like foo + bar()
. I'm trying to understand why the %prec
declaration doesn't resolve that conflict. I'm using Bison 3.0.2, which seems to think the directive is useless:
$ bison -r state,solved -Wall ambigram.y
ambigram.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
ambigram.y:5.1-5: warning: useless precedence and associativity for CALLPREC [-Wprecedence]
Oddly, eliminating the %prec CALLPREC
and declaring %left '('
resolves the conflict, but declaring %left ')'
does not. This is the opposite of what I'd expect from the Bison docs, which say that [by] default, the precedence of a rule is that of its last token.