[antlr-interest] How to resolve the left-recursion problem?
    John B. Brodie 
    jbb at acm.org
       
    Tue Jun  5 12:04:29 PDT 2007
    
    
  
> Thanks for your reply. 
Sure thing. hope the reply was useful...
> Forget about the scope name for now. Say that I want to recognize a series
> of name linked by ".", but I want to treat the "." as an operator which I
> want to associate some operation to it. I also want the . operator to be
> left associative. For example, "employer.ceo.name" is equivalent to
> ((employer.ceo).name) which generates the AST as 
> 
>          .
>        /   \
>       .     name
>     /     \
> employer  ceo
> 
> This is the only parser rule I can think of  that will do what I want. But
> it's left recursive.
> 
> attribute_expression
>   : NAME | dot_operator_exp
>   ;
> 
> dot_operator_exp
>   : attribute_expression DOT NAME
>   ;
ok. ast construction (as opposed to parse trees). have you tried:
attribute_expression : NAME (DOT^ NAME)* ;
> Thanks for any help,
You are welcome.
   -jbb
    
    
More information about the antlr-interest
mailing list