BF+BF
BF+BF is an esoteric programming language invented by the user (User:IAM) as a combination of Befunge and Brainfuck Extended Type I.
Concept
BF+BF inherits from its brainfuck ancestry a portion of commands and the tape-like memory, while relying on a two-dimensional layout of ASCII characters in the vein of Befunge, as well as a select subset of its instructions. The brainfuck side is expanded into two axes as well, mimicking in this data grid the instruction topology without, however, introducing any correlation.
Terminology
Code array: A two-dimensional array where the code is stored. Its origin is located at the top-left corner (0, 0). It expands infinitely to the right and bottom.
Data array: A two-dimensional array where the data is stored. Its origin is located at the top-left corner (0, 0). It expands infinitely to the right and bottom.
Instruction pointer: A pointer pointing at an item of the code array and having a direction.
Data pointer: A pointer pointing at an item of the data array, used to indicate which cell is being used currently.
Architecture
The data management is based upon two components: a data grid and a scalar storage.
The data grid describes a matrix of integer numbers, the extent of which to the right and bottom is unrestrained. Attempts to move beyond the other limits, however, will incite an error. A data pointer operates on this grid, marking at any time a single cell as selected. Several commands for its navigation, access, and manipulation exist.
An additional scalar integer value, called the storage, can be utilized to avail in performing certain operations, in particular logical ones, in cooperation with the active grid cell.
Execution
The execution of a BF+BF program begins with the instruction pointer in the top left corner (0, 0) of the code grid, oriented to the right. Each tick, the instruction pointer executes the instruction below it and moves one space in the direction of its orientation. If the instruction pointer trys to move out of the code array, an error is signaled.
Commands
BF+BF combines instructions from both of its ancestors, as indicated by the following aperçu:
Character | Meaning |
---|---|
>
|
Moves the data pointer one cell to the right. |
<
|
Moves the data pointer one cell to the left. |
A
|
Moves the data pointer one cell up. |
v or V
|
Moves the data pointer one cell down. |
+
|
Increments the cell under the data pointer. |
-
|
Decrements the cell under the data pointer. |
.
|
Outputs the contents of the cell under the data pointer. |
,
|
Prompts from the user a character and stores its byte value in the cell under the data pointer. |
[
|
Scan for a ] in the direction that the instruction pointer is moving. [ s and ] s can be nested. If it is not found, there is an error. Then jump to the command after the ] if the contents of the current cell is zero.
|
]
|
Jumps to the command after the matching [ if the curremt cell is nonzero.
|
$
|
Sets the value in the storage (like BF Extended Type I) to the value under the data pointer. |
!
|
Sets the value under the data pointer to the value in storage. |
}
|
Performs a single right logical shift of the byte at the pointer. |
{
|
Performs a single left logical shift of the byte at the data pointer. |
~
|
Sets the value under the data pointer to its bitwise NOT value. |
^
|
Sets the value under the data pointer to its value bitwise XOR-combined with the storage byte. |
&
|
Sets the value under the data pointer to its value bitwise AND-combined with the storage byte. |
|
|
Sets the value under the data pointer to its value bitwise OR-combined with the storage byte. |
0 to 9
|
Sets the cell under the data pointer to the respective number. |
U
|
Sets the instruction pointer direction to up. |
D
|
Sets the instruction pointer direction to down. |
L
|
Sets the instruction pointer direction to left. |
R
|
Sets the instruction pointer direction to right. |
@
|
Ends the program. |
Examples
Hello, World!
v8[>4[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]D > D.------.+++.<.-<.>>.+++..+++++++.--->.>L R--------.>>+.>++.@
Infinite cat program
This solution to the continuously repeating cat program employs the warklooms inherent to brainfuck: a jumping via the commands [
and ]
:
1[,.1]@
An alternative solution — at least conceptually equivalent — harnesses the topological and navigational capabilities of BF+BF to visually express an infinitely operating cat program:
R,.D . , , . U.,L
Interpreter
- Common Lisp implementation of the BF+BF programming language.