Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » refining generated model
refining generated model [message #761095] Mon, 05 December 2011 22:07 Go to next message
Vlad Dumitrescu is currently offline Vlad DumitrescuFriend
Messages: 430
Registered: July 2009
Location: Gothenburg
Senior Member
Hi,

I think that is easiest to write a grammar that creates a rather generic parse tree and would like to refine the generated model to provide the more specific features. For example,
Module: forms+=Forms*;
Form: Attribute | Function;

where I'd like to have access to the attributes and functions separately. I can't write
Module: (attributes+=Attribute | functions+=Function)*;

because this loses the order and the serialized form puts all attributes or functions at the start.

Can I somehow refine the model directly, or do I have to resort to helper classes? Would it work better if I was to write my code in Xtend?

(This is quite a lot to take in, and then there's the use of Guice too that makes things less familiar, so please excuse me if all these questions are naive. I do try to find the answers myself first, but most examples are for simple languages.)

best regards,
Vlad

Re: refining generated model [message #761157 is a reply to message #761095] Tue, 06 December 2011 01:52 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
The approach I took was to use the generated model until I was finished
exploring what my language would be like. I then copied the model to a
separate project and turned off generation in favor of using an external
model. I then refined the model using EMF tools.

After some point in the dev cycle you really do not want changes in the
grammar to have an effect on the model.

Regards
- henrik

On 2011-05-12 23:07, Vlad Dumitrescu wrote:
> Hi,
>
> I think that is easiest to write a grammar that creates a rather generic
> parse tree and would like to refine the generated model to provide the
> more specific features. For example, Module: forms+=Forms*;
> Form: Attribute | Function;
> where I'd like to have access to the attributes and functions
> separately. I can't write
> Module: (attributes+=Attribute | functions+=Function)*;
> because this loses the order and the serialized form puts all attributes
> or functions at the start.
>
> Can I somehow refine the model directly, or do I have to resort to
> helper classes? Would it work better if I was to write my code in Xtend?
>
> (This is quite a lot to take in, and then there's the use of Guice too
> that makes things less familiar, so please excuse me if all these
> questions are naive. I do try to find the answers myself first, but most
> examples are for simple languages.)
>
> best regards,
> Vlad
>
>
Re: refining generated model [message #761259 is a reply to message #761157] Tue, 06 December 2011 07:48 Go to previous messageGo to next message
Vlad Dumitrescu is currently offline Vlad DumitrescuFriend
Messages: 430
Registered: July 2009
Location: Gothenburg
Senior Member
Thank you Henrik!

This is a good idea, definitely to be used when the grammar is stable. However, if I understand correctly, it means that until then I still have to find a way to encapsulate the model refinements (because I don't want to rewrite all the IDE support). I think I might be able to use Xtend and its extension methods.

best regards,
Vlad
Re: refining generated model [message #761262 is a reply to message #761157] Tue, 06 December 2011 07:50 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
I tend to create model helper classes/extensions which provide "derived model properties" quite early on in development. Thanks to Xtend2's extension mechanism these tie in beautifully to any Xtend2 code (e.g., templates) that I'm using. You can have Guice inject those helper classes by just annotating the field of the client with '@Inject' - no need to define a binding anywhere if the helper class is its own implementation.

Fixing the meta model is useful when the meta model doesn't change anymore (or in a very controlled fashion) and it is part of the public API. In the beginning of dev, it's typically only a hindrance because you want to be able to move quickly in exploring what your language should look like.


Re: refining generated model [message #761266 is a reply to message #761262] Tue, 06 December 2011 07:55 Go to previous messageGo to next message
Vlad Dumitrescu is currently offline Vlad DumitrescuFriend
Messages: 430
Registered: July 2009
Location: Gothenburg
Senior Member
Thanks Meinte!

Yes, I see. Using Guice is still something new for me and it solves a lot of issues that otherwise require quite a lot of plumbing.

My language is actually stable, the problems that I have are related to trying to get as close as possible to an existing model and also to handling a few constructs that seem difficult to parse with a LL grammar (the original parser is a recursive-descent one).

best regards,
Vlad
Re: refining generated model [message #761300 is a reply to message #761266] Tue, 06 December 2011 08:58 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Xtext (ANTLR) actually generates a recursive-descent parser, so in theory those constructs shouldn't be harder to parse with an LL(*)-grammar. Mapping a recursive-descent parser implementation to an LL(*)-grammar isn't wholly trivial, though Wink

Re: refining generated model [message #761879 is a reply to message #761300] Wed, 07 December 2011 08:15 Go to previous messageGo to next message
Vlad Dumitrescu is currently offline Vlad DumitrescuFriend
Messages: 430
Registered: July 2009
Location: Gothenburg
Senior Member
Yes, I noticed that! I got it almost working, but there are a couple of constructs that are ambiguous and I'm not sure what to do about them. I can tweak the grammar, but then the parse tree will be very weird... Well, if it was easy, everybody could do it!

regards,
Vlad
Re: refining generated model [message #762125 is a reply to message #761879] Wed, 07 December 2011 15:32 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
In case you haven't done already, you should dive into the subject "(un)assigned actions" and "syntactic predicates" which might very well help you with re-writing the AST to something useful and getting rid of ambiguities, resp.

Re: refining generated model [message #762285 is a reply to message #762125] Wed, 07 December 2011 20:03 Go to previous message
Vlad Dumitrescu is currently offline Vlad DumitrescuFriend
Messages: 430
Registered: July 2009
Location: Gothenburg
Senior Member
Ah, yes, I know that these can help, but it's only now that I see that you wrote about it in your blog, I'll go read!

Thanks!
Vlad
Previous Topic:Using multiple alternatives 1,2
Next Topic:grammar mixin
Goto Forum:
  


Current Time: Sat Apr 04 13:28:44 GMT 2020

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

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

Back to the top