-
Book Overview & Buying
-
Table Of Contents
Implementing Domain-Specific Languages with Xtext and Xtend - Second Edition
By :
Our implementation of SmallJava does not yet allow to make references to types such as Object, String, Integer, and Boolean We could use these to declare variables initialized with constant expressions. In this section, we show how to create a library with predefined types.
One might be tempted to hardcode these classes/types directly in the grammar, but this is not the best approach. There are many reasons for not doing that; mostly, that the grammar should deal with syntax only. Moreover, if we hardcoded, for example, Object in the grammar, we would only be able to use it as a type, but what if we wanted Object to have some methods? We would not be able to express that in the grammar.
Instead, we will follow the library approach (see also the article Zarnekow 2012-b). Our language implementation will provide a library with some classes, for example, Object, String, and so on, just like Java does. Since Xtext deals with EMF models, this library could consist of any EMF...