brainfuck-tut-0.6.0.1: A simple BF interpreter.

Copyright(c) Alejandro Cabrera, 2014
LicenseBSD-3
Maintainercpp.cabrera@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe-Inferred
LanguageHaskell2010

Language.Brainfuck.Eval

Description

 

Synopsis

Documentation

eval :: Tape -> String -> IO Tape Source

eval operates over the given tape, parses the string, and returns the state of the tape.

Potential unhandled errors:

  • Out of bounds access to the tape
  • Infinite loops
  • Exceptions thrown by print
  • Exceptions thrown by putChar

Handled errors:

  • Matching jump not found for '[' and ']': terminate eval and return tape

As a result of evaluating the BF program, the following instructions are effectful:

  • ',': pauses evaluation to receive user input
  • .: prints the tape contents at DP as a Char

Here's how eval might be called:

>>> let tape = listArray (0,99) (replicate 100 0)
>>> eval tape "+.+."
\1\2
>>> eval tape ",."
aa