Domain Specific Languages

Narratives

Preface: [Topic]:

An Introductory Example:

Using Domain Specific Languages:

Implementing DSLs:

Implementing an Internal DSL:

Implementing an External DSL:

Choosing Between and Internal and External DSLs:

Alternative Computational Models:

Code Generation:

Language Workbenches:

External DSL Topics

Tree Construction: The parser creates and returns a syntax tree representation of the source text that is manipulated by later tree walking code.

Embedded Translation: Embed translation code into the grammar.

(Embedded Interpretation): Embed interpreter actions into the grammar, so that executing the parser causes text to be directly interpreted to produce the response.

Delimiter Directed Translation: Translate source text by breaking it up into chunks (usually lines) and then parsing each line.

Syntax Directed Translation: Translate source text by defining a grammar, and using that grammar to structure translation.

BNF: Formally define the syntax of a programming language.

(Recursive Descent Parser): A particular implementation of top down parser, one that is particularly amenable to hand-writing.

Foreign Code: Embed some foreign code into an external DSL to provide more elaborate behavior than can be specified in the DSL.

Alternative Tokenization: Alter the lexing behavior from within the parser.

Nested Expression: [Topic]: Handle arithmetic and boolean expressions

Syntactic Newlines: Give syntactic meaning to newlines by making them statement separators.

External DSL Miscellany: [Topic]: Odds and ends about external DSLs

Internal DSL Topics

Expression Builder: An object that provides a fluent interface over a normal command-query API

Function Sequence: A combination of function calls as a sequence of statements.

Nested Function: Compose functions by nesting function calls as arguments of of other calls.

Method Chaining: Make modifier methods return the host object so that multiple modifiers can be invoked in a single expression.

Object Scoping: Put DSL code in a subclass of a class that provdes the DSL vocabulary.

Closure:

Nested Closure: Express statement sub-elements of a function call by putting them into a closure in an argument.

Literal List: Represent language expression with a literal list

Literal Map: Represent as a Literal Map

Dynamic Reception: Handle messages without defining them in the receiving class.

Annotation: Data about program elements, such as classes and methods, which can be processed during compilation or execution.

Macro: Transform input text into a different text before language processing using

Parse Tree Manipulation: Capture the parse tree of a code fragment to manipulate it with DSL processing code.

Class Symbol Table: Use a class and its fields to implement a symbol table in order to support type-aware completion in a statically typed language.

Textual Polishing: Perform simple textual substitutions before more serious processing

Literal Extension: Add methods to program literals.

Alternative Computational Models

Adaptive Model: Arrange blocks of code in a data structure to implement an alternative computational model.

Decision Table: Represent a combination of conditional statements in a tabular form.

Dependency Network: A list of tasks linked by dependency relationships. To run a task you invoke its dependencies, running those tasks if pre-requisites.

Production Rule System: Organize logic through a set of production rules, each of which has a condition and an action.

State Machine: Model a system as a set of explicit states with transitions betwen them.

Code Generation

Model-Aware Generation: Generate code with an explicit simulacrum of the the semantic model of the DSL, so that the generated code has generic-specific separation.

Model Ignorant Generation: Generate code with all logic hard coded into the generated code so that there's no explicit representation of the

Transformer Generation: Generate code by writing a transformer that navigates the input model and produces output.

Templated Generation: Generate output by hand-writing an output file and placing template call-outs to generate variable portions.

Embedment Helper: An object that minimizes code in a template system by providing all needed functions to that templating mechanism.

Generation Gap: Separate generated code from non generated code by inheritance.

Common Parser Topics

Semantic Model: The domain model that's populated by a DSL

Symbol Table: A location to store all identifiable objects during a parse to resolve references.

Context Variable: Use a variable to hold context required during a parse.

Construction Builder: Incrementally create an immutable object with a builder that stores constructor arguments in fields.

Not sure where this goes yet

The MDD view of the Language Landscape: [Topic]: Explains the levels of instance, schema, meta-model and meta-meta model.

(Migration Execution): Parse the DSL, but instead of executing in the usual way generate a new version of the DSL code.

For a while now, I've been working on a book on Domain Specific Languages. This page is a gateway into my Work In Progress on the book.

My current vision for the book is a Duplex Book, split into a section of narratives and a (larger) reference section of topics. At the moment most topics are in pattern form, but I don't expect this to be necessarily the case as I flesh them out. Reference items in parenthesis are just placeholders for material that I'll be writing later. I have a roadmap that gives the current state of the book and my vision for my next moves.

