Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Looking for antlr+emf samples
Looking for antlr+emf samples [message #417274] Tue, 04 March 2008 14:26 Go to next message
Felix Dorner is currently offline Felix DornerFriend
Messages: 676
Registered: July 2009
Senior Member
Hey,

I look for _basic_ examples how to specify an antlr grammar where the
generated parser creates an emf model instance. I know that Emfatic and
XText actually generate such grammar specs to avoid specifying such
grammars manually. But I don't know if they're powerful enough, so I
want to get my hands dirty... Before Installing one of those to see how
the generated grammars look like, I'd like to ask if someone has a
_basic_ hand-written example? I also thought of the OCL Component but
they don't use antlr...

Felix
Re: Looking for antlr+emf samples [message #417368 is a reply to message #417274] Thu, 06 March 2008 16:37 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Hi Felix,

basically you have to create the model using Antlr actions.
Here is an example of how ugly such grammar code looks like:

ruleXtendFile returns [XtendFile r]
@init{
$r = factory.createXtendFile();
}
:
(i=ruleImport {$r.getImports().add(i);})*
(c=ruleConcept {$r.getConcepts().add(i);})*
;

regards,
Sven


Felix Dorner wrote:
> Hey,
>
> I look for _basic_ examples how to specify an antlr grammar where the
> generated parser creates an emf model instance. I know that Emfatic and
> XText actually generate such grammar specs to avoid specifying such
> grammars manually. But I don't know if they're powerful enough, so I
> want to get my hands dirty... Before Installing one of those to see how
> the generated grammars look like, I'd like to ask if someone has a
> _basic_ hand-written example? I also thought of the OCL Component but
> they don't use antlr...
>
> Felix
>
>
Re: Looking for antlr+emf samples [message #417377 is a reply to message #417368] Thu, 06 March 2008 23:43 Go to previous messageGo to next message
Jim Steel is currently offline Jim SteelFriend
Messages: 54
Registered: July 2009
Member
One of the catches with this is that it can be hard to build the model
completely at parse-time. Often you need to go back and make one (or
more) passes to link up, for example, uses to definitions, etc. So an
alternative is to parse the text into some intermediate object model,
then make a visitor or something and go back and link it up.

I believe the Kermeta guys (www.kermeta.org) used Emfatic (and about a
half dozen post-parse linking passes!) to build their parser, and they
have a reasonably big metamodel, and pretty big models, and as far as I
know, Emfatic hasn't caused them any scalability or expressiveness
problems. I'm sure they'd be happy to respond to questions about it.

Tefkat (http://tefkat.sourceforge.net) builds its models using an antlr
grammar. Its probably not a great example to start with, since its not
small (the .g file is 2500 lines long!), and the metamodel may not be
the most accessible (its not a library metamodel :), so the code is
there if you really want to look at it.

Jim.




Sven Efftinge wrote:
> Hi Felix,
>
> basically you have to create the model using Antlr actions.
> Here is an example of how ugly such grammar code looks like:
>
> ruleXtendFile returns [XtendFile r]
> @init{
> $r = factory.createXtendFile();
> }
> :
> (i=ruleImport {$r.getImports().add(i);})*
> (c=ruleConcept {$r.getConcepts().add(i);})*
> ;
>
> regards,
> Sven
>
>
> Felix Dorner wrote:
>> Hey,
>>
>> I look for _basic_ examples how to specify an antlr grammar where the
>> generated parser creates an emf model instance. I know that Emfatic
>> and XText actually generate such grammar specs to avoid specifying
>> such grammars manually. But I don't know if they're powerful enough,
>> so I want to get my hands dirty... Before Installing one of those to
>> see how the generated grammars look like, I'd like to ask if someone
>> has a _basic_ hand-written example? I also thought of the OCL
>> Component but they don't use antlr...
>>
>> Felix
>>
>>
Re: Looking for antlr+emf samples [message #417411 is a reply to message #417377] Sat, 08 March 2008 10:53 Go to previous message
Felix Dorner is currently offline Felix DornerFriend
Messages: 676
Registered: July 2009
Senior Member
Thanks for your replies. I'll tell you my experiences when I'am through
with it...

Felix
Previous Topic:Does the order of setter calls matter?
Next Topic:getChildren() for itemProviders
Goto Forum:
  


Current Time: Fri Apr 26 08:02:58 GMT 2024

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

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

Back to the top