Category:Brainf***: Difference between revisions

From Rosetta Code
Content added Content deleted
(Reasons for naming.)
(Added some more description of the BF language and made it more consistent.)
Line 1: Line 1:
{{language|Brainf***|bnf=http://ninh.nl/blog/2008/10/25/brainfck-birds-of-a-feather-session-take-2/}}Also known as '''Brainfuck''', but identified as '''Brainf***''' for reasons described [[Rosetta Code:Brainf***|here]]. Created by Urban Müller in 1993 in an attempt to create the world's smallest Turing-complete compiler. It is noted as an [[:Category:Esoteric_Languages|esoteric programming language]], as it is not ordinarily used for applications development, but it also noted as being a minimalist language.
{{language|Brainf***|bnf=http://ninh.nl/blog/2008/10/25/brainfck-birds-of-a-feather-session-take-2/}}Also known as '''Brainfuck''', but identified as '''Brainf***''' for reasons described [[Rosetta Code:Brainf***|here]]. Created by Urban Müller in 1993 in an attempt to create the world's smallest Turing-complete compiler. It is noted as an [[:Category:Esoteric_Languages|esoteric programming language]], as it is not ordinarily used for applications development, but it also noted as being a minimalist language.


The construct for the language is similar to a [[wp:Turing Machine|Turing Machine]]. The commands themselves act on an array or "tape" (usually a byte or integer array and usually "infinite" on one or both ends) and a pointer to a position in that array. The complete specification for the language can be summed up with the following eight symbols:
The construction of the language is similar to a [[wp:Turing Machine|Turing Machine]]. As with the [[wp:Turing Machine|Turing Machine]] Brainf*** is built from a finite state machine and an infinite tape of cells. Each cell can be any size, including unbounded, but is frequently an eight bit byte. The finite state machine is the program code with the program counter pointing at the current state. The strong similarity is one reason that a Brainf*** equivalent named ''Ρʺ'' was suitable for use by Corrado Böhm in 1964 to prove that structured programming using only ''while loops'' was just a powerful as ''goto spagetti'' programming.

The complete specification for the language (the available state transitions of the Turing machine) can be summed up with the following eight symbols:


{| class="wikitable"
{| class="wikitable"
Line 14: Line 16:
|-
|-
|style="text-align:center"|<tt>+</tt>
|style="text-align:center"|<tt>+</tt>
||increment (increase by one) the byte at the pointer.
||increment (increase by one) the cell at the pointer.
|-
|-
|style="text-align:center"|<tt>-</tt>
|style="text-align:center"|<tt>-</tt>
||decrement (decrease by one) the byte at the pointer.
||decrement (decrease by one) the cell at the pointer.
|-
|style="text-align:center"|<tt>.</tt>
||output the value of the byte at the pointer (usually interpreted to a character).
|-
|style="text-align:center"|<tt>,</tt>
||accept one byte of input (usually interpreted from a character), storing its value in the byte at the pointer.
|-
|-
|style="text-align:center"|<tt>[</tt>
|style="text-align:center"|<tt>[</tt>
||jump forward to the command after the corresponding <tt>]</tt> if the byte at the pointer is zero.
||jump forward to the command after the corresponding <tt>]</tt> if the cell at the pointer is zero.
|-
|-
|style="text-align:center"|<tt>]</tt>
|style="text-align:center"|<tt>]</tt>
||jump back to the command after the corresponding <tt>[</tt> if the byte at the pointer is nonzero.
||jump back to the command after the corresponding <tt>[</tt> if the cell at the pointer is nonzero.
|-
|style="text-align:center"|<tt>.</tt>
||output the value of the cell at the pointer as a character.
|-
|style="text-align:center"|<tt>,</tt>
||accept one character of input, storing its value in the cell at the pointer.
|}
|}


Alternatively, the <tt>]</tt> command may instead be translated as an unconditional jump '''to''' the corresponding <tt>[</tt> command, or vice versa; programs will behave the same but will run more slowly.
Alternatively, the <tt>]</tt> command may instead be translated as an unconditional jump '''to''' the corresponding <tt>[</tt> command, or vice versa; programs will behave the same but may run more slowly.


All other symbols, including traditional whitespace characters, are interpreted as comments.
All other symbols, including traditional whitespace characters, are interpreted as comments.
Line 38: Line 40:
Due to this minimal instruction set, Brainf*** is used as an introduction to compilers and has even been successfully implemented as a microprocessor core and the foundation to an operating system using a slightly extended syntax for output.
Due to this minimal instruction set, Brainf*** is used as an introduction to compilers and has even been successfully implemented as a microprocessor core and the foundation to an operating system using a slightly extended syntax for output.


The definition of the <tt>.</tt> and <tt>,</tt> in the above table still has some ambiguities due to the many ways of converting 'numbers' to 'characters'. Urban Müller's ''smallest compiler'' converted between characters and numbers using the ASCII character set. The newline character is number ''10'' and a end of file on input is signalled by the cell value being unchanged when the <tt>,</tt> command completes. The <tt>,</tt> command uses line editing and waits for for the return key to be pressed.
==See also==
==See also==
* [[RCBF]] - BF interpreters as a Rosetta Code task
* [[RCBF]] - BF interpreters as a Rosetta Code task

Revision as of 08:51, 29 April 2014

Language
Brainf***
This programming language may be used to instruct a computer to perform a task.
See Also:
Listed below are all of the tasks on Rosetta Code which have been solved using Brainf***.

Also known as Brainfuck, but identified as Brainf*** for reasons described here. Created by Urban Müller in 1993 in an attempt to create the world's smallest Turing-complete compiler. It is noted as an esoteric programming language, as it is not ordinarily used for applications development, but it also noted as being a minimalist language.

The construction of the language is similar to a Turing Machine. As with the Turing Machine Brainf*** is built from a finite state machine and an infinite tape of cells. Each cell can be any size, including unbounded, but is frequently an eight bit byte. The finite state machine is the program code with the program counter pointing at the current state. The strong similarity is one reason that a Brainf*** equivalent named Ρʺ was suitable for use by Corrado Böhm in 1964 to prove that structured programming using only while loops was just a powerful as goto spagetti programming.

The complete specification for the language (the available state transitions of the Turing machine) can be summed up with the following eight symbols:

Character Meaning
> increment the pointer (to point to the next cell to the right).
< decrement the pointer (to point to the next cell to the left).
+ increment (increase by one) the cell at the pointer.
- decrement (decrease by one) the cell at the pointer.
[ jump forward to the command after the corresponding ] if the cell at the pointer is zero.
] jump back to the command after the corresponding [ if the cell at the pointer is nonzero.
. output the value of the cell at the pointer as a character.
, accept one character of input, storing its value in the cell at the pointer.

Alternatively, the ] command may instead be translated as an unconditional jump to the corresponding [ command, or vice versa; programs will behave the same but may run more slowly.

All other symbols, including traditional whitespace characters, are interpreted as comments.

Due to this minimal instruction set, Brainf*** is used as an introduction to compilers and has even been successfully implemented as a microprocessor core and the foundation to an operating system using a slightly extended syntax for output.

The definition of the . and , in the above table still has some ambiguities due to the many ways of converting 'numbers' to 'characters'. Urban Müller's smallest compiler converted between characters and numbers using the ASCII character set. The newline character is number 10 and a end of file on input is signalled by the cell value being unchanged when the , command completes. The , command uses line editing and waits for for the return key to be pressed.

See also

  • RCBF - BF interpreters as a Rosetta Code task

Citations