Zomis / Brainduck

Brainfuck Interpreter in Java/Groovy, with a Groovy DSL
40 stars 1 forks source link

Procedural Brainfuck #19

Closed Zomis closed 2 years ago

Zomis commented 8 years ago

From http://4mhz.de/bfdev.html#pbrain

pbrain means "procedural brainfuck" and enables you to define and call procedures in your BF programs. For this purpose, pbrain adds three new commands to the BF language: "(", ")", and ":".

"(" starts definition of a procedure. This newly created procedure will be referenced with the value that's in the current memory cell. ")" ends the definition. ":" calls that procedure that is referenced by the current memory cell. BFdev does not tolerate calling of undefined procedures. In this case, it will report an error. BFdev offers a stack of 65536 entries, that means you can nest procedures until a depth of 65536. There is no stack overflow checking. This doesn't mean BFdev crashes if the stack grows too big, but instead, your program crashes and you probably wouldn't know why. The IDE itself doesn't crash when the stack overflows (I cared for this).

See also http://www.parkscomputing.com/2014/04/pbrain/

Example programs, as found on the link above:

Unknown effect

+([-])
+(-:< <[>>+< <-]>[>+< -]>)
+([-]>++++++++++[< ++++>-]< ++++++++>[-]++:.)
>+++>+++++>++:
>+++:

This pbrain program initializes a memory location to 65, the ASCII value of the letter ‘A’. It then calls a function for subsequent memory locations to copy the previous location and add one to it. Once a few cells are initialized, it prints all the cells to standard output.

+([-]< [-]<[>+>+< <-]>>[< <+>>-])
+([-]>[-]+:< +)
>>+++++++++++++[< +++++>-]
 ++:
>++:
>++:
>++:
< <<<.>.>.>.>.

Note that this issue conflicts with #11 because of the use of ( and )

Ethan-Bierlein commented 8 years ago

Just a small suggestion, but maybe you could surround it with single curly braces, like this:

{+[>+.]}

Or maybe double curly braces like this, to emphasize the fact that it's a method:

{{+[>+.]}}