brainfuck-tut

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.

BSD3 licensed by Allele Dev
Maintained by allele.dev@gmail.com

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.

Terms

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)

Evaluation Semantics

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

Executable

An executable is provided:

$ cabal build bfh
$ cabal run bfh
usage: bfh <size> <program>
$ cabal run bfh 10 ',.'
a<enter>
a

Changes

0.7.0.0

  • added support for '?' command
    • this breaks compatibility with programs that use ? as a comment character

0.6.0.1

  • update the changelog

0.6.0.0

  • fix: jump logic now respects nesting

0.5.1.3

  • Add changelog

0.5.1.2

  • Add homepage, issue tracker, project repo

0.5.1.1

  • Fix documentation formatting issues

0.5.1.0

  • Initial release
Depends on:
Used by 1 package:
comments powered byDisqus