Providing a library
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 ...
Get Implementing Domain-Specific Languages with Xtext and Xtend - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.