[antlr-interest] deleting a left-recursive

jabon elekis at gmail.com
Sat May 3 08:17:58 PDT 2008


oki, I ve reduce the prob,
now I have this

expression
    :      (
           expression     
               
(T_Ne|T_Eq|T_Ge|T_Le|T_Lt|T_Gt|T_And|T_Mod|T_Star|T_Slash|T_Iff|T_Implies|T_Or|T_Plus|T_Minus)  

           expression
       )
         ;

it's a simple left recuse but in the doc this become this.
a : a b |b; ==> a : b+;

So I ve tried


expression
    :      (
               
(T_Ne|T_Eq|T_Ge|T_Le|T_Lt|T_Gt|T_And|T_Mod|T_Star|T_Slash|T_Iff|T_Implies|T_Or|T_Plus|T_Minus)  

           expression+
       )
         ;

but That doesn't work.
any idea??

thanks

a++

Johannes Luber a écrit :
> jabon schrieb:
>> hi all,
>>
>> I have a little probleme with my grammar , I have a left recursive 
>> and I have lot of diffcult to remove this.  I need a little help (I m 
>> not an expert sorry and compilations lessons are far away)
>>
>> expression
>>    : T_LParent expression T_RParent
>>    | binaryExpression
>>    | castExpression
>>    | desig | literal
>>    | newExpression
>>    | quantifierExpression
>>    | unaryExpression
>>    ;
>>
>>
>> binaryExpression
>>    : (expression (T_Ne|T_Eq|T_Ge|T_Le|T_Lt|T_Gt) expression)
>>    |(expression (T_And|T_Mod|T_Star|T_Slash) expression)
>>    |(expression (T_Iff|T_Implies|T_Or|T_Plus|T_Minus) expression);
>>
>> thanks a lot
>>
>> a+++
>>
>
> You've reminded me that I didn't posted my tutorial about 
> left-recursion removal yet. After 1 hour or so intense formatting you 
> can see the result here: 
> <http://www.antlr.org/wiki/display/ANTLR3/Left-Recursion+Removal>. 
> Hopefully it is helpful enough. :)
>
> Johannes



More information about the antlr-interest mailing list