Home

Awesome

DIY Lang

batteries included, some assembly required

In this tutorial/workshop we'll be implementing our own little language, more or less from scratch.

By the end of the tutorial you will be the proud author of a programming language, and will hopefully better understand how programming languages work on a fundamental level.

What we will be making

We will make a relatively simple, but neat language. We aim for the following features:

We will not have:

The language should be able to interpret the following code by the time we are done:

(define fact
    ;; Factorial function
    (lambda (n)
        (if (eq n 0)
            1 ; Factorial of 0 is 1
            (* n (fact (- n 1))))))

;; When parsing the file, the last statement is returned
(fact 5)

The syntax is very similar to languages in the Lisp family. If you find the example unfamiliar, you might want to have a look at a more detailed description of the language.

Prerequisites

First, clone this repo.

git clone https://github.com/kvalle/diy-lang.git
cd diy-lang

Then, depending on your platform:

Test your setup

Once installed, run nosetests --stop see that everything is working properly. This will run the test suite, stopping at the first failure. Expect something like the following:

$ nosetests --stop
E
======================================================================
ERROR: TEST 1.1: Parsing a single symbol.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/home/vagrant/diy-lang/tests/test_1_parsing.py", line 15, in test_parse_single_symbol
    assert_equals('foo', parse('foo'))
  File "/home/vagrant/diy-lang/diylang/parser.py", line 17, in parse
    raise NotImplementedError("DIY")
NotImplementedError: DIY

----------------------------------------------------------------------
Ran 1 test in 0.034s

FAILED (errors=1)

A few tips

Take the time to consider the following points before we get going:

Get started!

The workshop is split up into eight parts. Each consist of an introduction, and a bunch of unit tests which it is your task to make run. When all the tests run, you'll have implemented that part of the language.

Have fun!