Program:
Runtime

About

Brainfuck is a minimal programming language which consists of 8 commands (< > + - [ ] . ,) and an instruction pointer which operates on a memory tape.
Detailed explanation can be viewed in the Wikipedia page.
A collection of program snippets are available at the Brainfuck archive.

Examples (click to load)

Implementation assumptions

There are a few implementation specific factors to designing a Brainfuck interpreter. Brainfucked implements the following design:

  • Cell size: Classical 1 byte operands. Essentially operates in the ASCII range of 0 to 255
  • Memory size: Memory tape expands infinitely to the right. Causes error on moving beyond the left
  • Wrapping: Memory values wrap at both extremes of ASCII range. 0 decrements to 255; 255 increments to 0
  • EOF behaviour: Will always prompt for input when there is no more to consume

Optimization

About the optional 'Minor optimization' in this interpreter: when enabled, the pre-processing fuses together multiple consecutive occurrences of the 4 operands < > + -
+++..---[[]],,>><< becomes 3+..3-[[]],,2>2<
Notice that the program now becomes a superset of Brainfuck language.
Speed savings are significant on time intensive programs like Mandelbrot (~20s compared to ~130s).