In the DSL we develop in this chapter, which we call
Expressions DSL, we want to accept input programs consisting of expressions and variable declarations with an initialization expression. Expressions can refer to variables and can perform arithmetic operations, compare expressions, use logical connectors (and
and or
), and concatenate strings. We will use +
both for representing arithmetic addition and for string concatenation; when used with strings, the +
will also have to automatically convert integers and booleans occurring in such expressions into strings.
Here is an example of a program that we want to write with this DSL:
i = 0 j = (i > 0 && (1) < (i+1)) k = 1 j || true "a" + (2 * (3 + 5)) // string concatenation (12 / (3 * 2))
For example, "a" + (2 * (3 + 5))
should evaluate to the string "a16"
.
First of all, we will use the Xtext project wizard to create the projects for our DSL (following the same procedure explained in Chapter...