The pbrain programming language is an extension of the brainfuck programming language that adds support for procedures. This is done with the addition of the instructions :, (, and ) to the existing brainfuck instructions. pbrain was created by Paul M. Parks in 2004.
A procedure is delimited by the ( and ) instructions. It's assigned a numeric identifier equal to the contents of the active cell at the time the ( is encountered. For example, the following pbrain program creates a procedure numbered "1" that will increment the active cell and move one cell to the right:
To call this procedure, the active cell is set to 1 and the procedure is called with the : instruction. Assuming the current cell is zero, the following will call the above procedure:
While pbrain adds procedures, the procedure that is called depends on the value in a cell which can change during execution. This means that one cannot always determine which procedure is being called just by reading the code. The code must be executed to determine the cell value and therefore called procedure. This is a disadvantage for code conversion but an advantage for obfuscation. For named procedures, see Toadskin.
Tbrain is an extension of the Pbrain programming language. In addition to procedure calls it also adds the option to call procedures on a new thread using ; and to join all threads active of a specific procedure using \. Every thread has its own memory pointer, but the memory itself is shared between threads. The following Tbrain program prints "Hello World" 4 times and waits for all threads to finish before exiting.
- A C++ interpreter and a C# compiler for Microsoft .NET may be found at http://www.parkscomputing.com/applications/pbrain/.
- Brainfuck Developer, a comprehensive Brainfuck IDE for Windows, supports pbrain.
- A concise interpreter in C is available at http://www.hevanet.com/cristofd/pbrain.c. I have tried to complete the semantics the cleanest way I could.
- weave.rb is a pbrain interpreter (with -p) in Ruby that optionally includes Weave and Brainfork threading.
- BrainFry is a Brainfuck interpreter command line tool and library with Pbrain and Tbrain support.