Alan Cameron Wills - Domain Specific Languages

Models, domain-specific languages, code generation, ....

Sorts of language

One thing to think about when inventing your domain specific language: what general sort of syntax do you want?  Here are some options:

  • Text — like, y’know, strings of characters in words separated by spaces and punctuation. Maybe there is some formatting like bold, italic, bullet points etc, but basically it’s a string.  Usually there will be some block structure (as in XML and any programming language) because the text really represents a tree (which you can get by parsing and looking at the DOM) or a graph (if you think of declared names as representing links across the tree).
  • Block-laid text — including
    • Tables — as in spreadsheets etc
    • Math formulae with big divisions and matrices and superscripts and so on — like TeX does.
    • Anything HTML can produce
    • Nassi-Schneiderman diagrams
    • Software architecture
  • Node-and-line diagrams — all about things and relationships. Often the nodes are boxes; sometimes the nodes can be nested. Includes:
  • Channel diagrams — usually about time sequence and the interactions between things.
    • Sequence diagrams and activity diagrams with swimlanes
    • GANTT and PERT charts
  • Cartesian — where the relative distances, shapes and areas are important
    • Graphs
    • Geographical maps
    • Building plans
  • 3D — where your editing tools display a projection
    • Hardware design
    • Data envisioning

Metalanguages – But notice that if your business is to make tools working in a particular domain, then the DSL you want in order to generate or configure those tools is probably a meta-level above the target domain. For instance, if you write Geographical Information Systems, then your end-users will be working a lot with maps; but what you want is to be able to define operations on the maps and whatever’s shown on them. So you might find some variant of SQL to be what you need.

Aspects – Secondly, your ideal DSL will probably include more than one sort of syntax. E.g. entity-relational diagrams to define the classes of thing you’re working with, and sequence diagrams to tell what to do with them.  Tools should make it easy to cross-link between them.