An interpreter for brainfuck, the (in)famous esolang created by Urban Müller in 1993. This is meant to be a personal learning exercise so I can develop my understanding of how interpreters work. This interpreter has been tested on a variety of brainfuck source code files, and works without issue.
brainfuck programs consist of eight instructions, which manipulate a sequential number of cells using a pointer. From Wikipedia:
| Character | Description |
|---|---|
> |
Increment the data pointer by one (to point to the next cell to the right). |
< |
Decrement the data pointer by one (to point to the next cell to the left). |
+ |
Increment the byte at the data pointer by one. |
- |
Decrement the byte at the data pointer by one. |
. |
Output the byte at the data pointer. |
, |
Accept one byte of input, storing its value in the byte at the data pointer. |
[ |
If the byte at the data pointer is zero, then instead of moving the instruction pointer forward to the next command, jump it forward to the command after the matching ] command. |
] |
If the byte at the data pointer is nonzero, then instead of moving the instruction pointer forward to the next command, jump it back to the command after the matching [ command. |
First, ensure the following tools are installing on your machine:
Run the following in your terminal to clone this repository, navigate to its
root directory, and compile nbi:
git clone https://github.com/nsdigirolamo/nbi.git && cd nbi && make
After compiling nbi, you can run it on any file that contains brainfuck source
code. Brainfuck source code typically uses the .b file extension:
./nbi samples/hello_world.b