Trying to compare grammar conflicts between parser generators I noticed that "lemon" differs form "yacc/bison" in how to assign rule precedence, "yacc/bison" uses the rightmost token but "lemon" uses the leftmost token (at least on the documentation).
But looking through the code it seems that "lemon" is only respecting the documentation for MULTITERMINAL but using the rightmost token otherwise (see bellow), the loop that goes through all rhs elements of a rule do not stop when it finds the first, so if we have more than one token with precedence defined the last one (rightmost) will prevail, except for MULTITERMINAL that stops at the first found.
======
void FindRulePrecedences(struct lemon *xp)
{
struct rule *rp;
for(rp=xp->rule; rp; rp=rp->next){
if( rp->precsym==0 ){
int i, j;
for(i=0; i<rp->nrhs && rp->precsym==0; i++){
struct symbol *sp = rp->rhs[i];
if( sp->type==MULTITERMINAL ){
for(j=0; j<sp->nsubsym; j++){
if( sp->subsym[j]->prec>=0 ){
rp->precsym = sp->subsym[j];
break; ///<<<<< break only the inner loop, but continue looking in the outer loop
}
}
}else if( sp->prec>=0 ){
rp->precsym = rp->rhs[i]; ///<<<<< no break here, continue looking for more tokens
}
}
}
}
return;
}
======