В нём всего 8 символов
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 byte at the data pointer as an ASCII encoded character. |
| 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 |
| 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 |
Так что написание и отладка програм очень упрощаются - не надо знать сложный синтаксис, семантику и API
Вот пример “Hello world” на brainfuck
+++++ +++++ initialize counter (cell #0) to 10
[ use loop to set the next four cells to 70/100/30/10
> +++++ ++ add 7 to cell #1
> +++++ +++++ add 10 to cell #2
> +++ add 3 to cell #3
> + add 1 to cell #4
<<<< - decrement counter (cell #0)
]
> ++ . print 'H'
> + . print 'e'
+++++ ++ . print 'l'
. print 'l'
+++ . print 'o'
> ++ . print ' '
<< +++++ +++++ +++++ . print 'W'
> . print 'o'
+++ . print 'r'
----- - . print 'l'
----- --- . print 'd'
> + . print '!'
> . print '\n'
Это же можно переписать в строчку:
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
По этим линкам примеры программ:
http://www.muppetlabs.com/~breadbox/bf/
http://hackage.haskell.org/packages/archive/brainfuck/0.1/doc/html/Language-Brainfuck-Examples.html
http://stackoverflow.com/questions/4995624/source-for-simple-programs-in-brainfuck
А вот пузырьковая сортировка:
>>>>>,+}?<<<}?;
>>>,+?;
<<<}?>>>}?>>>}}?{{{{<<<?;
>>>}}}}?<<<}?>>}?<}?{{{{{{{<<?;
-.}?{?;
-?;
>>>?;
-<<<-<+>}}}}?{{{{>>?;
<?;
>>>+<<<-?;
>+>>>+<<<<-?;
>?;