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 ...

Get Implementing Domain-Specific Languages with Xtext and Xtend 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.