Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Recursive Definitions in xtext
Recursive Definitions in xtext [message #52950] Thu, 25 June 2009 19:14 Go to next message
Gunnar Reimann is currently offline Gunnar ReimannFriend
Messages: 3
Registered: July 2009
Junior Member
Hi,

I'm getting into trouble when I use recursive definitions in xtext.

The following simple grammar produces Stack-Overflow-Exceptions when it is
generated:

------------------------------------------------------------
Model:
(assignment+=RightAssignment)*;

RightAssignment:
AdditiveOperation;

AdditiveOperation:
MultiplikativeOperation (("+" | "-") MultiplikativeOperation)* ;

MultiplikativeOperation:
UnaryExpression (("*" | "/") UnaryExpression)* ;

UnaryExpression:
Literal | "(" AdditiveOperation ")";

Literal:
ID | INT;
------------------------------------------------------------ --

The reason of the Stack-Overflow seems to be the -"(" AdditiveOperation
")"- construct in the UnaryExpression rule.

What's wrong with this recursive approach?

Thanks for your help!
Re: Recursive Definitions in xtext [message #52975 is a reply to message #52950] Thu, 25 June 2009 20:14 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Gunnar,

altough it may not be highlighted as an error (I guess due to the
StackOverflowError - would you please be so kind and file a bugzilla?),
the rule AdditiveOperation is invalid because it consists of two
unassigned RuleCalls (MultiplicativeOperation), which is only allows in
an Alternative.

Please have a look into the concept of assigned Actions and the explicit
definition of return Types[1] to implement your Expression grammar.

You may even want to study the SimpleExpressions sample language[2].

Hope that helps,
Sebastian

[1] http://www.eclipse.org/Xtext/documentation/0_7_0/xtext.html
[2]
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.tmf/org .eclipse.xtext/tests/org.eclipse.xtext.generator.tests/src/o rg/eclipse/xtext/testlanguages/SimpleExpressionsTestLanguage .xtext?root=Modeling_Project&view=markup



Am 25.06.2009 21:14 Uhr, schrieb Gunnar Reimann:
> Hi,
>
> I'm getting into trouble when I use recursive definitions in xtext.
>
> The following simple grammar produces Stack-Overflow-Exceptions when it
> is generated:
>
> ------------------------------------------------------------
> Model:
> (assignment+=RightAssignment)*;
>
> RightAssignment:
> AdditiveOperation;
>
> AdditiveOperation:
> MultiplikativeOperation (("+" | "-") MultiplikativeOperation)* ;
>
> MultiplikativeOperation:
> UnaryExpression (("*" | "/") UnaryExpression)* ;
>
> UnaryExpression:
> Literal | "(" AdditiveOperation ")";
>
> Literal:
> ID | INT;
> ------------------------------------------------------------ --
>
> The reason of the Stack-Overflow seems to be the -"(" AdditiveOperation
> ")"- construct in the UnaryExpression rule.
>
> What's wrong with this recursive approach?
>
> Thanks for your help!
>
>
>
Re: Recursive Definitions in xtext [message #53000 is a reply to message #52950] Thu, 25 June 2009 20:34 Go to previous messageGo to next message
Gunnar Reimann is currently offline Gunnar ReimannFriend
Messages: 3
Registered: July 2009
Junior Member
Just a remark:

This one works:

-----------------------------
Model:
(assignment+=RightAssignment)*;

RightAssignment:
AdditiveOperation;

AdditiveOperation:
MultiplikativeOperation (("+" | "-") MultiplikativeOperation)* ;

MultiplikativeOperation:
UnaryExpression (("*" | "/") UnaryExpression)* ;

UnaryExpression:
Literal;

Literal:
ID | INT;

-----------------------------

So the problem seems to be the recursive call of "AdditiveOperation".



Gunnar Reimann wrote:

> Hi,

> I'm getting into trouble when I use recursive definitions in xtext.

> The following simple grammar produces Stack-Overflow-Exceptions when it is
> generated:

> ------------------------------------------------------------
> Model:
> (assignment+=RightAssignment)*;

> RightAssignment:
> AdditiveOperation;

> AdditiveOperation:
> MultiplikativeOperation (("+" | "-") MultiplikativeOperation)* ;

> MultiplikativeOperation:
> UnaryExpression (("*" | "/") UnaryExpression)* ;

> UnaryExpression:
> Literal | "(" AdditiveOperation ")";

> Literal:
> ID | INT;
> ------------------------------------------------------------ --

> The reason of the Stack-Overflow seems to be the -"(" AdditiveOperation
> ")"- construct in the UnaryExpression rule.

> What's wrong with this recursive approach?

> Thanks for your help!
Re: Recursive Definitions in xtext [message #53026 is a reply to message #53000] Thu, 25 June 2009 20:37 Go to previous messageGo to next message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Gunnar,

it actually does not work, as every rule except Model will be infered as
a data type rule, which is probably not what you expect.

Regards,
Sebastian

Am 25.06.2009 22:34 Uhr, schrieb Gunnar Reimann:
> Just a remark:
>
> This one works:
>
> -----------------------------
> Model:
> (assignment+=RightAssignment)*;
>
> RightAssignment:
> AdditiveOperation;
>
> AdditiveOperation:
> MultiplikativeOperation (("+" | "-") MultiplikativeOperation)* ;
>
> MultiplikativeOperation:
> UnaryExpression (("*" | "/") UnaryExpression)* ;
>
> UnaryExpression:
> Literal;
>
> Literal:
> ID | INT;
>
> -----------------------------
>
> So the problem seems to be the recursive call of "AdditiveOperation".
>
>
>
> Gunnar Reimann wrote:
>
>> Hi,
>
>> I'm getting into trouble when I use recursive definitions in xtext.
>
>> The following simple grammar produces Stack-Overflow-Exceptions when
>> it is generated:
>
>> ------------------------------------------------------------
>> Model:
>> (assignment+=RightAssignment)*;
>
>> RightAssignment:
>> AdditiveOperation;
>
>> AdditiveOperation:
>> MultiplikativeOperation (("+" | "-") MultiplikativeOperation)* ;
>
>> MultiplikativeOperation:
>> UnaryExpression (("*" | "/") UnaryExpression)* ;
>
>> UnaryExpression:
>> Literal | "(" AdditiveOperation ")";
>
>> Literal:
>> ID | INT;
>> ------------------------------------------------------------ --
>
>> The reason of the Stack-Overflow seems to be the -"("
>> AdditiveOperation ")"- construct in the UnaryExpression rule.
>
>> What's wrong with this recursive approach?
>
>> Thanks for your help!
>
>
Re: Recursive Definitions in xtext [message #53178 is a reply to message #53026] Fri, 26 June 2009 09:27 Go to previous messageGo to next message
Gunnar Reimann is currently offline Gunnar ReimannFriend
Messages: 3
Registered: July 2009
Junior Member
Hi Sebastian,

thank you for your help! But as we are not working with xtext 0.7, this
one does, what we want:

-----------------------------------------------------

Model:
(right+=RightAssignment)*;

RightAssignment:
(AdditiveOperation);

AdditiveOperation:
expr+=MultiplikativeOperation (("+" | "-") expr+=MultiplikativeOperation)*
;

MultiplikativeOperation:
expr+=UnaryExpression (("*" | "/") expr+=UnaryExpression)* ;

UnaryExpression:
literal=Literal | "(" expr+=AdditiveOperation ")";

NumLiteral:
INT;

SymLiteral:
ID;

Literal:
NumLiteral | SymLiteral;

------------------------------------------------------------ --


Greetings,

Gunnar
Re: Recursive Definitions in xtext [message #53204 is a reply to message #53178] Fri, 26 June 2009 09:44 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi Gunnar,

currently you'll get more helpful answers to questions regarding oAW
Xtext at http://www.openarchitectureware.org/forum/?menu=Forum.

Regards,
Sebastian


Am 26.06.2009 11:27 Uhr, schrieb Gunnar Reimann:
> Hi Sebastian,
>
> thank you for your help! But as we are not working with xtext 0.7, this
> one does, what we want:
>
> -----------------------------------------------------
>
> Model:
> (right+=RightAssignment)*;
>
> RightAssignment:
> (AdditiveOperation);
>
> AdditiveOperation:
> expr+=MultiplikativeOperation (("+" | "-")
> expr+=MultiplikativeOperation)* ;
>
> MultiplikativeOperation:
> expr+=UnaryExpression (("*" | "/") expr+=UnaryExpression)* ;
>
> UnaryExpression:
> literal=Literal | "(" expr+=AdditiveOperation ")";
>
> NumLiteral:
> INT;
>
> SymLiteral:
> ID;
>
> Literal:
> NumLiteral | SymLiteral;
>
> ------------------------------------------------------------ --
>
>
> Greetings,
>
> Gunnar
>
>
>
Previous Topic:[Announce] TMF XTEXT 0.7.0 is available
Next Topic:DSL project creation - extention points?
Goto Forum:
  


Current Time: Thu Dec 26 12:06:40 GMT 2024

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

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

Back to the top