BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Article: Developing a Complex External DSL

Article: Developing a Complex External DSL

Bookmarks

In this article Vaughn Vernon explains the difference between internal and external DSLs and shows the steps involved in developing a complex external DSL.

Read: Developing a Complex External DSL

Before starting his example of developing an external DSL, Vernon makes the difference between internal and external DSLs. For an internal DSL, “the language that is developed could be very closely tied to and implemented on top of the primary general purpose programming language in use in your project, such as Java, C#, or Ruby.” Creating an external DSL is:

analogous to creating a general purpose programming language that is either compiled or interpreted. The language has a formal grammar; that is to say, the language is constrained to allow only well-defined keywords and expression types.

The first step in DSL development is defining a syntax, and Vernon offers advice on how to do that:

  1. Study other languages.
  2. Experiment with various syntax ideas using agile techniques.
  3. Identify as many language features as possible.
  4. Present your language before communities of potential users.
  5. Beta test your language.

The next step is defining a metamodel:

Think of source code written in a language's grammar (syntax) as a model of concepts that you are describing. The concepts you are describing could be data, structure, and behavior, which are typical concepts in computerlandia. From the language designer's point of view, the descriptions of these concepts are a model, not just source code. Thus, when you parse a source model and put its representational contents into objects, the objects are called a metamodel.

Next comes the parser, and Vernon gives the reader a basic example how it can be done. The last step is generating the code from the model, and the author deals with multiple approaches, like: generating the code directly from the model, walking the metamodel, eventing the metamodel, using code templates, the last representing a recommended choice.

Rate this Article

Adoption
Style

BT