[antlr-interest] got associativity working

Terence Parr parrt at cs.usfca.edu
Thu Feb 24 15:09:36 PST 2011


assumes left unless you say otherwise:

e: e '.'^ ID
  | '-'^ e
  | e '^'<assoc=right>^ e
  | e '*'^ e
  | e ('+'^|'-'^) e
  | e ('='<assoc=right>^ |'+='<assoc=right>^) e
  | INT
  | ID
  ;

All operators at the same precedence level must have the same associativity;  it's   nonoptimal to have to say it on each operator, but there is no existing syntax that would let me say "right associativity for this alternative".

some examples examples of the associativity

a^b^c		-> (^ a (^ b c))
a=b=c		-> (= a (= b c))
a=b=c+d.e	-> (= a (= b (+ c (. d e))))

Ter
PS: woot!



More information about the antlr-interest mailing list