lang-brainfzck

lang-brainfzck-0.0.3 by tobyink

Parse and run Brainfuck programs

Download .tar.gz

Package

Name
lang-brainfzck
Version
0.0.3
Uploaded
2026-06-12 23:10:45
Repository
https://github.com/tobyink/zuzu-lang-brainfzck
Dependencies
Metadata
zuzu-distribution.json
Archive
Download .tar.gz
JSON-LD-logo-88

lang/brainfzck

Parse and run Brainf*ck programs from ZuzuScript.

This trial distribution provides a small pure-Zuzu Brainf*ck virtual machine. It ignores non-command characters, checks bracket pairing before execution, uses wrapping byte cells by default, and supports callback-based input and output for embedding.

The distribution contains:

  • modules/lang/brainfzck.zzm: compiler, program object, and interpreter.
  • scripts/brainfzck: command-line Brainf*ck runner.
  • tests/lang/brainfzck.zzs: interpreter and compiler tests.
  • tests/runner.zzs: author-only command-line runner test.

The distribution is licensed under the Artistic License 1.0 or the GNU General Public License version 2. See LICENCE.

Module API

from lang/brainfzck import brainfzck, compile_brainfzck;

say( brainfzck("++++++++[>++++++++<-]>+.") );  // A

let program := compile_brainfzck(",+.");
say( program.run( { input: "A" } ) );  // B

brainfzck(source, options?) compiles and runs source, returning the captured output string unless options{output_callback} is supplied.

compile_brainfzck(source, source_name?) returns a BrainfzckProgram. source_name is used in syntax errors and defaults to <string>.

BrainfzckProgram.run(options?) accepts:

  • input: input string consumed by ,.
  • input_callback: function called when input is needed. It may return a one-character string, a byte number, or null for EOF.
  • output_callback: function called as callback(character, byte) for each . command.
  • eof: one of zero, minus-one, or unchanged; defaults to zero.
  • tape_size: positive integer maximum cell count; defaults to 30000.
  • cell_size: positive integer wrapping modulus; defaults to 256.

BrainfzckSyntaxError reports unmatched brackets during compilation. BrainfzckRuntimeError reports pointer and option errors during execution.

Runner

scripts/brainfzck is executable:

brainfzck hello.bf
brainfzck -e '++++++++[>++++++++<-]>+.'
brainfzck program.bf < input.txt

Options:

  • -e, --eval SOURCE: run source supplied on the command line.
  • -o, --output FILE: write output to a file instead of STDOUT.
  • --eof MODE: select zero, minus-one, or unchanged.
  • --tape-size N: set maximum tape cells.
  • --cell-size N: set cell wrapping modulus.
  • -h, --help: show usage.

Installation

If you have zuzuzoo installed, you can install the latest release of lang-brainfzck using this command:

zuzuzoo install lang/brainfzck

Documentation