Copyright | (c) Sebastian Galkin, 2014 |
---|---|
License | MIT |
Maintainer | paraseba@gmail.com |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
This module exports functions that allow to evaluate a BrainFuck program.
Evaluation supports two types of error, parsing and execution, by returning
instances of EvalResult
This module should be all library users need to import.
- eval :: Monad m => Machine m -> Program -> m (Either BFExError BFTape)
- evalBS :: Monad m => Machine m -> ByteString -> m EvalResult
- evalStr :: Monad m => Machine m -> String -> m EvalResult
- data EvalResult
- data Machine m = Machine {}
- defaultIOMachine :: Machine IO
- simulatorMachine :: Machine (State SimState)
- data SimState = SimState [Int8] [Int8]
- simStateOutput :: SimState -> [Int8]
- emptyState :: SimState
- module HaskBF.Tape
- module HaskBF.Parser
Documentation
:: Monad m | |
=> Machine m | The machine used to do I/O |
-> ByteString | The code to evaluate |
-> m EvalResult | Parsing/evaluation result |
Evaluate an unparsed BrainFuck program using I/O provided by the given
- Machine
-
- The result is returned as an EvalResult
:: Monad m | |
=> Machine m | The machine used to do I/O |
-> String | The code to evaluate |
-> m EvalResult | Parsing/evaluation result |
Evaluate an unparsed BrainFuck program using I/O provided by the given
- Machine
-
- The result is returned as an EvalResult
data EvalResult Source
Evaluation result of an unparsed BrainFuck program
EvalSuccess BFTape | Parsing and evaluation were successful. The resulting - state of the tape after the last instruction - was executed. |
EvalExecError BFExError | The program was parsed successfully but evaluation - failed. - The reason for failure is overflowing a limit of the tape. - The state of the tape before the error is included |
EvalParseError ParseError | The program can not be parsed. Parsing error message is - included |
Underlying input output for the evaluation machine. Changing the monad m
- achives different results. For instance using the IO
monad an evaluator can
- be created that does inputoutput to stdinstdout. If the monad is State
,
- for instance, input/output can happen in memory.
-
- We offer two implementations of Machine
:
-
- * defaultIOMachine
: under the IO
monad, does input/output using the
- standard streams
- * simulatorMachine
: under the State
monad, does input/output on lists
-
- It's easy to create other Machine
s by using different monads and
- functions.
State used by simulatorMachine
to evaluate code under the State
monad
-
- It maintains input and output bytes inside lists
simStateOutput :: SimState -> [Int8] Source
Extract the output stream from a simulatorMachine
state
Initial simulatorMachine
state
module HaskBF.Tape
module HaskBF.Parser