A complete Brainfuck programming language interpreter implemented in C.
clang -g brainfuck.c -o brainfuck
# or
gcc -g brainfuck.c -o brainfuckMethod 1: Execute code directly
./brainfuck '++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.'Method 2: Execute from file
./brainfuck bf_tests/test.bfBrainfuck has 8 basic commands that operate on a memory array and a pointer:
| Command | Operation | Description |
|---|---|---|
> |
Pointer++ | Move data pointer one position to the right |
< |
Pointer-- | Move data pointer one position to the left |
+ |
Value++ | Increment current cell value by 1 (wraps 0-255) |
- |
Value-- | Decrement current cell value by 1 (wraps 0-255) |
. |
Output | Output ASCII character of current cell value |
, |
Input | Read one character into current cell |
[ |
Loop Start | Jump to matching ] if current value is 0 |
] |
Loop End | Jump to matching [ if current value is non-zero |
All other characters are ignored, allowing for comments in the code.
- Memory Size: 30,000 bytes (cells)
- Initial Value: All cells initialized to 0
- Data Type: Unsigned byte (0-255, wrapping)
- Pointer Range: 0-29,999 (out of bounds causes error)
- ✅ Complete Command Support - All 8 standard Brainfuck commands
- ✅ Bracket Matching Check - Automatically detects mismatched
[and] - ✅ Error Handling - Detects pointer out-of-bounds and bracket errors
- ✅ File and CLI Support - Supports reading from files or passing code directly
- ✅ Standard I/O - Full support for input (
,) and output (.) - ✅ 30KB Memory - Sufficient for running most Brainfuck programs
clang -g -O0 brainfuck.c -o brainfuckclang -O2 brainfuck.c -o brainfuckThe project includes a test script run_tests.sh to verify all functionality:
./run_tests.shTest Coverage:
- ✅ Hello World program
- ✅ Single character output
- ✅ Multiple character output
- ✅ File execution
- ✅ Loops and calculations
.
├── brainfuck.c # Interpreter source code
├── brainfuck # Compiled executable
├── bf_tests/ # Stored Brainfuck test files
│ ├── test.bf
│ ├── test2.bf
│ ├── test5.bf
│ └── test8.bf
├── run_tests.sh # Automated test script
└── README.md # This file
- Brainfuck Wikipedia
- Esolang Brainfuck
- Try It Online - Online Brainfuck editor
MIT
r1file
Note: Brainfuck is a minimalist, Turing-complete programming language designed to demonstrate the possibility of an extremely minimal programming language. While rarely used in practice, it's valuable for learning compiler and interpreter design principles.