Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Source code translation with models
Source code translation with models [message #1269171] Tue, 11 March 2014 13:32 Go to next message
Dam Ur is currently offline Dam UrFriend
Messages: 2
Registered: March 2011
Junior Member
Hello guys,

Firstly I am a beginner in the model-engineering field, so don't blame me. Secondly, not sure I am at the right place for this question, but I can't find a general forum for my particular concern (and I guess I can find some specialists here...).

I would like to achieve source code translations with models. Let's say, I want to translate a C# source code to a Java source code (and why not translate it back as well). I know the environments are not the same, neither the libraries provided, but this does not matter for me.

I can imagine something like :

C# source code -> C# model -> model translation -> Java model -> Java source code.

Is this the correct way to fulfill my needs ?

What tools could I use ? I think I could use EMF, Xtext, a model transformation tool (ATL ?). If I use Xtext, I have to write both grammars, but if I understand well, the serialization process will be automatic. I have seen MoDisco has a Java discoverer, would it help ?

Thanks in advance,
Dam.
Re: Source code translation with models [message #1269213 is a reply to message #1269171] Tue, 11 March 2014 14:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 26287
Registered: July 2009
Senior Member
Comments below.

On 11/03/2014 3:15 PM, Dam Ur wrote:
> Hello guys,
>
> Firstly I am a beginner in the model-engineering field, so don't blame
> me. Secondly, not sure I am at the right place for this question, but
> I can't find a general forum for my particular concern (and I guess I
> can find some specialists here...).
>
> I would like to achieve source code translations with models. Let's
> say, I want to translate a C# source code to a Java source code (and
> why not translate it back as well). I know the environments are not
> the same, neither the libraries provided, but this does not matter for
> me.
>
> I can imagine something like :
> C# source code -> C# model -> model translation -> Java model -> Java
> source code.
Mostly it's not done this way because the complexity of the models
involved. I.e., you'd need a full model for all the syntax of C# (down
to the expression level) and a full model of all the syntax for Java
(down to the expression level). I certainly don't know of a model for C#.
>
> Is this the correct way to fulfill my needs ?
Alternatively you generated source code directly from the model using a
template language such as Xtend.
>
> What tools could I use ? I think I could use EMF, Xtext, a model
> transformation tool (ATL ?). If I use Xtext, I have to write both
> grammars, but if I understand well, the serialization process will be
> automatic.
Yes, though formatting reasonably is not completely trivial.
> I have seen MoDisco has a Java discoverer, would it help ?
I'm not sure their model covers the full Java syntax; perhaps only the
declarations not statements and expressions. I believe this model is
very complete:
http://emftext.org/index.php/EMFText_Concrete_Syntax_Zoo_Java_5
>
>
> Thanks in advance,
> Dam.
Re: Source code translation with models [message #1269271 is a reply to message #1269213] Tue, 11 March 2014 16:17 Go to previous messageGo to next message
Dam Ur is currently offline Dam UrFriend
Messages: 2
Registered: March 2011
Junior Member
Thanks Ed,

It seems that MoDisco's Java discoverer covers the full language.

And there is also a C# model in the EMFText zoo (marked as experimental, can't put the link here)

I had the idea of using a code generator as you suggest, to simply generate code from a model, but if I want to have the bi-directional translation, I would have to write two code generation mechanisms. Instead I wanted to have two model transformations, and leave the code generation work to be done by the serialization of the model: no work for me, and I think this is more secure, because I am sure the generated code has more chances to be correct (or correct me). As the two languages are close (for some aspects), transformations could be simple in some cases.

What do you think of this ? Is it feasible ? Or is it more work than the solution you propose ?
Re: Source code translation with models [message #1269278 is a reply to message #1269271] Tue, 11 March 2014 16:30 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26287
Registered: July 2009
Senior Member
Comments below.

On 11/03/2014 5:17 PM, Dam Ur wrote:
> Thanks Ed,
>
> It seems that MoDisco's Java discoverer covers the full language.
>
> And there is also a C# model in the EMFText zoo (marked as
> experimental, can't put the link here)
>
> I had the idea of using a code generator as you suggest, to simply
> generate code from a model, but if I want to have the bi-directional
> translation, I would have to write two code generation mechanisms.
> Instead I wanted to have two model transformations, and leave the code
> generation work to be done by the serialization of the model: no work
> for me,
Well, the complexity of expressing a model to model translation down to
the level of expression might make it harder to understand the overall
process...
> and I think this is more secure, because I am sure the generated code
> has more chances to be correct (or correct me).
In the end, the most important consideration is that it's
understandable, transparent, and easy to maintain. Whatever achieves
those goals is best. Model to model transformation is certainly nice in
principle...
> As the two languages are close (for some aspects), transformations
> could be simple in some cases.
The devil is in the details...
> What do you think of this ? Is it feasible ? Or is it more work than
> the solution you propose ?
It sounds reasonable and is worth a try. Certainly EMF has
transformations from UML <-> Ecore and XSD <->Ecore as model to model
transformations, but Ecore -> Java is a model to text transformation
because it's easier to see at a glance what's being produced (though if
you look at the templates, that's an overstatement).
Previous Topic:Teneo + GMF Problems
Next Topic:[Texo] Project status and ease of development
Goto Forum:
  


Current Time: Sun Dec 21 22:21:38 GMT 2014

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

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