p-nand-q.com | home | computer | humor | business | pictures | about

humor

programming languages

Brainfuck miscellanea

A brainfuck program has an implicit byte pointer, called "the pointer", which is free to move around within an array of 30000 bytes, initially all set to zero. There are some limitations in this version:

  1. The memory size is restricted to 10240 chars
  2. The sourcecode size is restricted to 1024 chars
  3. The memory is shared between all clients in the world that try to view this page. So, the memory might very well be garbled up to the point of complete nonsense and not be initially all set to zero.
  4. The ',' instruction (input from stdin) is not supported for obvious reasons.

Vaguely inappropriate implementations

I wrote a standalone python interpreter and a slightly obfuscated C/C++ version.

CGI Brainfuck

I wrote a Python-based, MySQL-powered CGI Interpreter for the Brainfuck language. Please enter the sourcecode to execute:



Minimalistic Brainfuck

In the following sections I will introduce BFmin1 and BFmin2, two minimal versions of Brainfuck. Lets first do a short recap of the original brainfuck syntax:

Of these, I think you can eliminate the '-' because if you increment long enough, you get an overflow, so its just a matter of how many '+'s you write until you get -1.

Next, eliminate '<' for the same reason: the memory pointer is an address, which is an integer, which can be decrement by ingenious use of overflow.

Next, I think the language should still be complete for all practical reasons one could ask for if it had just one of the two loop constructs; so lets eliminate ']'. The '[' needs to change its semantics (see below).

Next, I think I/O is no essential feature for practical completeness and or usefullness in daily life, because one could encode the input data in the source, and require the output data be the content of the memory after program execution. (Much like, when you take first steps in assembler, you look in memory to see the output of your program).

BFmin1

So, lets all give a warm welcome to BFmin1, the language with the following syntax elements:

There are exactly 2000 memory cells, so writing + 1999 times will result in a -1.

You can download

BFmin2

Because BFmin1 programs are so large, I've written a second version that uses an optimized syntax: its line oriented, and after each command you specify the repeat count; so e.g. '> 1999' means 1999 copies of '>'. You can download