| [TCS]Create left-recursive syntax [message #9799] | 
Mon, 31 March 2008 11:06   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Hi, 
 
assuming I'd have a metamodel like this: 
 
abstract class Expression { 
} 
 
class BinaryExpression extends Expression { 
  attribute left : Expression; 
  attribute right : Expression; 
} 
 
class Value extends Expression { 
  attribute value: String; 
} 
 
And assuming I'd have a syntax like that: 
template BinaryExpression 
:  left "=" right 
; 
 
template Value 
:  value 
; 
 
Then this syntax is obviously left-recursive, and ANTLR writes the  
following error: 
[antlr:antlr3] error(210):  The following sets of rules are mutually  
left-recursive [binaryExpression, expression] 
 
However, in theory it is possible to create ANTLR Grammars that can do  
what I indended above, by using more grammar rules (separating recursive  
from non-recursive rules). 
Is there any way to achieve this for the scenario above without changing  
the metamodel? What would be the best approach to create such a syntax?
 |  
 |  
  | 
| Re: [TCS]Create left-recursive syntax [message #9825 is a reply to message #9799] | 
Mon, 31 March 2008 12:16   | 
 
Eclipse User  | 
 | 
 | 
   | 
 
Hello, 
 
When you have left recursion, you should use operatorTempltates and the  
operator table. 
You can for instance have a look at the FPath project from the TCS Zoo. 
 
 
Regards, 
 
Frédéric Jouault 
 
Thibault a écrit : 
> Hi, 
>  
> assuming I'd have a metamodel like this: 
>  
> abstract class Expression { 
> } 
>  
> class BinaryExpression extends Expression { 
>  attribute left : Expression; 
>  attribute right : Expression; 
> } 
>  
> class Value extends Expression { 
>  attribute value: String; 
> } 
>  
> And assuming I'd have a syntax like that: 
> template BinaryExpression 
> :  left "=" right 
> ; 
>  
> template Value 
> :  value 
> ; 
>  
> Then this syntax is obviously left-recursive, and ANTLR writes the  
> following error: 
> [antlr:antlr3] error(210):  The following sets of rules are mutually  
> left-recursive [binaryExpression, expression] 
>  
> However, in theory it is possible to create ANTLR Grammars that can do  
> what I indended above, by using more grammar rules (separating recursive  
> from non-recursive rules). 
> Is there any way to achieve this for the scenario above without changing  
> the metamodel? What would be the best approach to create such a syntax? 
>
 |  
 |  
  | 
Powered by 
FUDForum. Page generated in 0.02857 seconds