c2bf transpiles a C subset to Brainfuck — and, as helpers around
that, runs Brainfuck programs and pretty-prints Brainfuck code.
> cargo build --release --manifest-path rs/Cargo.toml
> ./rs/target/release/c2bf program.c -o program.bf
c2bf program.c (no command) compiles. Without -o, Brainfuck goes
to stdout; without a code file, source is read from stdin.
compile [file] [-o file] [-s] Transpile C source to Brainfuck (default)
check [file] Validate source, emitting nothing
run [file] [-i file] [-o file] Run a Brainfuck program
format [file] [-o file] [-m] Pretty-print Brainfuck (-m minifies)
help Show help
The code file may also be given as -c file. run requires a code
file; compile, check, and format fall back to stdin. Errors go
to stderr with usage; exit code is 1. compile -s (or --stats)
prints one BF bytes: N, cells: M line to stderr.
Run a transpiled program, feeding it input:
> ./rs/target/release/c2bf run -c program.bf -i input.txt
The core is a dependency-free Rust library. Adapters live outside it:
- C/C++: C ABI in rs/ffi/ (
c2bf.h,c2bf_compile/c2bf_run/c2bf_format). - Web: WebAssembly adapter in rs/wasm/ and the demo in demo/. Pages deploys automatically on pushes touching
demo/,rs/, or the Pages workflow (manual dispatch retained); see rs/wasm/README.md. No npm package will be published.
> cd tests && python3 test # oracle + golden suite (needs the build above)
Byte outputs are pinned under tests/golden/; regenerate them (with
review) after intentional changes:
> ./tests/golden/generate.sh
Only a C subset: int/char variables, arithmetic, comparisons,
logic, bitwise/shift, if/else, while/for/do...while, switch, break/continue,
functions, prototypes, typedef, enum, braced initializers, printf with %d/%c/%u/%o/%x/%X/%s/%%, scanf with %d/%u/%o/%x/%i/%c/%s, and more — see docs/semantics.md
for the ground-truth
behavior and tests/compile/ for examples. The original C++/ANTLR
implementation was retired after the Rust port matched it byte-for-byte
(see docs/decisions/).