Skip to content

leleneme/brainfck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple Brainfuck interpreter and compiler that can output QBE IL and C. This implementation uses 30.000 8-bit wide cells.

Building

This projects requires a C++ compiler with C++20 or later support. No external dependencies are used directly by the executable.

With Meson:
$ meson setup build/ && ninja -j $(nproc) -C build/
$ ./build/brainfck
Without Meson:
$ c++ -Wall -pedantic --std=c++20 src/*.cpp -Iinc/ -o brainfck
$ ./brainfck

Usage

$ 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 - 

License

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/.

About

A simple Brainfuck interpreter and compiler that can output QBE IL and C. Written in C++.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published