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, ornullfor EOF.output_callback: function called ascallback(character, byte)for each.command.eof: one ofzero,minus-one, orunchanged; defaults tozero.tape_size: positive integer maximum cell count; defaults to30000.cell_size: positive integer wrapping modulus; defaults to256.
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: selectzero,minus-one, orunchanged.--tape-size N: set maximum tape cells.--cell-size N: set cell wrapping modulus.-h, --help: show usage.