A closure-based Brainfuck interpreter in C and C++.
Instead of the typical switch-statement interpreter loop, this compiles Brainfuck programs into a sequence of closures (function pointers) that can be executed directly.
Inspired by this PlanetScale post on interpreter performance and skx/closure-based-brainfuck-vm.
Most Brainfuck interpreters read each character and dispatch via a switch.
make
# or directly:
gcc -O2 -o bf bf.c
g++ -O2 -o bf++ bf.cpp./bf program.bfbf.c— C implementationbf.cpp— C++ implementationMakefile— Build script
| Command | Description |
|---|---|
> |
Move pointer right |
< |
Move pointer left |
+ |
Increment current cell |
- |
Decrement current cell |
. |
Output current cell as ASCII |
, |
Read one byte of input |
[ |
Jump past matching ] if cell is zero |
] |
Jump back to matching [ if cell is non-zero |