that models the syntax and semantics
at the same level of abstraction as the
domain itself. 4
You may be wondering how this
particular DSL example developed
from the domain model and the common vocabulary business users speak.
It involved four major steps:
1. In collaboration with the business users, you derive the common
vocabulary of the domain that needs
to be used in all aspects the development cycle.
2. You build the domain model using the common vocabulary and the
programming language abstractions
of the underlying host language.
3. Again in collaboration with the
business users, you develop syntactic
constructs that glue together the various domain model elements, publishing the syntax for the DSL users. This
is a major advantage over a process
where you come up with a shared vocabulary up front and then drive the
Figure 1. Anatomy of a DSL.
development of the application solely
based on that dictionary. In a DSL-based development, you actually develop DSL constructs using the shared
vocabulary as the building blocks of
your business rules. The actual rules
get developed on top of these syntactic constructs.
4. Then you develop the business
rules using the syntax of the previous
step. In some cases the actual domain
users may also participate in the development.
An Introduction to DSL
Designing a DSL is not nearly as
daunting a task as designing a general-purpose programming language. A
DSL has a very limited focus, and its
surface area is restricted to only the
current domain being modeled. In
fact, most of the common DSLs used
today are designed as pure embedded programs within the structure of
an existing programming language.
Later we show how to accomplish this
embedding process to create a mini-language while using the infrastructure of the underlying implementation language.
Martin Fowler classified DSLs
based on the way they are implemented. 3 A DSL implemented on top of an
underlying programming language
is called an internal DSL, embedded
within the language that implements
it (hence, it is also known as an
embedded DSL). An internal DSL script is, in
essence, a program written in the host
language and uses the entire infrastructure of the host.
A DSL designed as an independent
language without using the infrastructure of an existing host language is
called an external DSL. It has its own
syntax, semantics, and language infrastructure implemented separately
by the designer (hence, it is also called
a standalone DSL).
This article focuses primarily on internal, or embedded, DSLs.
offers dsl expressivity
on top of
offers core implementation
Figure 2. DSL snippet showing domain vocabulary and bubble words.
new_trade 'T-12435' for account 'acc-123'
to buy 100 shares of 'IBM',
at UnitPrice= 100, Principal-12000, Tax=500
Advantages of using a DSL