Simple Brainfuck parser that reads text file or stdin and prints out the byte value or ASCII character.
- Install Ocaml and OPAM
- Compile to use in another Ocaml project:
$ ocamlc -c brainfuck.mli; ocamlopt -c brainfuck.ml
sample.bf:
Below calculates 100
+++++ [ > +++++ +++++ < - ] > .
run as a command line tool:
# Prints '100'.
$ ocaml brainfuck.ml sample.bf -fmt integer
$ echo '++++ [> +++++ +++++ < - ] > .' | ocaml brainfuck.ml -fmt integer
Leave out -fmt
option to print out ASCII characters as a default.
hello.txt
> +++++++ [ > +++++ +++++ < - ] > ++ .
> +++++ +++++ [ > +++++ +++++ < - ] > + .
> +++++ +++++ [ > +++++ +++++ + < - ] > -- .
> +++++ +++++ [ > +++++ +++++ + < - ] > -- .
> +++++ +++++ [ > +++++ +++++ + < - ] > + .
# Prints 'Hello'.
$ ocaml brainfuck.ml hello.txt
To use in another Ocaml project:
Brainfuck.interpret "++++ [ > +++++ +++++ < - ] > ."