[antlr-interest] parse tree construction after left recursion removal

Gavin Lambert antlr at mirality.co.nz
Tue Jul 7 06:34:33 PDT 2009


At 01:10 8/07/2009, Safiye Celik wrote:
>I have a rule and its tree construction such below:
>a : b | c! a c! | a d^ a
[...]
>What should I do to remove left recursion, but also provide the 
>tree I need?

Try this:

a : (b | c! a c!) (d^ a)? ;

Or this:

e : b | c! a c! ;
a : e (d^ e)* ;

(The recursion in the c alt is ok at parse time.  But it might 
make things difficult for you in the tree parser.  Could be 
helpful to insert an imaginary root at that point.)



More information about the antlr-interest mailing list