Home

Welcome to BrainFK web-app.
Designed to put your think tank to full throtle and have you pondering for a long time.

Test your logic without having to learn a lot.

Introduction

BrainFK is designed to challenge and amuse programmers and has little practical use. It was created with the intention of designing a language which could be implemented with the smallest possible compiler. A BrainFK program is a sequence of these commands, possibly interspersed with other characters (which are ignored). The commands are executed sequentially, an instruction pointer begins at the first command, and each command it points to is executed. The program terminates when the instruction pointer moves past the last command.

The BrainFK language uses a simple machine model consisting of the program and instruction pointer, as well as a tape of infinite (to the right) byte cells initialized to zero; a movable data pointer (initialized to point to the leftmost byte of the tape); and two streams of bytes for input and output (most often connected to a keyboard and a monitor respectively, and using the ASCII character encoding).

Commands

The nine commands, each consisting of a single character, are the following:


Character Meaning
> increment the data pointer (to point to the next cell to the right).
< decrement the data pointer (to point to the next cell to the left).
+ increment (increase by one) the byte at the data pointer.
- decrement (decrease by one) the byte at the data pointer.
. output the ASCII equivalent character of the byte at the data pointer.
# output the integer value of the byte at the data pointer.
, accept one byte of input, storing its value in the byte at the data pointer.
[ if the byte at the data pointer is zero, then instead of moving the instruction pointer forward to the next command, jump it forward to the command after the matching ] command*.
] if the byte at the data pointer is nonzero, then instead of moving the instruction pointer forward to the next command, jump it back to the command after the matching [ command*.

*[ and ] match as parentheses usually do: each [ matches exactly one ] and vice versa, the [ comes first, and there can be no unmatched [ or ] between the two.

examples

Hello World!


The following program prints "Hello World!" and a newline to the screen:

 
©2010 - EiNSTASOFT