Fuck rust
A Brainfuck interpreter in Rust: all eight commands, file input, and an optional debug mode that dumps raw byte output.
Why brainfuck
Brainfuck is a language with exactly eight commands, designed to challenge and amuse programmers. Building an interpreter for it is a compact way to practice parsers, tape semantics, and error handling in a new language: no framework, no dependencies, just the spec.
The whole spec
| Command | What it does |
|---|---|
> |
move the pointer to the next cell |
< |
move the pointer to the previous cell |
+ |
increase the value at the current cell by 1 |
- |
decrease the value at the current cell by 1 |
. |
output the ASCII representation of the current cell |
, |
get a single byte of input from the user |
[ |
start a loop; execute if the current cell is non-zero |
] |
end a loop; jump back if the current cell is non-zero |
That table is the entire language. The interpreter’s job is to make that table fast, correct, and debuggable. The interesting part of “trivial” languages is always the edge cases, not the happy path.
Loop semantics
++++++++++[>+>+++>+++++++>++++++++++<<<<-]>>>.
Loops are bracket-matched: [ enters only while the current cell is non-zero, ] jumps back while non-zero. Getting the jump bookkeeping exactly right is where interpreters for minimal languages earn their keep: off-by-one in a jump target and every program after it is garbage.
Debug mode
The honest edge case
Invalid commands are validated and reported. Unmatched brackets are the documented gap
A --debug flag prints the raw output as a vector of bytes instead of ASCII, which is essential when a program manipulates values that aren’t printable. The toy becomes a tool for verifying programs that work below the character layer.