Is it possible to create a grammar that has a rule with multiple operators with the same level of precedence but different associativity?
For example "+" and "-" both have same precedence and associativity (left assoc.)
But if I want to change "+" to right associative but with the same precedence how can I do that ?
I tried:
expr: expr op=('*'|'/') expr # MulDiv
| expr op=(<assoc=right>'+'|'-') expr # AddSub
| INT # int
| ID # id
| '(' expr ')' # parens
;
And @LucasTrzesniewski. Still does not work your suggestion
addSubOp: <assoc=right>'+'| <assoc=lefts>'-';
expr: expr op=('*'|'/') expr # MulDiv
| expr addSubOp expr # AddSub
| INT # int
| ID # id
| '(' expr ')' # parens
;
But with no success.