JavaScript Python Lua assembler brainfuck-interpreter esoteric-language Rust Haskell C
Need help with brainfuck?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.


BF playground

137 Stars 23 Forks MIT License 155 Commits 0 Opened issues

Services available

Need anything else?


A collection of brainfuck interpreters/translators.



This project is just really a playground to try different languages. A nice excuse to do something a bit more complex than a "hello world". New BF programs or interpreters in other languages are absolutely welcome!



directory contains a gallery of BF programs, most of them taken from other sites dedicated to BF (check See Also). Notable mentions:



Simple interpreter written in x86_64 asm, using Mac OS syscall conventions.

Source: asm/brainfuck.s

$ cd asm
$ make
as -arch x86_64 brainfuck.s -o brainfuck.o
ld -e _main -arch x86_64 -lc brainfuck.o -o brainfuck 
ld: warning: -macosx_version_min not specified, assuming 10.6
rm brainfuck.o
$ ./brainfuck ../programs/
Primes up to: 50
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47  


Simple implementation, with precalculated jumps.

Source: c/brainfuck.c

$ cd c
$ make brainfuck
cc brainfuck.c -o brainfuck
$ ./brainfuck ../programs/
Hello World!


There are currently two interpreters in different styles, and a JIT compiler (see

All tested with Clang 11.0.3 and GCC 10.1.0.

See more in cpp.

Quick example:

$ cd cpp
$ make brainfuck-jit
c++ -std=c++14 -g -O3 brainfuck-jit.cpp -o brainfuck-jit
$ ./brainfuck-jit ../programs/
Hello World!


Source: go/brainfuck.go

Running the number warper with the go interpreter:

$ cd go
$ GOPATH=$PWD go run brainfuck.go ../programs/
/\ \/

Thanks Philip K. for the contribution!


Interpreter source: haskell/brainfuck.hs

Translator to C: haskell/bf2c.hs

To run the interpreter:

$ cd haskell
$ runhaskell brainfuck.hs ../programs/
Hello World!

To translate any BF program to C:

$ cd haskell
$ make ../programs/sierpinski.c
runhaskell bf2c.hs < ../programs/ | indent > sierpinski.c
$ make sierpinski
cc sierpinski.c -o sierpinski
$ ./sierpinski


Source: javascript/brainfuck.js

Simple debugger-like UI, using Bootstrap and jQuery (yes, I'm old school) with support for:

  • Memory inspection
  • Step-by-step execution
  • Configurable speed (instructions per cycle/delay between cycles)
  • Gallery of sample programs, loaded on the fly
  • Choice of pure JS or WASM engine

JS UI Screenshot

The JS version can run in stand-alone mode, but to enable the WASM engine a minimal HTTP server is needed. In the

directory, run:
$ cd javascript
$ python -m SimpleHTTPServer
Serving HTTP on port 8000 ...

Then connect to http://localhost:8000

Alternatively, use the online version available at


Interpreter source: lua/brainfuck.lua

Translator source: lua/bf2lua.lua

The interpreter is compatible with Lua 5.1, 5.2 and 5.3, and runs with LuaJIT. To run it:

$ cd lua
$ lua brainfuck.lua ../programs/
Hello World!

Running the same program, but the version translated to Lua:

$ cd lua
$ lua bf2lua.lua ../programs/ | lua -
Hello World!

Thanks François Perrad for the contribution!


Original, unoptimized, verbose interpreter: python/

Optimized (no method lookups, pre-computed jumps over minified source): python/

Slightly modified version of the optimized interpreter so it can be translated to C, using RPython: python/

JIT-enabled version: python/

Using the plain python interpreter to run a "helloworld" program:

$ cd python
$ cat << EOF | python 
> ++++++++++[>+++++++>++++++++++>+++>+<<<++.>+.+++++++..+++.>++.<.+++.------.--------.>+.>.
Hello World!

To use the RPython version:

$ cd 
$ python rpython/translator/goal/ ~/Projects/github/brainfuck/python/
$ time ./brainfuck-rpython-c ~/Projects/github/brainfuck/programs/
real  0m29.978s
user  0m29.796s
sys  0m0.110s

To use the JIT-enabled version: (thanks Gsam for the suggestion)

$ python rpython/translator/goal/ --opt=jit ~/Projects/github/brainfuck/python/
$ time ./brainfuck-rpython-jit-c ~/Projects/github/brainfuck/programs/
real  0m4.943s
user  0m4.867s
sys  0m0.043s


Interpreter source: rust/src/ Includes improved optimizations (compressing identical contiguous operations)

Translator source: rust/src/bin/ Supports translating to Rust and C.

JIT version: rust/src/bin/ See

To run the interpreter:

$ cd rust
$ cargo run ../programs/
    Finished dev [optimized + debuginfo] target(s) in 0.01s
     Running `target/debug/main ../programs/`
Primes up to: 50
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47

To translate to Rust:

$ ./ ../programs/ rs
    Finished dev [optimized + debuginfo] target(s) in 0.02s
     Running `target/debug/translate rs`
   Compiling brainfuck v0.1.0 (/Users/pablo/Projects/github/pablojorge/brainfuck/rust)
    Finished dev [optimized + debuginfo] target(s) in 0.38s

real 0m0.419s user 0m0.299s sys 0m0.134s Finished dev [optimized + debuginfo] target(s) in 0.01s Running target/debug/mandelbrot [...]

real 0m2.049s user 0m1.976s sys 0m0.047s

And to C:

$ ./ ../programs/ c
    Finished dev [optimized + debuginfo] target(s) in 0.02s
     Running `target/debug/translate c`
cc -O1 mandelbrot.c -o mandelbrot

real 0m1.603s user 0m1.448s sys 0m0.114s [...]

real 0m1.006s user 0m0.985s sys 0m0.009s


Rust interpreter, prepared to be compiled to WASM: wasm/src/

To generate the WASM binary and JS glue:

$ cd rust
$ wasm-pack build --target web

That will generate the target libs in

. To try in the browser:
$ python -m SimpleHTTPServer

And then connect to http://localhost:8000. Modify the

vars in
to try other programs.


| | Mandelbrot | Primes up to 100 | | ---: | :---: | :---: | | Non-optimized python version (CPython) | 991m45.631s | 19m34.163s | | Non-optimized python version (PyPy) | 24m59.928s | 0m28.210s | | Simplified python version (CPython) | 67m39.287s | 1m16.431s | | Simplified python version (PyPy) | 1m35.345s | 0m2.144s | | Improved python version (RPython) | 0m29.796s | 0m0.486s | | JIT-enabled version (RPython-JIT) | 0m4.867s | 0m0.107s | | Assembler | 1m7.288s | 0m1.501s | | C Interpreter (-O0) | 2m7.036s | 0m2.012s | | C Interpreter (-O1) | 1m7.504s | 0m1.005s | | Translated to C (-O0) | 0m19.674s | 0m0.243s | | Translated to C (-O1) | 0m1.360s | 0m0.012s |


  • The same code is 40 times slower in CPython vs PyPy. You can have a really big gain for "free" (almost), by just using the PyPy interpreter.
  • Adapting the source to RPython is not free of course, and the gain is not as big, BUT if we explictly add support for the JIT, the gain makes it totally worthy. In fact the gain of this version compared with running the simplified version (unmodified) with PyPy, is comparable to the gain obtained by running the unmodified version with PyPy vs running it with CPython.
  • The other performance differences are totally expected (C interpreter compiled with optimisations has an equivalent performance to the assembler interpreter, the translated to C version is almost two orders of magnitude faster than the interpreted version, etc.).
  • The JIT-enabled Python version runs faster than the translated-to-C version (compiled without optimizations).

See Also

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.