Brainfuck extended

From Esolang
Jump to navigation Jump to search

Brainfuck extended is extended Brainfuck, which can do complicated stuff easier than Brainfuck, developed by User:None1.

You can call it Bx for short.

Memory Model

Brainfuck stores its memory in a tape, so does Bx. But Bx also has a 8 bit register (which is 0 initially), which means it is more powerful.

Commands

There are 8 commands in Brainfuck, but Bx had much more.

Standard Commands

Standard commands are derived from brainfuck.

But in Bx, the + and - commands are replaced with / and \, because + and - have other uses.

Register Commands

Commands that access the register.

@  Rewrites the register with the pointer value.

%  Rewrites the pointer with the register value.

~  Swaps the pointer value with the register value.

+  Add the register and the pointer, and store the result into the register (modulo 256).

-  Subtracts the register by the pointer, and store the result into the register (modulo 256).

*  Multiplies the register and the pointer, and store the result into the register. (Modulo 256)

|  Compares the register value with the pointer value, if the register value is
 greater than the pointer value, store 1 into the register, otherwise 0.

&  Bitwise and the register value and the pointer value, and store it into the register.

^  Bitwise or the register value and pointer value, and store it into the register.

!  Bitwise not the register value.

;  Rewrites the register with a random integer from 0 to the register value before.

The random generator can either be a psuedo random generater or a real random generator.

Other Commands

A command that is neither a standard command nor a register command belongs to the 'Other Command' group.

(  Reads a decimal integer (unsigned) from standard input, and stores it into the pointer 
(modulo 256).

)  Writes the pointer value to standard output as an unsigned decimal integer.

{  Reads a hexadecimal integer (unsigned) from standard input, and stores it into the pointer 
(modulo 256).

}  Writes the pointer value to standard output as an unsigned hexadecimal integer.

_  Followed by exactly 2 hexadecimal digits (either uppercase or lowercase), rewrites the pointer with 
the value represented by these digits.

?<code>:<code>'  Conditional operator, if the pointer value is not zero, then run the code between ? and :
, otherwise run the code between : and '. The ' IS mandatory.

$<string>$  Treats the string as a C-style string, and rewites the tape with it, starting from the pointer.
Each $ matches the nearest $ after it.

#  Comment, each # matches the nearest # after it, just like that each /* matches the nearest */ in C++.

Example Programs

Hello World

_48._65._6c.._6f._20._57._6f._72._6c._64._21.

Cat Program

/[,.]

Random Integer Between 1 and 6

_05~;/~)

An easier way to print Hello World

$Hello World!$[.>]

Add two unsigned integers, the result is guaranteed to be less than 256

(@(+%)

Truth Machine (Characters that are not 0 are treated as 1)

_30~,~-~?_31[.]:.'

Randomly choose a number from two numbers read from user input

(>>(</~;~[>>]<)

Turing Complete?

This language is certainly turing complete, because Brainfuck is, and this language is a superset of Brainfuck.

Implementation

Bx is not implemented yet, but is implementable, but very hard because there are so many commands.