A Brainfuck interpreter made in Zig
Find a file
2024-12-23 12:17:22 +00:00
examples Adding some examples 2024-12-18 22:54:43 +00:00
src Add LICENSE, update README, set version to 1.0.0 2024-12-23 12:17:22 +00:00
.gitignore Exclude .direnv 2024-12-18 22:56:30 +00:00
build.zig Make wrapping optional 2024-12-22 21:10:47 +00:00
build.zig.zon Add LICENSE, update README, set version to 1.0.0 2024-12-23 12:17:22 +00:00
flake.lock Add Zig flake template 2024-12-18 22:55:13 +00:00
flake.nix Add Zig flake template 2024-12-18 22:55:13 +00:00
LICENSE Add LICENSE, update README, set version to 1.0.0 2024-12-23 12:17:22 +00:00
README.md Add LICENSE, update README, set version to 1.0.0 2024-12-23 12:17:22 +00:00
treefmt.nix Add Zig flake template 2024-12-18 22:55:13 +00:00

Zig Brainfuck interpreter

A Brainfuck interpreter written in Zig

Build

Using Zig of course! Here are some examples of build commands:

# Build interpreter
zig build

# Run the tests
zig build test

# Disable value and pointer overflow wrapping
# If the value in the stack overflows, it will stay the same
# If the pointer to the stack overflows, it will panic and return an error
zig build -Dwrap_addr_overflow=false -Dwrap_val_overflow=false

# Non-debug build (debug build will return information about the stack on each Brainfuck call)
zig build -Doptimize=ReleaseFast

Usage

The interpreter takes any number of argument, each one can be a Brainfuck program. You can also pass a file with the -file parameter:

# Run an Hello world program
bf ">+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-]<.>+++++++++++[<++++++++>-]<-.--------.+++.------.--------.[-]>++++++++[<++++>-]<+.[-]++++++++++."

# Run the sierpinski example
bf -file examples/sierpinski.b

EOF can be sent with Ctrl+D on UNIX systems, Ctrl+Z then Enter on Windows systems.