Running an algorithm on expressions before code generation [message #513553] |
Wed, 10 February 2010 14:48 |
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 |
Sven Efftinge Messages: 1823 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.04057 seconds