BrainFuck

Last edit

Summary: Rework for clarity and accuracy.

Changed: 1,2c1,2

< BrainFuck is a really simple programming language.
< So simple in fact, that compilers of size under 300 bytes exist.

to

> Brainfuck is a really simple programming language.
> So simple, in fact, that compilers of size under 150 bytes exist.

Changed: 7,8c7,10

< + increments
< - decrements

to

> Assume an array of 30,000 cells initialized to 0, and a pointer at left.
>
> + increments a cell
> - decrements a cell

Changed: 10,13c12,14

< . does output
< , does input
< [ ] is a loop
< Assume a 30000 array of 0-initialized cells.

to

> . does ASCII output
> , does ASCII input
> [ ] loop until cell is zero

Changed: 15,17c16,18

< +++.
< This increments the first cell to 3, and then prints it, resulting in ^C.
< Here is how to print "Emacs":

to

> +++++++++++++++++++++++++++++++++.
> This increments the first cell to 33, and then prints it, resulting in a '!'.
> Here is one way to print "Emacs":

Changed: 24,25c25

< This works as follows: [ checks if the current cell is 0, if not it
< executes the loop content...

to

> This works as follows: [ checks if the current cell is 0, and if so it skips the loop contents. ] checks if the current cell is 0, and if not it repeats the loop contents.

Added: 27a28,29

> * http://home.wxs.nl/~faase009/Ha_BF.html
> * http://www.hevanet.com/cristofd/brainfuck/brainfuck.html


Brainfuck is a really simple programming language. So simple, in fact, that compilers of size under 150 bytes exist. Needless to say, this language is totally useless in real life. Some people still like to play around with it. And Emacs has a BrainFuckInterpreter, of course.

Executive Summary

 Assume an array of 30,000 cells initialized to 0, and a pointer at left.
 
 + increments a cell
 - decrements a cell
 < and > move the pointer
 . does ASCII output
 , does ASCII input
 [ ] loop until cell is zero

A very simple program:

 +++++++++++++++++++++++++++++++++.

This increments the first cell to 33, and then prints it, resulting in a ‘!’.

Here is one way to print “Emacs”:

 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.
 ++++++++++++++++++++++++++++++++++++++++.------------.++.++++++++++++++++.

The simplest loop here sets a cell to 0:

 [-]

This works as follows: [ checks if the current cell is 0, and if so it skips the loop contents. ] checks if the current cell is 0, and if not it repeats the loop contents.

For more info about the language itself, see:


What about bfemacs, an emacs with EmacsLisp replaced by BrainFuck ? --JeanPhilippeTheberge


CategoryHumor