A simple Brainfuck interpreter and compiler that can output QBE IL and C. This implementation uses 30.000 8-bit wide cells.
This projects requires a C++ compiler with C++20 or later support. No external dependencies are used directly by the executable.
$ meson setup build/ && ninja -j $(nproc) -C build/
$ ./build/brainfck
$ c++ -Wall -pedantic --std=c++20 src/*.cpp -Iinc/ -o brainfck
$ ./brainfck
$ brainfck <subcommand> <file>
This application has three subcommands: run
, c
and qbe
. run
interprets
the provided brainfuck program on the fly, while c
and qbe
output the
transpilled code to stdout.
Since the program outputs code to stdout, it can be piped into a C compiler to create a final executable:
$ brainfck c sample.bf | cc -O2 -x c -o out -
or with QBE (assuming it can be located by the shell):
$ brainfck qbe sample.bf | qbe | cc -O2 -x assembler -o out -
The program can also read programs from stdin, using -
as filename:
# Outputs 'A'
$ echo "----[---->+<]>++." | ./build/brainfck run -
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.