A Brainfuck language interpreter with a few slight additions, written in Go.
- Windows
./brainfuck-windows.exe <file path> [memory allocation]
./brainfuck-windows-32.exe <file path> [memory allocation]
./brainfuck-windows-arm64.exe <file path> [memory allocation]
- macOS
./brainfuck-macos-intel <file path> [memory allocation] # For Macs with Intel processors
./brainfuck-macos-arm <file path> [memory allocation] # For Macs with Apple M processors
- Linux
./brainfuck-linux <file path> [memory allocation]
./brainfuck-linux-32 <file path> [memory allocation]
./brainfuck-linux-arm <file path> [memory allocation]
./brainfuck-linux-arm64 <file path> [memory allocation]
Note
If you see permission denied
error when running the file, make the file executable
by typing chmod +x brainfuck-*
To do this, you must have the Go 1.22+ compiler installed.
go run brainfuck <file path> [memory allocation]
This project is available as a Docker image and can be pulled from GitHub Container Registry.
Dockerfile example:
FROM ghcr.io/wavy-cat/gobrainfuck
COPY . .
ENTRYPOINT ["brainfuck", "main.bf"]
Command | Go Equivalent | Meaning |
---|---|---|
> |
cursor++ |
Move to the next cell |
< |
cursor-- |
Move to the previous cell |
+ |
memory[cursor]++ |
Increase the value in the current cell by 1 |
- |
memory[cursor]-- |
Decrease the value in the current cell by 1 |
. |
fmt.Print(string(memory[cursor])) |
Print the contents of the current cell |
, |
fmt.Scanln(&byte) |
Store user input in a cell |
[ |
for memory[cursor] != 0 { |
Start of loop |
] |
} |
End of loop |
* |
fmt.Print(memory[cursor]) |
Print the contents of the current cell in raw form |
The
*
command is not present in the official language specification, nevertheless, it was introduced in this implementation for simplicity of debugging. Whenever possible, use code that fully conforms to the official specification, for examplen>>+++++++++[<++++++>-]----[<+>-]<.
.
Input using ,
command works with os.Stdin
. Only the first byte (the first character) is written.
An empty input will write the value 0 to the cell.
Usually, ASCII characters are accepted, but you can specify a number directly if you start the line with //
.
For example, //69
will write the number 69 to the cell.
Output is implemented via fmt.Print()
. Usually, the character under the number written in the cell is displayed,
however, you can print the number itself using the *
command.
By default, the interpreter allocates 30,000 memory cells, by the language design. But you can specify a different number of cells before starting the program. All you need to do is specify the desired number of memory cells in the launch command, placing the number immediately after the file path. Here is an example, where 100 memory cells are allocated:
./brainfuck-* <file path> 100
This is an optional step.
- Download the file of the latest version of the interpreter.
- Make it executable by running
chmod +x brainfuck-*
. - Move it to
/usr/bin
using the commandsudo mv brainfuck-* brainfuck
. - Verify its functionality by executing
brainfuck version
.
Note
Please note that compiled builds are available in Actions.
- Install the latest version of the Go compiler from the official site
- Initiate the compilation using
go build brainfuck
Example for Linux on the amd64 platform with root permissions:
wget https://go.dev/dl/go1.22.2.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.22.2.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
go build brainfuck