HiveBrain v1.2.0
Get Started
← Back to all entries
patternModerate

Formally describing a new domain specific programming language

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
formallynewprogrammingdescribinglanguagespecificdomain

Problem

I am about to implement a domain specific language for representation of social learning conventions. Part of the implementation is a formal description of a language - its 'calculus', symbols and logical expressions.

My approach would be to describe the language by describing its grammar but there are also concepts such as relations, dialogs, expectations that require more theoretic approach and the description of the logic.

I would like to ask for an example and a literature recommendation (papers, books) that would help me with this description. I feel relatively competent approaching this task so I am not asking for a total hand holding, but help from a theoretician in this area would be GREATLY appreciated.

Solution

There are two parts of the semantics you will need to describe:

-
static semantics: structure of well formed programs

-
dynamic semantics: meaning of running programmings

Static semantics usually take the form of type systems. I'd recommend looking at the books by Benjamin C Pierce and Robert Harper. Alternatively, you could write the rules of well-formed programs as a collection of (formal or informal) statements describing the validity conditions of your program. The formal approach taken by type systems provides a well-known framework for such specifications.

There are many formalisms for expressing the dynamic semantics to consider as your basis:

  • denotational semantics --- gives meaning in terms of semantic domains



  • operational semantics --- gives meaning in terms changes to an abstract machine states



  • axiomatic semantics --- gives meaning in terms of assertions about the state of the machine



  • algebraic semantics --- semantics is defined in terms of algebraic laws.



There should be plenty of books out there on these topics. A good broad introductory one is
Nielson and Nielson's Semantics with Applications. A downloadable version is available from the authors' site.
There is also a newer edition, but I haven't seen it.

Within each of these, there are choices to make. For example, if you decide to use operational semantics, there are large-step semantics, small step semantics, semantics based on labelled transition systems, semantics based on rewriting logic.

-
In Composing contracts: an adventure in financial engineering,
Simon Peyton Jones et al gives denotational semantics to a financial DSL.

-
The Denotational and Static Semantics of a Domain-Specific
Language for Flow-Network Design by
Assaf Kfoury presents a denotational semantics for a flow network DSL

-
Andrei Lapets' thesis Algebraic Semantics of Domain-Specific Languages
discusses algebraic semantics of DSLs.

-
There are many more: this, that, one in terms of abstract machines, another one.

What kind of approach you should take will depend on what kind of language your DSL is, what kind of experience you have with designing semantics, and your personal preference.

Without any concrete details, I can help no further.

Context

StackExchange Computer Science Q#3313, answer score: 10

Revisions (0)

No revisions yet.