Skip to content

Latest commit

 

History

History
66 lines (37 loc) · 1023 Bytes

README.md

File metadata and controls

66 lines (37 loc) · 1023 Bytes

ml-brainfuck

Simple Brainfuck parser that reads text file or stdin and prints out the byte value or ASCII character.

Setup

  • Install Ocaml and OPAM
  • Compile to use in another Ocaml project:
$ ocamlc -c brainfuck.mli; ocamlopt -c brainfuck.ml

Usage

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 "++++ [ > +++++ +++++ < - ] > ."