Books on Xtext [message #903514] |
Fri, 24 August 2012 00:59  |
Eclipse User |
|
|
|
Its been hard to find a single source of information. I tried amazon, no luck anyone know of any concrete books that give a good overview of how to use xtext to create DSL's? - Duncan
[Updated on: Fri, 24 August 2012 01:00] by Moderator
|
|
|
|
|
|
|
|
Re: Books on Xtext [message #903692 is a reply to message #903669] |
Fri, 24 August 2012 19:16   |
Eclipse User |
|
|
|
On 2012-24-08 22:03, Duncan Krebs wrote:
> Hey guys, thanks for the replies. EMF is a technology I know well, its
> just figuring out how to put together a grammer with simple if/then
> logic and then building a runtime component to execute it. Am I correct
> that if something like if (x = y) then add 1 to y would be modeled as
> emf objects like having an "And" model object as well as a "Then" model
> object in my generated ecore or is it a lot easier than that? Also
> things like creating functions and pretty much building my own scripting
> language is what I'm wanting to learn more about. Do you think the books
> mentioned cover this kind of material? - Duncan
The easiest way to get started is to start with a small example. Since
you want to build a scripting language, you probably need expressions.
So start with an expression example - a calculator or something.
Then look at implementations of some more complex languages. Xbase,
Xtend etc. If you want to do something like C, C++, Ruby, or JavaScript
you have a rougher ride ahead as there are some difficult problems to
overcome inherit in parsing those languages. I take that back, some of
them is not so much a ride as a free fall, or in the case of Java
Script, a riot at the asylum ;-)
Then ask for pointers and guidance along the way. The books, although
they are good as introduction very quickly gets complicated, and are
perhaps more useful when you want to learn about something specific.
If you have not done any language design, parsers, etc. read some
introductory chapters to get a feel for the issues.
OTOH, if you need a competent scripting language, there is always Xtend :)
And, you are naturally correct that expressions are modeled using EMF.
An expression such as '1 + 2' (typically) becomes an Add instance with a
left containment reference to an instance of LiteralInt with an int
feature value = 1, and a right containment reference to an instance of
LiteralInt with value = 2.
You can also do this as a BinaryOp instance and have a String op = '+'
feature. It is common to divide them by precedence, So you may have an
abstract BinaryOp, with AdditiveOp, MultiplicativeOp being derived from
BinaryOp. Or indeed be explicit and have a class per binary and unary
operator.
Your choices have effect on flexibility of the model, what is reflected
in the grammar/model itself, and what you need to handle in validation
of the model.
Good advice is to make the grammar as lenient as possible to avoid harsh
"syntax error" and unrecognized parts in what is parsed. The more that
the parser can understand and construct a model for, the more help can
be provided in the editor. So don't go overboard with specifying every
itty bitty detail in the grammar itself. In fact, build it to withstand
typical anticipated user errors. Again a balancing act, as the more
flexible you allow the grammar to be, the less help do you get with the
generated tooling/out-of-the-box features.
oh - welcome to the club - working with Xtext (and languages) is fun
stuff :)
Regards
- henrik
|
|
|
Re: Books on Xtext [message #903905 is a reply to message #903514] |
Mon, 27 August 2012 04:20  |
Eclipse User |
|
|
|
Hi Duncan,
I think that the following blog post of Simon Gerlach is very helpfull, too:
xtexterience.wordpress.com/2011/05/17/xtext-based-lua-editor
(Sorry for the incomplete link. The forum doesn't allow to set a link outsite of eclipse.org as long as I have less than 25 messages. Just add a http:// in front of the link.)
He implements the LUA language in the grammar language of xtext.
Best Regards,
Tobias
[Updated on: Mon, 27 August 2012 04:21] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.08986 seconds