Skip to content
/ b1fipl Public

A Bestiary of Single-File Implementations of Programming Languages

Notifications You must be signed in to change notification settings

marcpaq/b1fipl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 

Repository files navigation

A Bestiary of Single-File Implementations of Programming Languages

From a French Prayer-book of the Thirteenth Century, in the British Museum.

Programming languages are amazing

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.

Concatenative

bbf, v3 implemented by Mark Carter. A Forth in C.

dc implemented by Lorinda Cherry.

Forth1 implemented by Tycho Luyben.

jonesForth implemented by Richard W.M. Jones.

Mouse implemented by Peter Grogono.

Functional

7 lines of code, 3 minutes implemented by Matt Might.

arpilisp implemented by Marc Paquette.

How to implement a programming language in JavaScript implemented by Mihai Bazon.

(How to Write a (Lisp) Interpreter (in Python)) implemented by Peter Norvig.

komplott implemented by Kristoffer Grönlund.

Lisp500 implemented by Teemu Kalvas.

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.

Most functional implemented by John Tromp. An implementation of binary lambda calculus in 25 lines of obfuscated C.

sectorlisp implemented by Justine Alexandra Roberts Tunney et al. An x86 Lisp interpreter that fits in a boot sector.

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

Imperative

asm6502.py implemented by David Beazley.

wak is the single-file version of a "fairly compact implementation of the AWK programming language", implemented by Ray Gardner.

bc implemented by depsterr. Compiles brainfuck into an x86_64 linux binary.

Brainfuck implemented by Brian Raiter.

c4 C in 4 functions, implemented by Robert Swierczek.

Jasic implemented by Robert Nystrom. Old-school BASIC in Java.

mescc-tools-seed, implemented by Jeremiah Orians. A complete chain of one-file languages, from compiler to assemblers and even a shell, for Intel x86: C compiler in assembly, macro assembler to build the C compiler, hex2 assembler to build the macro assembler, hex1 assembler to build the hex2 assembler, hex0 assembler to bootstrap the whole thing, and finally, a shell to script the previous stages.

Mini-C implemented by Sam Nipps. A small subset of C, of course. But not as small as you would guess.

Pascal-S implemented by Niklaus Wirth & Scott A. Moore.

picol is a Tcl interpreter implemented in C. Implemented by Salvatore Sanfilippo, aka antirez.

Selfie includes a 1-file C compiler in C. Implemented by the Computational Systems Group at the Department of Computer Sciences of the University of Salzburg.

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.

Logical

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.

Tiny Prolog in OCaml is an interpreter for a subset of Prolog, in OCaml, implemented by Lilian Besson (@Naereen)

Honourable Mentions

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.

JS-Interpreter implemented by Neil Fraser. A JavaScript interpreter in JavaScript. This file is part of a larger project for running JavaScript in a sandbox.

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.

Epilogue

Have you implemented a programming language in a single file? Let me know with a pull request.

Or fork your own b1fipl. If you do, please give me credit.

Image credit

Parton, James. Caricature and Other Comic Art in all Times and many Lands. Project Gutenberg. Retrieved 2021-02-04. http://gutenberg.org/ebooks/39347

About

A Bestiary of Single-File Implementations of Programming Languages

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published