Programming languages are amazing pieces of work. They turn our words, numbers, and symbols into the bits that make a machine do things.
It’s easy to get overwhelmed when implementing a programming language. The GNU Compiler Collection is millions of lines long.
That’s too complicated to learn how to implement a programming language. Luckily, some smart people have distilled the most interesting parts of programming languages into an approachable essence. I’m referring to implementations of programming languages that fit in a single source code file.
These single-file implementations are rarely complete, hardly sophisticated or efficient. But they are self-contained, concise, and clear. They make it fun to discover why programming languages are amazing.
7 lines of code, 3 minutes implemented by Matt Might.
arpilisp implemented by Marc Paquette.
(How to Write a (Lisp) Interpreter (in Python)) implemented by Peter Norvig.
komplott implemented by Kristoffer Grönlund.
Lisp9 implemented by Nils M. Holm. A byte-compiling Lisp interpreter.
Lisp90 implemented by Anthony C. Hay.
Lisp In Less Than 200 Lines Of C implemented by Carl Douglas.
MiniLisp implemented by Rui Ueyama.
Mini-Scheme updated by Chris Pressey, originally implemented by Atsushi Moriwaki.
mLite implemented by Nils M. Holm. A lightweight variant of ML.
sedlisp implemented by Shinichiro Hamaji.
single_cream, scheme interpreter implemented by Raymond Nicholson.
ulc implemented by Asad Saeeduddin. A minimalistic implementation of the untyped lambda calculus in JS
asm6502.py implemented by David Beazley.
Brainfuck implemented by Brian Raiter.
c4 C in 4 functions, implemented by Robert Swierczek.
dc implemented by Lorinda Cherry.
jonesForth implemented by Richard W.M. Jones.
Mini-C implemented by Sam Nipps. A small subset of C, of course. But not as small as you would guess.
Mouse implemented by Peter Grogono.
Pascal-S implemented by Niklaus Wirth & Scott A. Moore.
picol is a Tcl interpreter implemented in C. Implemented by Salvatore Sanfilippo, aka antirez.
swizzle implemented by Robert Swierczek.
The Super Tiny Compiler! implemented by James Kyle.
Tiny Basic implemented by Tom Pittman.
Trac implemented by Jack Trainor.
Tutorial – Write a Shell in C implemented by Stephen Brennan.
VTL02 for 6502 ported and improved by Mike Barry. VTL-02 was originally designed and implemented by Gary Shannon & Frank McCoy.
microKanren is a Kanren interpreter, implemented by Jason Hemann.
prolog.c is a simple Prolog interpreter written in C++, implemented by Alan Mycroft.
Prolog originally implemented by Ken Kahn, adapted by Nils M. Holm.
256LOL implemented by Jeff Overbey. An x86 assembler in 256 lines or less. Technically not a single file but Jeff gives good descriptions of the problems with elegant, simple solutions.
An Implementation of J implemented by Arthur Whitney. See the appendix “Incunabulum”. It’s only a fragment of the J interpreter, but its conciseness is impressive.
A Regular Expression Matcher implemented by Rob Pike, exegesis by Brian Kernighan.
Microlisp, a Scheme-like lisp in less than 1000 loc of C, implemented by Michael Lazear. A single-implementation with extra files for examples and building.
Tiny Compiler implemented by Minko Gechev. It translates only arithmetic expressions, but it’s well written.
Have you implemented a programming language in a single file? Let me know with a pull request.