SLE SS 2013 Assignment 2


Implement a DSL


Research a technology option for DSL implementation and demonstrate the technology with a fully working example. The implementation should make good use of the features that are supported by the technology. The final presentation should summarize the technology at a higher level of abstraction and explain the exercised DSL implementation in some detail.

DSL options

Let us favor a small number of scenarios of DSL implementations which should be adopted for the different technologies. Alternative proposals are appreciated, but they should be comparable in complexity. Please get in touch. There is a risk that, by the time of choosing technology and DSL options, it is not obvious that the chosen DSL will not work too well with the chosen technology. In this case, the DSL must be creatively evolved so that something interesting can still be shown with the chosen technology. (Also, the presentation should analyze the expressiveness of a technology to useful characterize the technology relative to the DSL option.)

Generalized member access

Regular member access is what we call "." for an OO language. For instance, consider some object o of say type Point. With regular member access, we can access the coordinates of o as in "o.x" and "o.y". Generalized member access stands for the idea that "." is "overloaded" to support other than basic attribute access. Here are some options for generalization:

  • If o in "o.x" is a map (hash map), then treat x as a key and perform lookup.
  • If o in "o.x" is a list type, then apply x to all elements of o and append the results. If some element cannot be accessed via x, then return the empty list.
  • If o in "o.x" is a tuple type, then treat it essentially like a list. (Here we assume that the host language has tuples.)

Can you think of some other idiom that could be subjected to generalized member access?

If you have trouble syntactically hijacking the regular "." operator (or whatever member access looks like in the chosen host language), then feel free to designated a new operator to generalized member access. The key challenge is to supported a syntactic form which generalized normal attribute access.

Yield return

In a basic programming language, when a method needs to return a list, then the method would actually construct a list object, add elements to the list, and then indeed return the list. .NET languages (and a few others) support a notion of "yield return" such that a method can simply "yield return" element by element. Such a construct should be added to the language at hand. Some pseudo-code in some fantastic C#-like language should help here.

Concise code with yield return:

// return even numbers up-to some limit

public List<int> even(int to) {
foreach (int x = 0; x < to; x += 2;) {
yield return x;

Non-concise (inefficient) code without yield return:

// return even numbers up-to some limit

public List<int> even(int to) {
var r = new List<int>();
foreach (int x = 0; x < to; x += 2;) {
return r;

This is not quite how it works in .NET, but it is interesting enough to try it this way. So we are sort of ignoring IEnumerables here. Anyway, you can also do any sort of variation on this sort of idea. The key challenge is here that this problem involves some non-local code rewriting.

Embedded HTML

DSL support is to be provided so that a few HTML tags are expressible and a corresponding markup document can be constructed. (Please do not implement too much of HTML, just enough to show the principles. Also, if HTML's lexical syntax causes trouble, use some other lexical convention.) It should be important that some sort of quasiquotation is available so that expressions and loops can be unquoted (spliced) into the constructed HTML. In some phantasy notation, we should be able to do this:

title = "hello";
numbers = ...;
x = [|
          ${for x in numbers do [|<li>${x}</li>|]}

As the result of the execution, variable x should be assigned with appropriate HTML tree.

Technology options

  • Converge
  • Haskell Quasiquotation
  • Helvetia
  • Kiama
  • Lisp/Scheme (w/ macros)
  • JastAddJ
  • JetBrains MPS
  • Lua (Metalua)
  • Nemerle
  • Polyglot
  • Spoofax
  • Sugar/J
  • Template Haskell

You can also find some other technology, but it is important to pick some technology suited for DSL implementation as opposed to plain development of unintegrated external or plain internal DSL implementation.

General logistics

See the course page for deadlines and conditions on successfully completing the assignments.


  • Kilian Pirl, Christoph Ehlen: Lisp, "yield return"
  • Kevin Keul, Freya Surberg: Nemerle, generalized member access or "yield return"
  • Tobias Keweloh, Jan RĂ¼ther: MPS, generalized member access
  • Erwin Schens: MetaOCaml, DSL to be defined
  • Matthias Barde, Florian Bernd: MetaLua, DSL to be defined
  • Jan Hendrik Borth, Eduard Schlining: JastAdd, "yield return"