Domain Specific Languages

Narratives

An Introductory Example:

Using Domain Specific Languages:

Implementing DSLs:

Implementing an Internal DSL:

Implementing an External DSL:

Code Generation:

External DSL Topics

(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.

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

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.

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

(Host Code Embedment): Embed some host code into an external DSL to provide more elaborate behavior than can be specified in the DSL.

(BNF): [Topic]: Guide to BNF and EBNF syntaxes. How to transform EBNF into BNF

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

Internal DSL Topics

Expression Builder: An object that provides a fluent interface over a normal push-button 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 Collection Expression: Form language expressions using literal collection syntax

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): Define DSL expressions as macro definitions

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

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 in the same object by putting them in seperate files.

Alternative Computational Models

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

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

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 is published (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

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.