O'Reilly logo

Implementing Domain-Specific Languages with Xtext and Xtend by Lorenzo Bettini

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Forward references

You should know by now that parsing is only the first stage when implementing a DSL and that it cannot detect all the errors from the programs. We need to implement additional checks in a validator.

One important thing we need to check in our Expressions DSL is that an expression (including the initialization expression of a variable) does not refer to a variable defined after the very expression. Using an identifier before its declaration is usually called a forward reference .

Therefore, this program should not be considered valid:

i = j + 1
j = 0

since the initialization expression of i refers to j,which is defined after. Of course, this is a design choice: since we want to interpret the expressions, it makes sense to interpret ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required