]> gitweb.factorcode.org Git - factor.git/blob - extra/brainfuck/brainfuck-docs.factor
Use factor.com to get stdout
[factor.git] / extra / brainfuck / brainfuck-docs.factor
1 ! Copyright (C) 2009 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3
4 USING: help.syntax help.markup brainfuck strings ;
5
6 IN: brainfuck
7
8 HELP: run-brainfuck
9 { $values { "code" string } }
10 { $description
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"
15     "\n"
16     "The eight language commands, each consisting of a single character, "
17     "are the following:\n"
18     { $table
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*." }
28     }
29     "\n"
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"
33     { $table
34         { { $strong "Character" } { $strong "C equivalent" } }
35         { ">" "++ptr;" }
36         { "<" "--ptr;" }
37         { "+" "++*ptr;" }
38         { "-" "--*ptr;" }
39         { "." "putchar(*ptr);" }
40         { "," "*ptr=getchar();" }
41         { "[" "while (*ptr) {" }
42         { "]" "}" }
43     }
44 } ;
45
46 HELP: get-brainfuck
47 { $values { "code" string } { "result" string } }
48 { $description "Returns the output from a brainfuck program as a result string." }
49 { $see-also run-brainfuck } ;