As asked and answered in http://stackoverflow.com/questions/2999755/removing-left-recursion-in-antlr , I could remove the left recursion
E -> E + T|T T -> T * F|F F -> INT | ( E )
After left recursion removal, I get the following one
E -> TE' E' -> null | + TE' T -> FT' T' -> null | * FT'
Then, how to make the tree construction with the modified grammar? With the input 1+2, I want to have a tree
^('+' ^(INT 1) ^(INT 2)). Or similar.
grammar T;
options {
output=AST;
language=Python;
ASTLabelType=CommonTree;
}
start : e -> e
;
e : t ep -> ???
;
ep :
| '+' t ep -> ???
;
t : f tp -> ???
;
tp :
| '*' f tp -> ???
;
f : INT
| '(' e ')' -> e
;
INT : '0'..'9'+ ;
WS: (' '|'\n'|'\r')+ {$channel=HIDDEN;} ;