A simple BF interpreter. https://gitlab.com/queertypes/brainfuck-tut
|Latest on Hackage:||0.7.0.2|
This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.
Brainfuck: A Toy Implementation
This project exists to show what a Brainfuck evaluator might look like in Haskell.
The implementation is fairly well documented. I endeavored to make it readable.
Below is the abstract syntax tree for the BF language as implemented:
data Term = IncDP -- > | DecDP -- < | OutDP -- ? | IncByte -- + | DecByte -- - | OutByte -- . | InByte -- , | JumpForward -- [ | JumpBackward -- ] deriving (Show, Eq)
I followed the summary given on the wikipedia page closely. A few particulars to this implementation:
- "Jump not found" errors abort evaluation and return the state of the tape
- Out of bound errors are not detected
- Evaluation proceeds until the instruction stream runs out
An executable is provided:
$ cabal build bfh $ cabal run bfh usage: bfh <size> <program> $ cabal run bfh 10 ',.' a<enter> a
- added support for '?' command
- this breaks compatibility with programs that use ? as a comment character
update the changelog
fix: jump logic now respects nesting
Add homepage, issue tracker, project repo
Fix documentation formatting issues
- Initial release