Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [TCS]Create left-recursive syntax
[TCS]Create left-recursive syntax [message #9799] Mon, 31 March 2008 15:06 Go to next message
T Kruse is currently offline T KruseFriend
Messages: 73
Registered: July 2009
Member
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 16:16 Go to previous message
Frédéric Jouault is currently offline Frédéric JouaultFriend
Messages: 572
Registered: July 2009
Senior Member
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?
>
Previous Topic:[TCS] Templates for ambiguous classes
Next Topic:Problem injector TCS
Goto Forum:
  


Current Time: Sat Oct 19 17:43:24 GMT 2024

Powered by FUDForum. Page generated in 0.03791 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top