Skip to content
nbozidarevicPublic

About

c2bf transpiles a C subset to Brainfuck — dependency-free Rust core, with a C ABI and a WebAssembly demo.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

387 Commits

Folders and files

Repository files navigation

c2bf

c2bf transpiles a C subset to Brainfuck — and, as helpers around that, runs Brainfuck programs and pretty-prints Brainfuck code.

Quick start

> 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.

Commands

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

Embedding

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.

Tests

> 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

What it accepts

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/).

About

c2bf transpiles a C subset to Brainfuck — dependency-free Rust core, with a C ABI and a WebAssembly demo.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages