The Expressions DSL
In the DSL we develop in this chapter, which we call Expressions DSL, we want to accept input programs consisting of the following statements: variable declarations with an initialization expression and evaluations of expressions. Variable declarations have the shape var name = exp
and evaluation statements have the shape eval exp
. 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:
var i = 0 var j = (i > 0 && 1 < (i+1)) var k = 1 eval j || true eval "a" + (2 * (3 + 5)) // string concatenation eval (12 / (3 * 2))
For example, "a" + (2 * (3 + 5))
should...