ANTLR Operator Precedence

With Xtext / ANTLR 3 you encode the precedence in the grammar rules like this:

Expr:  mult ('+' mult)* ;
Mult:  atom ('*' atom)* ;
Atom:  INT | '(' expr ')' ;

This would parse "1 + 2 * 3 + ( 4 * 5 + 6)" as "(1 + (2 * 3)) + ((4 * 5) + 6)"


Since you use Xtext, I'd recommend to use the action concept of Xtext. That is, a simple expression grammar would typically look similar to this one:

Sum: Product ({Sum.left=current} operator=('+'|'-') right=Product)*;
Product: Atom ({Product.left=current} operator=('+'|'-') right=Atom)*;
Atom: Number | Paren;
Paren: '(' Sum ')';
Number: value=INT;

Please have a look at the docs for details.