brainfuck-tut: A simple BF interpreter.

[ bsd3, language, library, program ] [ Propose Tags ] [ Report a vulnerability ]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.5.1.0, 0.5.1.1, 0.5.1.2, 0.5.1.3, 0.6.0.0, 0.6.0.1, 0.7.0.0, 0.7.0.1, 0.7.0.2
Change log changelog.md
Dependencies array, base (>=4.7 && <5), brainfuck-tut [details]
License BSD-3-Clause
Copyright (c) 2016 Allele Dev
Author Allele Dev
Maintainer allele.dev@gmail.com
Category Language
Home page https://gitlab.com/queertypes/brainfuck-tut
Bug tracker https://gitlab.com/queertypes/brainfuck-tut/issues
Source repo head: git clone git clone https://gitlab.com/queertypes/brainfuck-tut.git
Uploaded by alleledev at 2016-12-30T18:00:38Z
Distributions NixOS:0.7.0.2
Reverse Dependencies 1 direct, 0 indirect [details]
Executables bfh
Downloads 7125 total (33 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2016-12-30 [all 1 reports]

Readme for brainfuck-tut-0.7.0.2

[back to package description]

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