Brainfuck But With Buffer
BBWB is a brainfuck derivative that adds a buffer between you and the memory tape. You can increment and decrement the buffer value, then overwrite the pointed cell with said buffer value. You can also load pointed cell value to the buffer, overwriting it. It also adds I/O differences: you can get or put buffer value as int or as ASCII char. The cell pointer wraps around (there is a fixed number of cells).
Commands
(for the C transpilation part, we assume you have this setup:
int buff = 0;int tape[CELLS] = {0};int ptr = 0;
and you've defined a CELLS constant
)
Command | Effect | C transpilation |
---|---|---|
+ |
Increment the buffer value | ++buff; if (buff>255) buff = 0;
|
- |
Decrement the buffer value | --buff; if (buff<0) buff = 255;
|
# |
Set the buffer value to zero | buff = 0;
|
^ |
Set the pointed cell to the buffer value | tape[ptr] = buff;
|
v |
Set the buffer value to the pointed cell | buff = tape[ptr];
|
< |
Decrement the cell pointer | ++ptr; if (ptr>=CELLS) ptr=0;
|
> |
Increment the cell pointer | --ptr; if (ptr<0) ptr = CELLS-1;
|
. |
Output the buffer value as an int | printf("%d", buff);
|
: |
Output the buffer value as an ASCII char | printf("%c", buff);
|
, |
Input an int to the buffer value | scanf("%d", &buff);
|
; |
Input a char and set the buffer value to the char's ASCII value | scanf("%c", &buff);
|
[ |
Jump past the matching ] if the pointed cell is 0 |
while tape[ptr] {
|
] |
Jump back to the matching [ if the pointed cell is nonzero |
}
|
@ |
Print tape (for debugging purposes) |
Examples
Hello, world!
+++++++++^#[>v++++++++^#<v-^#]>v: print H # clear +++++++++++++++++++++++^#[>v+++^#<v-^#]>v: print E (a bit inefficent) # +++++++++++++++++++^#[>v++++^#<v-^#]>v: : print LL # ++++++++++^#[>v++++++++^#<v-^#]>v-: print O (80 minus 1 easier than 79) # +++++++++++^#[>v++++^#<v-^#]>v: print comma # ++++++++^#[>v++++^#<v-^#]>v: print space # +++++++++++^#[>v++++++++^#<v-^#]>v-: print W (same trick as O 88 minus 1 easier than 87) # ++++++++++^#[>v++++++++^#<v-^#]>v-: print O # ++++++++++^#[>v++++++++^#<v-^#]>v++: print R (80 plus 2 easier than 82) # +++++++++++++++++++^#[>v++++^#<v-^#]>v: print L # +++++++++++++++++^#[>v++++^#<v-^#]>v: print D # +++++++++++^#[>v+++^#<v-^#]>v: print ! # ++++++++++: print newline
Truth Machine
The truth machine in BBWB is surprisingly simple:
,^.[.]
Let's see it with comments
, get integer input ^ load to cell0 . print buffer [.] while selected cell print buffer
External resources
More info on the github page here: https://github.com/umanochiocciola/bbwb
Text Converter: https://github.com/umanochiocciola/bbwb-text-generator