Version 26 of domain-specific language

Updated 2014-12-22 04:11:57 by pooryorick

A domain-specific language is a language purpose-built for a specific problem domain.

See Also

programming by exception
one way to end up with a DSL
little language

Reading

Using a hierarchy of Domain Specific Languages in complex software systems design ,V.S. Lugovsky ,2004-09-09

Tcl DSL's

fileutil::multip::op
a DSL for performing operations on groups of files
TDL
A DSL for XML
Gregor: A DSL for building semester calendars
Solving the advection-diffusion equation
see below

Description

A domain-specific language is a programming language designed explicitly to express activities in a certain domain, and either incidentally or purposefully limits itself to those expressions directly relevant to that domain.

Some examples:

  • Text processing: awk, sed, m4
  • Document preparation: LaTeX, roff
  • Page description: PostScript
  • Software development: make, Lex, Yacc
  • Mathematics: MATLAB , Scilab
  • systems-level bit-twiddling: C
  • interacting with command-line programs: Expect
  • composing structured text: STX, TIP format, wikit's page formatting language
  • everything that seems to fall outside Tcl syntax: all of the Tcl little languages
  • regexp

Controversial examples:

  • (not usually thought of as a language) network protocols for performing the network interaction specified by the protocol, so SMTP for example, can be considered a DSL for defining a mail exchange. If Java can use XML, we can use SMTP.
  • (also not usually thought of as a language) Undo Lists - programs which implement an undo function must do so by maintaining an ordered list of functions to apply to reverse a given operation - these have linguistic structure.

Aside from the concept of domain suitability alluded to above, many have tried to further pin down the defining characteristics of a DSL. For instance, see [L1 ] [L2 ] [L3 ]. Microsoft has its own visual-programming take on DSLs: [L4 ].

Tcl itself was designed as a primordial domain-specific language, ready to be extended into any specific domain via the customization of available commands in a given Tcl interpreter. John Ousterhout had written several tools for IC design, each sporting its own domain-specific language, and wrote Tcl as a single reusable DSL to end this pattern of implementing an ad-hoc quirky command interface for each program.

One tool method of extending Tcl into some domain is to create a safe interpreter and populate it with an appropriate set of commands.

NEM: Some people make the distinction between an embedded DSL and other forms of DSL. An embedded DSL extends some host language to add constructs relevant to some domain. In this case you have the full power of the host language available as well as the domain-specific features. Tcl lends itself well to this sort of DSL (regexp and expr are two examples). Lisp is another language good for EDSL development. The other choice is to make the DSL standalone, typically by writing an interpreter or compiler for it. In Tcl you can do that, as lexfiend says, by making use of interp and removing (or hiding) those commands that aren't needed and adding back in domain-specific ones. Another approach, popular in Java land, is to use XML to define a the syntax of a DSL. Visual DSLs are periodically trendy.


AM 2006-03-03: I consider the script in Solving the advection-diffusion equation an example of a domain-specific language:

  • The script defines some convenient commands to get the description of the physical-mathematical problem into the solver's data structures
  • It uses the control structures offered by Tcl to steer the computation and produce output.

CMcC 2006-09-13: Tcl is eminently suitable as a target for compilation of DSLs, in that it has a very regular/minimal syntax and a rich and extensible semantics. Tcl's syntax supports trees (as lists of lists) and lexically colouring elements with semantics (by using [] instead of {} to delineate sub-tree nodes.) It is therefore possible, and quite often effective, to transform (compile) a DSL into Tcl, then evaluate the product.

This is how I implement STX ... parsing the input text into functional units, basically duples (function and text-or-subexpression) and then lexically converting these into invocations of tcl-supplied semantics.