Someone sent this to me and claimed it is a hello world in Brainfuck (and I hope so...)
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.
All the answers are thorough, but they lack one tiny detail: Printing.
In building your brainfuck translator, you also consider the character .
, this is actually what a printing statement looks like in brainfuck. So what your brainfuck translator should do is, whenever it encounters a .
character it prints the currently pointed byte.
Example:
suppose you have --> char *ptr = [0] [0] [0] [97] [0]
...
if this is a brainfuck statement: >>>.
your pointer should be moved 3 spaces to right landing at: [97]
, so now *ptr = 97
, after doing that your translator encounters a .
, it should then call
write(1, ptr, 1)
or any equivalent printing statement to print the currently pointed byte, which has the value 97 and the letter a
will then be printed on the std_output
.