There are only 8 characters in the language. Each operates on a 'tape' or sequence of integers, usually with 30000 units allocated all set to zero.
Say 'p' is a char* pointing to sequence of N bytes all set to zero. The characters of the language do the following.
">": would be ++p it would increment the current location in the sequence
"<": would be --p the exact opposite of the above
"+": would be ++*p which would increment the value stored at the current location
"-": would be --*p which would decrement the value stored at the current location
".": would be putchar(*p) which would print the current character
",": would be *p = getchar() which would read in data from the input stream
"[": would be kinda like the beginning of a while loop, like while(*p) { it has to be matched by a "]" character that ends the loop.
"]": would be like the closing brace of a loop } so that it must be matched with "[" before it
For any confusions please see this Wikipedia page on the matter.
There are many ways to implement this. You could interpret it pretty easily. You could translate it to another language like C or C++ and use that to compile it. You could make a full fledged compiler or JIT the code even!
It would be neat to add extensions to the language even. Esolang has a whole category for brainfuck derivatives, here.
I'm eager to see what you create
edit:
also, If you would like to check your work against another interpreter, Curtis Rutland wrote this a while back for his C# brainf*** challenge.
there are also a number of interesting scripts here to work with including a quine(prints it's own source code), a prime number sieve, and 99 bottles of bear on the wall.
This post has been edited by ishkabible: 21 March 2012 - 05:00 PM

New Topic/Question
Reply






MultiQuote










|