Penguin
Note: You are viewing an old revision of this page. View the current version.

Brainf*ck

An interesting programming language. It is a very easy to learn language, but can get extremely confusing.

The language has 8 different constructs which following, and included is their purpose:

+
Increment the value of the current pointer by 1
-
Decrement the value of the current pointer by 1
.
Print the current value as a character to standard output stdout(3)
,
Read a value from standard input stdin(3)
>
Move to current pointer to the next address
<
Move to current pointer to the previous address
[
Start of a loop. This essentially is a while loop which will keep iterating until the referenced value equals zero. ie. while(!x) { }
]
End of the while loop. Anything between these two language constructs will get executed whilst the while loop executes.

As they say about Perl: There are many ways to skin a Camel This also holds true for Brainf*ck.

Standard Brainf*ck thinks of every variable as an integer with a range of 0 through to 255. A variable in Brainf*ck is used by the < and > instructions. For example, the code
  • +>++++<

would mean the following:

  • Increment the current variable by 2
  • Move to the next variable
  • Increment this variable by 4
  • Move to the previous variable

After this bit of code, the variable we are currently referencing has a value of 2, and the next variable has a value of 4.

Sample HelloWorld program

The basic program to display the functionality of a programming language. The text string "Hello World\n"

File: helloworld.bf

  • +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.
  • ++++++++++++++>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  • +++++++++++++++++++++++++++++++++++++++++++.+++++++..+++.>++++++++++++++
  • +++++++++++++++++.<<.>.+++.------.--------.

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

Notes

The language has the simple specification to ignore any character in the program source code which is not a valid language construct. This allows us to put comments in our code, as long as we make sure we do not accidentally use one of the language constructs in our comments.

GerwinVanDeSteeg is planning on writing his own Compiler and an Interpreter for this language sometime in the near future. There are some available already on the WorldWideWeb, to find one, try Google.


There is someone in my head,
and it is not me.

-- Pink Floyd, Brain damage