Brainfuck^

From Esolang
Jump to navigation Jump to search

Brainfuck^ by User:Password is vanilla brainfuck with a few additional commands, more specifically the additional commands are pointer versions of the existing ones.

As a refresher, the standard commands are:

Command Description
> Move the pointer to the right
< Move the pointer to the left
+ Increment the memory cell under the pointer
- Decrement the memory cell under the pointer
. Output the character signified by the cell at the pointer
, Input a character and store it in the cell at the pointer
[ Jump past the matching ] if the cell under the pointer is 0
] Jump back to the matching [ if the cell under the pointer is nonzero

and the extended commands are:

Command Description
} Increment the memory cell which the current cell refers to
{ Decrement the memory cell which the current cell refers to
( Jump past the matching ) if the cell which the current cell points to is 0
) Jump back to the matching ( if the cell which the current cell points to is nonzero

Examples

Here's a list of some basic programs.

If you set memory like this ( |n| denotes the pointer position, the first address is zero always )

>+>+>+>+>+>+>+>+>+>+<<<<<<<<<<
|0| 1 1 1 1 1 1 1 1 1 1 

and you run +(+) it will show you the address of the first empty cell, i.e.

|11| 1 1 1 1 1 1 1 1 1 1

A more involved program is:

,>,>,>,>,>,<<<<<<-(-)-[({>+<)-]>!01020304050f
|30|  

Let's break it down. ,>,>,>,>,>,<<<<< sets up cell 0-5 with the hexadecimal values after the !. <-(-) moves the pointer to the last position on the tape, due to wrapping. Then it loads the value of the first empty cell to the right. -[({>+<)-] then copies the last nonempty cell to cell0 and repeats until all cells are zero.

And here is a first attempt at a Fibonacci sequence using the pointers:

+++++++++++>+++>+>+<<<[->({+++}+}----)+++({---}+++)+({---}+++)-----({+++}+}----) +++({---}+++)+({--}++)--<]

Source code

Currently there is no library released. IF there is some interest I (User:Password) will consider either releasing the Qt class or an c++ only version.