A simple Brainfuck interpreter written in C++. Brainfuck is a minimal and esoteric programming language with an extremely limited set of commands, making it an excellent subject for study and amusement.
Just for fun. Enjoy!
-
Clone the repository:
git clone https://github.com/neutrinozh/brainfuck.git
-
Build the project:
cd brainfuck cmake -B ./build/ cmake --build ./build/
-
Run the interpreter with a Brainfuck program:
cd .. ./build/brainfuck ./examples/hello-world.bf
Sample Brainfuck programs can be found in the examples
directory. You can use them to test the interpreter.
Brainfuck consists of only 8 commands:
>
: Increment the pointer<
: Decrement the pointer+
: Increment the value at the current cell-
: Decrement the value at the current cell[
: Begin loop (jump forward to the corresponding]
if the value at the current cell is 0)]
: End loop (jump back to the corresponding[
if the value at the current cell is nonzero),
: Input a character (ASCII).
: Output a character (ASCII)
- Replacing multiple
>
or<
with one instruction with a parameter of count increments or decrements pointer. - Replacing multiple
+
or-
with one instruction with a parameter of value for incrementing or decrementing the value of the current cell. - Saving instruction numbers for
[
and]
allows executing jumps between corresponding instructions without the need to iterate over all instructions, preventing delays in program execution. - Optimizing
[+]
and[-]
into one instructionset_zero
This project is licensed under the MIT License - see the LICENSE file for details.