&SPL – Creating a simple imperative programming language

SPL sample code

&SPL is an acronym for Simple Programming Language, and is a C-like imperative programming language, with classes, lists, and tuples. For example, the following code produces the Fibonacci sequence.

#include "stdlib/std.spl"

// Output the Fibonacci sequence
main ()
{
    var t1 = 0;
    var t2 = 1;

    while(True) {
        println(t2);
        var h = t1 + t2;
        t1 = t2;
        t2 = h;
    }
}

The language is formally defined with a context-free grammar and typing rules. In this post an implementation of an &SPL source code compiler implemented in Haskell will be discussed. The compiler compiles the source code into assembly for a Simple Stack Machine [1] (http://www.staff.science.uu.nl/~dijks106/SSM/) in a four-part process of lexing, parsing, typing and code generation. The source code is available on GitHub.

Continue reading “&SPL – Creating a simple imperative programming language”

[1] A. Dijkstra, “Simple stack machine.”
[Bibtex]
@Manual{SSM,
title = {Simple Stack Machine},
author = {Atze Dijkstra},
timestamp = {2017-06-18},
url = {http://www.staff.science.uu.nl/~dijks106/SSM/},
}