bf v1.4.0 Bf.Parser View Source

Parses brainfuck programs.

Examples

iex> Bf.Parser.parse("++++[-.]>--")
{:ok, [{:add, 4},
       {:loop, [{:add, -1}, {:write}]},
       {:move, 1},
       {:add, -2}]}

Link to this section Summary

Types

All possible brainfuck instructions

A list of brainfuck instructions

Functions

Parses a brainfuck program into and returns a list of instructions

Link to this section Types

Link to this type instruction() View Source
instruction() ::
  {:add, integer()}
  | {:move, integer()}
  | {:set, integer()}
  | {:scan, integer()}
  | {:read}
  | {:write}
  | {:loop, program()}

All possible brainfuck instructions.

A list of brainfuck instructions.

Link to this section Functions

Link to this function parse(source) View Source
parse(String.t()) :: {:ok, program()} | {:error, term()}

Parses a brainfuck program into and returns a list of instructions.

Examples

iex> "--[>--->->->++>-<<<<<-------]>--.>---------.>--..+++."
...> |> Bf.Parser.parse()
{:ok,
 [{:add, -2},
  {:loop,
   [move: 1, add: -3, move: 1, add: -1, move: 1, add: -1,
    move: 1, add: 2, move: 1, add: -1, move: -5, add: -7]},
  {:move, 1}, {:add, -2}, {:write}, {:move, 1}, {:add, -9},
  {:write}, {:move, 1}, {:add, -2}, {:write}, {:write},
  {:add, 3}, {:write}]}