Basically, interpreters and code generators work differently. Code generators are like a compiler: they create the executable code of your DSL in another language; translators, on the other hand, are used to go through your DSL and execute them in your own environment. This means that the generated code should not (but, of course, it can) depend on your DSL, it can be faster / optimized; while translators need to understand the design of your language, but can be done in your development IDE without requiring an additional application to run.
AFAIK Xtext does not support written interpreters, it is somewhat beyond (incompletely) - for Xbase expressions there is an instance of XbaseInterpreter that can be reused - if you set its class path correctly), since they are extremely language specific.
I also donβt know the step-by-step guide for interpreting the Xtext DSL (even for XbaseInterpreter), but it basically comes down to bypassing the AST, and as the node goes through, the corresponding statement is executed dynamically. For this workaround to work, as expected, the interpreter must maintain a (possibly hierarchical) context of variables and other references.
source share