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