Be aware that this material is very much in the middle of sausage machine. Much of what's here is very rough and everything (especially pattern names) is likely to change without notice. Don't expect anything that's polished yet. This URL will be stable while I'm writing the book, but I'll take it down when the book enters the publication process (although I'll probably leave some markers somewhere as with the P of EAA material). So don't expect links to last for a long time.

If you want to be notified about changes I have included an atom feed.

I welcome comments, but please ignore typos: this is too early to be worried about those.

Updates

30 Jun 2009

I've suspended the updates of this page for the time being, as I've started talking to publishers. I may or may not resume updates in the future, depending on how the publisher wants to proceed. I'm still working on the book as I get it into a first review draft state, but I won't be updating the pages here.

03 Jun 2009

Added Context Variable

22 May 2009

First draft of Generation Gap

08 May 2009

First draft of Embedment Helper

05 May 2009

Added Literal Extension

25 Apr 2009

Added Text Polishing chapter.

22 Apr 2009

Split Literal Collection into Literal List and Map. Added chapter on Macros.

20 Apr 2009

Uploaded the start of a Language Workbench chapter with discussions on meta-models and projectional editing.

23 Feb 2009

Uploaded a narrative and several patterns on alternative computational models.

20 Jan 2009

Updated the narrative on implementing external DSLs into a coherent draft and uploaded a first draft of comparing internal and external DSLs. With this I've completed a first draft of the external DSL material.

02 Jan 2009

Posted Syntactic Newlines

17 Dec 2008

A lot (indeed too much) stuff in this update. Rewrote external DSL narrative. Posted Nested Expression and Alternative Tokenization. Rewrote Delimiter Directed Translation.

06 Nov 2008

Posted Foreign Code and BNF

20 Oct 2008

Posted Syntax Directed Translation

09 Sep 2008

Posted Delimiter Directed Translation.

04 Aug 2008

Posted Embedded Translation. I'm now focusing on the external DSL part of the book.

04 Aug 2008

Wrote up a roadmap to provide an overall state of the book - posted this in my bliki.

25 Jul 2008

Wrote first draft of Parse Tree Manipulation. Updated Expression Builder to make it consistent with the rest of this section.

30 Jun 2008

First draft of patterns on Dynamic Reception (overriding method_missing etc) and Annotation.

11 Jun 2008

Published drafts of a narrative on Code Generation and four code generation patterns.

28 Apr 2008

Published first draft of Tree Construction pattern. (This doesn't signal a shift in my writing focus, I'm not planning to focus on External DSLs just yet. I already had the example to hand and wanted to write it up to support some other posts I'm thinking of making.)

22 Apr 2008

Split the introductory narrative and added a narrative on general implementation notes (including some material on testing).

08 Apr 2008

Added the pattern Nested Closure. Also altered the opening part of the internal overview to talk more about fluent and push-button APIs.

28 Mar 2008

Added a write up for Symbol Table. The crux of why I've done Symbol Table at this point is to describe (with an example) the technique of using class and fields as a symbol table instead of the (more obvious) dictionary. Class and field allows static typing, particularly handy for IDE support with modern IDEs.

06 Mar 2008

Added a write up for Literal Collection Expression.

21 Feb 2008

Another long gap between updates - this time because I've been doing a lot of travelling and not been able to work on the book for the last month :-(. This change is a reworking of the basic patterns in the internal section. In particular I'm now founding the discussion of using functions on three function combination patterns: Function Sequence, Nested Function, and Method Chaining. I've also looked at using the notion of an informal grammar to help choose which technique is the best one to use.

10 Jan 2008

It's been a while since I've added anything - this isn't because I've not been working on things, just because I've been struggling with how to work with some particular material. But I now have it in a reasonable form. The new items are Computational Network, Dependency Network, and Closures.

11 Dec 2007

I've released Object Scoping. That pretty much gets me up to date with the material that I have in reasonable draft form.

05 Dec 2007

I've released the patterns for Global Scoping and Method Chaining. I also altered the definition text (in the intro) to put "computer language" as one of the definitional points of DSLs.

04 Dec 2007

As a result of an email conversation with Michael Hunger, I've changed the fluent java example in the introduction to one that uses java fields instead of strings to identify the elements of the state machine.

03 Dec 2007

I've started a yahoo group for discussion of the book. This is likely to only interest people who want to get into a discussion about how I put together the material in the book. As a result it's not a public list, but if you're interested in joining do send me an email.

30 Nov 2007

Released the expression builder pattern.

22 Nov 2007

Released a first draft of narrative on external DSLs. This is rather sketchier than I expect it will turn out to be - just enough to outline the flow the patterns.

19 Nov 2007

Released a first draft of narrative on internal DSLs.

15 Nov 2007

First publication of material - the introductory chapter.