rewrite ANTLR .g grammar in XText [message #649367] |
Tue, 18 January 2011 17:47  |
Eclipse User |
|
|
|
I have a .g grammar file which already describes a DSL. I would like to import this .g file into Xtext but I think that is not possible.
Nonetheless it should be possible to "easily" convert it to an equivalent Xtext grammar definition.
Do you have any experience with this ? Any tips, tutorials, articles, etc ... that can help me with this task ?
Thank you in advance!
|
|
|
Re: rewrite ANTLR .g grammar in XText [message #649425 is a reply to message #649367] |
Wed, 19 January 2011 03:28   |
Eclipse User |
|
|
|
Hi Sergio,
as the Xtext grammar contains information that is not available from an
Antlr grammar, it is impossible to derive it automatically. However,
pasting an Antlr grammar into an Xtext editor and subsequently fixing
the error markers is usually straight forward enough - at least if your
*.g file does not contain to many actions, predicates and rewrite rules
but just plain parser rules.
Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 18.01.11 23:47, schrieb sergiofbsilva@gmail.com:
> I have a .g grammar file which already describes a DSL. I would like to
> import this .g file into Xtext but I think that is not possible.
> Nonetheless it should be possible to "easily" convert it to an
> equivalent Xtext grammar definition.
>
> Do you have any experience with this ? Any tips, tutorials, articles,
> etc ... that can help me with this task ?
>
> Thank you in advance!
|
|
|
Re: rewrite ANTLR .g grammar in XText [message #649427 is a reply to message #649367] |
Wed, 19 January 2011 03:33   |
Eclipse User |
|
|
|
Xtext uses a subset of Antlr internally, so there are similarities.
OTOH, an Xtext grammar has syntax for describing the lexical structure
of a language and the construction of an EMF-based AST including
cross-references. In Antlr, the construction of the AST is usually
performed in Antlr actions, which let you insert any code in the parser.
The focus on a well defined AST often results a different kind of
grammar, i.e. one rule for each object type.
So the feature set of Antlr and Xtext are quiet different, and I am not
aware of any migration guide.
OTOH, your grammar is already LL*, so one of the big obstacles in
porting a grammar to Xtext is already solved. The migration will be
harder if your Antlr grammar uses
- semantic predicates
- syntatic predicates (partly implemented in Xtext 2.0)
- very complex code in actions
Similar concepts in both frameworks are
- Rules (terminal rules, parser rules)
- Rule calls
- Groups, alternatives and cardinalities
Additional in Xtext and likely to appear, so you might want to learn
about these concepts by reading the docs
- Assignments
- Return types of rules
- AST node creation
Am 18.01.11 23:47, schrieb sergiofbsilva@gmail.com:
> I have a .g grammar file which already describes a DSL. I would like to
> import this .g file into Xtext but I think that is not possible.
> Nonetheless it should be possible to "easily" convert it to an
> equivalent Xtext grammar definition.
>
> Do you have any experience with this ? Any tips, tutorials, articles,
> etc ... that can help me with this task ?
>
> Thank you in advance!
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
|
|
|
|
|
|
|
|
|
|
|
Re: rewrite ANTLR .g grammar in XText [message #649975 is a reply to message #649870] |
Fri, 21 January 2011 04:19  |
Eclipse User |
|
|
|
Am 20.01.11 20:38, schrieb Sérgio Silva:
> Well I still have a problem with some grammar issue that I can't see how
> to solve it.
>
>
> suppose that my grammar is :
>
> Class:
> 'class' name=CLASS_NAME ('extends' superType=CLASS_NAME)? '{'
> (classSlots+=Slot)*
> '}';
>
> RoleDefinition :
> type=[Class] 'playsRole' roleName=ID (('{' (roleProperty += RoleProperty)+
> '}')? | ';')
> ;
>
> So this will match something like :
>
> class Xpto {
> String field1;
> Integer field2;
> Boolean field1;
> }
>
> class Zen {
> String field1;
> }
>
> class Zorg {}
>
>
> Zorg playsRole zorg;
>
> So in the type of RoleDefinition I will have a cross reference to a
> Class and it works.
>
> The problem is like I want this type to be a Class cross-reference or a
> fully qualitfied String (x.slkdasl.askdasl)
>
> So this 2 possiblities should be possible :
>
> 1) x.slkdasl.askdasl playsRole zorg;
> 2) Zorg playsRole zorg;
>
> Any help with this ?
Yes: Read the Xtext docs ;-)
(Getting started->Creating a DSL->Adding a namespace concept)
You need a datatype rule for qualified names and use that in the cross
reference.
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
|
|
|
Powered by
FUDForum. Page generated in 0.05316 seconds