Writing an interpreter

We will now write an interpreter for our Expressions DSL. The idea is that this interpreter, given an AbstractElement, returns a Java object which represents the evaluation of that element. Of course, we want the object with the result of the evaluation to be of the correct Java type; that is, if we evaluate a boolean expression, the corresponding object should be a Java boolean object.

Such an interpreter will be recursive, since to evaluate an expression, we must first evaluate its sub-expressions and then compute the result.

When implementing the interpreter we make the assumption that the passed AbstractElement is valid. Therefore, we will not check for null sub-expressions; we will assume that all variable references ...

Get Implementing Domain-Specific Languages with Xtext and Xtend now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.