Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Running an algorithm on expressions before code generation
Running an algorithm on expressions before code generation [message #513553] Wed, 10 February 2010 14:48 Go to next message
Matthieu  is currently offline Matthieu
Messages: 10
Registered: February 2010
Junior Member
Hello everybody,

Here is my problem: I have an Xtext grammar file, which includes the possibility to define a field that looks more like a program than a model description. I explain with an example: I can write something like that

computation {
a = 1;
b = a + 5;
c = a*b;
}


Let's say (it will be simpler) I have a "Computation" definition which has a "program" field in it and this program field is a reference to an Expression object.

Here is the beginning of the definition of "Expression" in my xtext file:

Expression :  
	OrExpression;

OrExpression returns Expression:
	AndExpression ({BooleanOperation.left=current} operator="||" right=AndExpression)*;
	
AndExpression returns Expression:
	RelationalExpression ({BooleanOperation.left=current} operator="&&" right=RelationalExpression)*;

...


My problem is: I generate some Java codes with Xpand according to a model description following the grammar rules, but for Expression it's more difficult to generate something only with Xpand because I need to analyze the AST of the expression in order to optimize it before generating codes.
Let's say it's more a compilation work (traditional AST analyze, with inherited and synthesized attributes) than a simple generation, and Xpand seems not to be enough.

So is it a way to take my instance of Expression (which seems to be the root of an AST), use it as a parameter for a (Java ?) algorithm, then use the result of the algorithm to generate something with Xpand ?

I heard about Xtend, is it that tool I need ?

I hope my explanations are clear enough (I'm a French student, my English must be quiet imperfect...).

Thanks !
Re: Running an algorithm on expressions before code generation [message #513586 is a reply to message #513553] Wed, 10 February 2010 16:00 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven Efftinge
Messages: 1762
Registered: July 2009
Senior Member
What kind of optimizations do you want to do?
You can modify your model with Xtend, if that is the question.

Cheers,
Sven

Matthieu schrieb:
> Hello everybody,
>
> Here is my problem: I have an Xtext grammar file, which includes the
> possibility to define a field that looks more like a program than a
> model description. I explain with an example: I can write something like
> that
>
> computation {
> a = 1;
> b = a + 5;
> c = a*b;
> }
>
> Let's say (it will be simpler) I have a "Computation" definition which
> has a "program" field in it and this program field is a reference to an
> Expression object.
>
> Here is the beginning of the definition of "Expression" in my xtext file:
>
> Expression : OrExpression;
>
> OrExpression returns Expression:
> AndExpression ({BooleanOperation.left=current} operator="||"
> right=AndExpression)*;
>
> AndExpression returns Expression:
> RelationalExpression ({BooleanOperation.left=current} operator="&&"
> right=RelationalExpression)*;
>
> ...
>
> My problem is: I generate some Java codes with Xpand according to a
> model description following the grammar rules, but for Expression it's
> more difficult to generate something only with Xpand because I need to
> analyze the AST of the expression in order to optimize it before
> generating codes.
> Let's say it's more a compilation work (traditional AST analyze, with
> inherited and synthesized attributes) than a simple generation, and
> Xpand seems not to be enough.
>
> So is it a way to take my instance of Expression (which seems to be the
> root of an AST), use it as a parameter for a (Java ?) algorithm, then
> use the result of the algorithm to generate something with Xpand ?
>
> I heard about Xtend, is it that tool I need ?
>
> I hope my explanations are clear enough (I'm a French student, my
> English must be quiet imperfect...).
>
> Thanks !


--
Need professional support for Xtext and EMF?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de


--
Need professional support on Xtext or Xtend?
Mail to: xtext (at) itemis.com
Twitter : @svenefftinge
Blog : blog.efftinge.de
Re: Running an algorithm on expressions before code generation [message #514351 is a reply to message #513553] Sun, 14 February 2010 22:50 Go to previous message
Karsten Thoms is currently offline Karsten Thoms
Messages: 353
Registered: July 2009
Location: Dortmund
Senior Member

If I understood correct you want to compute your result in Java based with the AST as argument and use that result in Xpand to generate code. If the answer is yes, then Xtend is right here. Write a Java extension which is called from your Xpand code.

Regards,
~Karsten


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Previous Topic:[JET] Protected Areas
Next Topic:Topcased UML Profiles and Spring Cartridge
Goto Forum:
  


Current Time: Mon Sep 15 04:07:07 GMT 2014

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

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