less_retarded_wiki/brainfuck.md
Miloslav Ciz 36aa02f6d9 Update
2021-11-21 10:54:23 -06:00

2.3 KiB
Raw Blame History

Brainfuck

Brainfuck is an extremely simple, untyped esoteric programming language; simple by its specification (consisting only of 8 commands) but intentionally very hard to program in. It works similarly to a pure Turing machine. In a way it is kind of beautiful by its simplicity. It is very easy to write your own brainfuck interpreter.

There exist self-hosted brainfuck interpreters which is pretty fucked up.

The language is based on a 1964 language P´´ which was published in a mathematical paper; it is very similar to brainfuck except for having no I/O.

Brainfuck has seen tremendous success in the esolang community as the lowest common denominator language: just as mathematicians use Turing machines in proofs, esolang programmers use brainfuck in similar ways -- many esolangs just compile to brainfuck or use brainfuck in proofs of Turing completeness etc. This is thanks to brainfuck being an actual, implemented and working language reflecting real computers, not just a highly abstract mathematical model with many different variants. For example if one wants to encode a program as an integer number, we can simply take the binary representation of the program's brainfuck implementation.

In LRS program brainfuck may be seriously used as a super simple scripting language.

Specification

The "vanilla" brainfuck operates as follows:

We have a linear memory of cells and a data pointer which initially points to the 0th cell. The size and count of the cells is implementation-defined, but usually a cell is 8 bits wide and there is at least 30000 cells.

A program consists of these possible commands:

  • +: increment the data cell under data pointer
  • -: decrement the data cell under data pointer
  • >: move the data pointer to the right
  • <: move the data pointer to the left
  • [: jump after corresponding ] if value under data pointer is zero
  • ]: jump after corresponding [ if value under data pointer is zero
  • .: output value under data pointer as an ASCII character
  • ,: read value and store it to the cell under data pointer

Variations

TODO