This is a 5-part tutorial on how to implement a programming language. It is intended for people with some programming experience, who want to know how their compiler, interpreter or virtual machine works. Hint: it's not magic.

There are many articles (even books!) on this topic. I'm writing mine with two purposes in mind:

  1. to keep it short and easy to follow by (hopefully) any programmer;
  2. to have an useful interpreter at the end of each installment.

The reader is expected to have basic-to-average programming knowledge, especially about objects, data structures and variable scope. Knowing some Javascript is necessary in order to understand the sample code.

Table of contents

  1. Part 0: motivations — DRAFT 1 — 2008-10-09
  2. Part 1: numbers and words — DRAFT 2 — 2008-09-06 (source code for part 1)
  3. Part 2: variables, string, comments — DRAFT — 2008-09-07 (source code for part 2)
  4. Part 3: user-defined words — DRAFT — 2009-05-17 (source code for part 3)
  5. Part 4: control structures — DRAFT — 2009-06-07 (source code for part 4)
  6. Part 5: conclusions — DRAFT — 2009-06-07
  7. Appendix A: a practical implementation — WORK IN PROGRESS — 2010-06-14

Each part comes with a working Javascript implementation of the interpreter described until that point. The code is tested and believed to work in Opera 9.5+, Firefox 3, WebKit and Konqueror.


Alex Bolboacă has been kind enough to review parts of the tutorial.

Syntax highlighting of the code samples is powered by JUSH.