ABFC (Another BrainFuck Clone)

From Esolang
Jump to navigation Jump to search

ABFC (stands for "Another BrainFuck Clone") is a language created in ~6 hours by User:Nurdle.

Language Overview

ABFC (as the name suggests) is heavily influenced by brainfuck. Similarly to brainfuck it uses an array for storing data, but instead of the array being 30000 cells long, it is instead only 4096 cells long. Programs written in ABFC and brainfuck access the array using a pointer, but unlike brainfuck the pointer's value can also be stored.

Command Description
@(number) Set the pointer's position
>(number) Add to the pointer's position
<(number) Subtract from the pointer's position
=(number) Set the pointer's value
+(number) Add to the pointer's value
-(number) Subtract from the pointer's value
.(0 or 1) Print the pointer's value (0 prints the ASCII character while 1 prints it as a number)
,(useless argument) Get input from the user and set the pointer's value to it
:(useless argument) Declare a label
;(number) Goto a label
#(character) Sets the pointer's value to the ASCII code of a certain character
*(number) Multiply the pointer's value
/(number) Divide the pointer's value (automatically rounded)
%(number) Get the modulus of the pointer's value
$(useless argument) Store the pointer's value
?(number) Compare the pointer's value to the stored value, if they are the same then go to a certain function, if not then just continue reading without jumping

There are two extra characters not referenced in the table above: x and ~, x references the value that was stored using the $ command, and ~ is used to wrap comments. (x will return its ASCII value when put after # but ~ will not)

Examples

Hello World Program

The Hello World Program looks like this:

@0#H.0-3.0+7.0.0+3.0# .0#W.0-8.0+3.0-6.0-8.0

With comments (may not work):

@0 ~ point towards 0 ~
#H ~ set pointer value to the ASCII code of "H" ~
.0 ~ print the pointer value as an ASCII Character ~
-3 ~ take away 3 from the pointer value (gives us E) ~
.0 ~ print ~
+7 ~ add 7 to the pointer value (gives us L) ~
.0 ~ print ~
.0 ~ print ~
+3 ~ add 3 to the pointer value (gives us O) ~
.0 ~ print ~
#  ~ get the ASCII value of the Space character ~
.0 ~ print ~
#W ~ get the ASCII value of "W"~
.0 ~ print ~
-8 ~ take away 8 from pointer value (gives us O) ~
.0 ~ print ~
+3 ~ add 8 to pointer value (gives us R) ~
.0 ~ print ~
-6 ~ take away 8 from pointer value (gives us L) ~
.0 ~ print ~
-8 ~ take away 8 from pointer value (gives us D) ~
.0 ~ print ~

Note: You may be asking "can't we just use the character command?" and yes we can. (I'm not going to show you it)

Truth Machine

A Truth Machine is simple, it gets input, if given an input of 0 then the program prints "0" once and terminates, if the input is 1 then it will print "1" constantly.

,$
@0#0
?1

:0
#1.0
;0

:1
#0.0=10.0

With comments (may not work):

,$           ~ store input in tempval ~
@0#0         ~ at 0 put the ascii code of "0" ~
?1           ~ if the given input is equal to the ascii code of "0" then skip to :1 ~

:0           ~ create a goto-label (loop) ~
#1.0         ~ print "1" ~
;0           ~ go back to the start of the loop ~

:1           ~ create a goto-label so that we can skip the loop above ~
#0.0         ~ print "0" ~

No formatting/function labels:

,$@0#0?1:#1.0;0:#0.0=10.0

See Also

External Resources