Summary

In this chapter, we presented type checking techniques that are typical for a DSL with object-oriented features. A small Java-like language was introduced to demonstrate how to parse features such as member access and inheritance and how to handle validation of type conformance. The reader might want to experiment with the caching techniques we described in the previous chapter and apply them to the implementation of the DSL.

For further reading concerning type system implementations for Xtext languages, we refer the interested reader to the articles Bettini et al. 2012, Bettini 2013, and Bettini 2016. In these articles, a DSL for implementing type systems for Xtext languages, Xsemantics is also described. Xsemantics is available as an open source project at http://xsemantics.sourceforge.net. There is, however, a crucial aspect that we still have to deal with—correct access to members (fields and methods). In fact, the following selection expression:

e.f

well-typed only if the field f is declared in the class of e (similarly for methods) or in any superclass of the class of e: If you perform some experiments, you will note that at the moment, you can access members which are not declared in the class of the receiver expression, and that you cannot access all the members of the hierarchy of the class of the receiver expression. Furthermore, local variable access does not work correctly in the current implementation; you can also refer to variables defined later and variables defined in inner blocks.

In order to correctly deal with the preceding issues, which concern cross-reference resolution, we will need to implement a custom scoping mechanism, as we will see in the next chapter. Scoping defines what is visible in a specific context so that Xtext can correctly resolve cross references.

In the next chapter, we will also add to SmallJava access level modifiers for members (that is, private, protected, and public). We will show you how a SmallJava program can access classes defined in other files and how to provide a library with some predefined classes (for example, Object, String, and so on).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.61.16