|Re: Books on Xtext [message #903692 is a reply to message #903669]
||Fri, 24 August 2012 23:16
| Henrik Lindberg
Registered: July 2009
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,
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
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
|Re: Books on Xtext [message #903905 is a reply to message #903514]
||Mon, 27 August 2012 08:20
| Tobias Mayer
Registered: August 2012
I think that the following blog post of Simon Gerlach is very helpfull, too:
(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.
[Updated on: Mon, 27 August 2012 08:21]
Report message to a moderator
Powered by FUDForum
. Page generated in 0.02134 seconds