Bf interpreter

By Omar Essilfie-Quaye

Settings

Program

++++++++++ [ > + > +++ > +++++++ > ++++++++++ <<<< - ] >>> ++ . > + . +++++++ .. +++ . << ++ . > +++++++++++++++ . > . +++ . ------ . -------- .

Output

Github Repo Link to github repository Docs Link to source code documentation

Brainfuck - The language

Brainfuck is an esoteric programming language created by Urban Müller to be extremely minimalistic. It features only 8 commands but despite this is a Turing complete programming language. Whilst it is technically possible to write a program to solve a large series of problems, in practicality it is very difficult to write anything more than a toy. Frankly there has been a small wave of people implementing interpreters and compilers for the language and very few people writing anything substantial. Wilfred Hughes has an interesting article about this. I shall, as always, endeavour to be part of the problem!

Memory

Brain fuck operates on a simple memory model which has a consecutive series of cells that can store 8 bit numbers.This series of cells is usually known as a tape as a nod to early computing machines which used physical rolls of tape for memory. A pointer starts at the beginning of the tape and moves around according to the program instructions. The data at each cell location can be incremented or decremented.

Usual implementations have 30,000 cells in the tape. There are a series of edge cases that can be handled slightly differently depending on the implementation. These include: integer overflow, integer underflow, buffer overflow, buffer underflow. These can be handled by wrapping data or pointers back around to the beginning, infinitely expanding buffers or just crashing the program. The sensible choice depends on the features used by a given program to do computations.

Loops

Loops have the ability to do two things at once: they act as a means to repeat instructions, and they act as conditional checks. In brainfuck the open loop operator will go to the next instruction if the value at the current data cell is not zero, otherwise the execution jumps to the loop end.

Operators
  • + Increment Cell
  • - Decrement Cell
  • > Move Pointer Right
  • < Move Pointer Left
  • [ Loop Start
  • ] Loop End
  • . Output Cell (ASCII Char)
  • , Input To Cell

See Also

Whilst looking for inspiration for this project I found a few cool blog posts about other brainfuck implementations online. To make it easier for other people to find good resources I have left a few of the ones I really like linked below.