Stacked Brainfuck

From Esolang
Jump to navigation Jump to search

This is brainfuck with the addition of a stack.

Commands

Stacked Brainfuck has the basic 8 commands.

The eight Basic language commands, each consisting of a single character:

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 byte at the pointer.
- Decrement (decrease by one) the byte at the pointer.
. Output the value of the byte at the pointer.
, Accept one byte of input, storing its value in the byte at the pointer.
[ Jump forward to the command after the corresponding ] if the byte at the pointer is zero.
] Jump back to the command after the corresponding [ if the byte at the pointer is nonzero.

There is also a ! command, which serves the usual function of separating code and data.

11 Additional stack manipulation commands.

Character Meaning
) Pushes the value at the current cell onto the stack
( Pops the value on the stack into the current cell (an empty stack pops zero into the cell)
@ Peeks the value on the stack, copying it into the current cell (without popping)
$ Drops the value on the stack (as if it was popped), but does not write it to the cell
= Current cell is set to the SUM between its value and the value on the top of the stack (peek)
_ current cell is set to the DIFFERENCE between its value and the value on the top of the stack (peek)
} Bitshifts the current cell value right by the value on the top of the stack (peek)
{ Bitshifts the current cell value left by the value on the top of the stack (peek)
| Current cell is set to the bitwise OR between its value and the value on the top of the stack (peek)
^ Current cell is set to the bitwise XOR between its value and the value on the top of the stack (peek)
& current cell is set to the bitwise AND between its value and the value on the top of the stack (peek)


Hello World

+>+++++)<{)>==+++.=---.$=++..+++.<.)>)>(<_$=+++.>.)+++.(---._---.<<+.!

Using preloaded data. (in reverse)

[)>]([.(]!!dlroW olleH

Implementation

In the given implementation there are 65536 cells, each consisting of a single unsigned byte. The initial cell is at zero. The start of the stack is at the last cell. They grow towards each other (per usual). Cell's wrap (255 + 1 = 0; 0 - 1 = 255). Attempting to decrement from the initial cell causes no decremention.

SBFCPP.cpp

Computational class

Stacked Brainfuck is obviously not Turing-complete, as it has bounded storage.

An alternative implementation to allow turing-completeness is to place the stack in negative cells below zero, or to separate it completely.