BrainRelax Development
The BrainRelax Code Generator translates code from the BrainFuck programming language to various languages, such as C, TCL, PHP, Pascal, Python, etc.

The br gets as input the target language configuration file.
A typical tl file is this:

# BF 2 C Rules

char a[99999];
PointerIncr: p+=BFNUM;
PointerDecr: p-=BFNUM;
ValueIncr: (*p)+=BFNUM;
ValueDecr: (*p)-=BFNUM;
ReadChar: *p=getchar();
WriteChar: putchar(*p);
WhileStart: while(*p){
WhileEnd: }
Footer: exit(0);}


This is a BF to C target language configuration file This file defines the rules of how we'll translate from BrainFuck to the C language.
BF has these operations:
Increment or Decrement by one the current memory address
Increment or decrement by one the value of the current memory address
Read a byte and place it to the current memory address
Print the character that its ascii value is at the current memory address
Run a while loop until the value at the current memory address gets zero.

So, according to these basic instruction set, we need to define the syntax that the target language uses to describe these instructions.
The configuration file has these sections:
Header: xxxxxxxxx
In the Header section we define the initializations and the headings that our target language might need. There are two different ways of defining it: The first is the common syntax that we use in all sections:
Header: xxxxxx
for one line headers,i the header is whatever is defined in the same line.
the second is:
for multiple line headers, the header is whatever defined in the lines between
the two tags.
Some of the initializations in the header might be the memory allocation for the BF's memory stack, as well as the iterator for the memory block (where needed).

Footer: the footer of the target code
PointerIncr: The statement used to move up to a memory block by BFNUM bytes.
PointerDecr: The statement used to move down to a memory block by BFNUM bytes.
ValueIncr: The statement used to add BFNUM to the value of the current memory address.
ValueDecr: The statement used to substract BFNUM to the value of the current memory address.
ReadChar: the statement used to read a number to the current memory address
WriteChar: the statement used to print the ascii character of the memory address
WhileStart: the statement used to open a "while (value_of_current_memory >0)" statement
WhileEnd: the statement used to close a while statement

all white lines or lines starting with # are ignored

How to Run:

For example, in order to translate the sample hello.b (HelloWorld) BF programm to C, type:

cat hello.b | ./br ./tl/ > hello.c
gcc -o helloc hello.c

If you want to write your own tl file for some other programming language and you think that the current tl format needs some enhancements, email me at

      BrainRelax Sourceforge

   Last Updated: 23 July 2001.