1 ! Copyright (C) 2009 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
4 USING: help.syntax help.markup brainfuck strings ;
9 { $values { "code" string } }
11 "A brainfuck program is a sequence of eight commands that are "
12 "executed sequentially. An instruction pointer begins at the first "
13 "command, and each command is executed until the program terminates "
14 "when the instruction pointer moves beyond the last command.\n"
16 "The eight language commands, each consisting of a single character, "
17 "are the following:\n"
19 { { $strong "Character" } { $strong "Meaning" } }
20 { ">" "increment the data pointer (to point to the next cell to the right)." }
21 { "<" "decrement the data pointer (to point to the next cell to the left)." }
22 { "+" "increment (increase by one) the byte at the data pointer." }
23 { "-" "decrement (decrease by one) the byte at the data pointer." }
24 { "." "output the value of the byte at the data pointer." }
25 { "," "accept one byte of input, storing its value in the byte at the data pointer." }
26 { "[" "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*." }
27 { "]" "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*." }
30 "Brainfuck programs can be translated into C using the following "
31 "substitutions, assuming ptr is of type unsigned char* and has been "
32 "initialized to point to an array of zeroed bytes:\n"
34 { { $strong "Character" } { $strong "C equivalent" } }
39 { "." "putchar(*ptr);" }
40 { "," "*ptr=getchar();" }
41 { "[" "while (*ptr) {" }
47 { $values { "code" string } { "result" string } }
48 { $description "Returns the output from a brainfuck program as a result string." }
49 { $see-also run-brainfuck } ;