Brainfuck a Turing-complete Programming Language 1/3

The brainfuck programming language is an esoteric programming language noted for its extreme minimalism. It implements a Turing-complete language.
brainfuck was created in 1993 by Urban Müller with the intention of designing a language which could be implemented with the smallest possible compiler.
The language consists of eight commands:

CmdEffect
+Increases element under pointer
Decrases element under pointer
>Increases pointer
<Decreases pointer
[Starts loop, flag under pointer
]Indicates end of loop
.Outputs ASCII code under pointer
,Reads char and stores ASCII under ptr

The equivalent C notation for brainfuck “+” is the following:
++*ptr
It increments the current cell by 1,
The equivalent C notation for brainfuck “-” is the following:
–*ptr
It decrements the current cell by 1.
If you want to set a “B” char in the current cell of memory you shell increment the cell with 66 + (if the current cell value is 0). Now if you want to set the value of this cell to a “A” char you only need to add a “-“, the following example prints “BA”.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-.

The equivalent C notation for brainfuck “>” is the following:
++ptr
New current cell is the next cell
The equivalent C notation for brainfuck “<” is the following:
–ptr
New current cell is the prevoius one.
If you want to set the first ten cell to “1” you can do the following:
+>+>+>+>+>+>+>+>+>+
and now if you want to come back to the first cell you can do:
<<<<<<<<<<

The equivalent C notation for brainfuck “.” is

putchar(*ptr)

the equivalent C notation for brainfuck “,” is the following:

*ptr=getchar();

The “,” operator will be implemented in a next version of brainfucktory.

The equivalent C notation for brainfuck “[” and “]” is the following:

while(*ptr)
{
}

if you want to do the following:

i=10;
while(i){printf("%d",i); i--}

you can do:
++++++++++[.-]

Brainfuck Tools

There are a lot of tools for brainfuck on the internet, here you are a short list of the most interesting (for me) brainfuck tools.

Brainfucked

Brainfucked
The compiler features an advanced code-optimization and therefore programs created with Brainfucked are quite small. Brainfucked, of course, checks the syntax of brainfuck programs to catch common and possible errors before compiling. It is also capable of compiling programs written for many different platforms such as Windows, DOS, Linux, Unix or Mac OS X. Thus there’s virtually no brainfuck program, which Brainfucked can’t compile! Every program compiled with Brainfucked is executable under Windows and MS-DOS.
The download of Brainfucked includes the compiler itself, its source code, a readme with a brief summary of the brainfuck syntax and some brainfuck examples.

  • A short summary of some of the features of Brainfucked:
  • Brainfuck compiler for Windows and MS-DOS
  • Checks the syntax of brainfuck programs
  • Creates optimized machine code and small files
  • Supports brainfuck programs written for different platforms (Windows, DOS, Linux, Unix, Mac)
  • Creates space saving COM files
  • Needs just 799 bytes of space
  • Free and open source code. Brainfucked is Open Source!

brainfuck.tk

brainfuck.tk, features an interpreter for the Brainfuck programming language.

bfc

bfc is a Brainfuck compiler written in C. It compiles Brainfuck code into machine code in ELF format for Linux running on Intel or AMD microprocessor. It generates assembly code in AT&T format and then uses GNU as and GNU ld programs to assemble and link it to generate the ELF executable code.

awib

Awib is a brainfuck compiler written in brainfuck. It’s portable, optimising, polyglot and supports multiple target platforms.
Awib compiles brainfuck source code into well performing 386 Linux binaries, C code, Ruby code, Go code and Tcl code.
Awib is itself polyglot in brainfuck, C, bash and Tcl.

nbfc

nbfc is a new, completely portable compiler for the brainfuck programming language. It will generate and compile C code or as an option a Java application.
nbfc is quite different from the original brainfuck compiler by the language’s inventor Urban Mueller:

  • It’s portable. The original bfc was for the Amiga only. nbfc should run on any unix-like system.
  • It uses standard tools for its implementation and doesn’t try to obfuscate the code.
  • It can compile to C and supports the ”write once, run anywhere” concept with its capability to generate Java applications.

Java Brainfuck Compiler

Java Brainfuck Compiler is an optimising Brainfuck to Java bytecode compiler.
The Java Brainfuck Compiler is a compiler for the uniquely powerful Brainfuck language, which produces Java bytecode that will run on any Java Virtual Machine (with no intermediate steps such as going by way of Java code).

Brainfuck Machine

Brainfuck Machine is a Brainfuck IDE.
Main functions:

  • editor
  • interpreter
  • debugger (trace, run to cursor, look into memory)
  • compiler (using bfd compiler, you can compile source without saveing it to file)

Other features:

  • probably the fastest Brainfuck interpreter with GUI
  • converting code from Brainfuck to: C, Perl, Pascal, Delphi
  • removeing comments (and other chars) from source code (source code cleaning)
  • random BF code generating
  • you can set your own BF instructions (for example + => a, – => b, [ => c …)
  • configurable memory size
  • font setting
  • copying, saveing to file and clearing output window
  • after run, you can see: time of running, instructions moves
  • Brainfuck Machine has also ASCII table and a lot of source examples (from ROT13 coding to GameOfLive)

More tools

simple interpreter

Simple Brainfuck Interpreter
a simple interpreter with a BSD style license

brainfck01, a MS Windows interpreter

If you have written your own tool, please add a comment to this post.

Leave Comment

Your email address will not be published. Required fields are marked *