A slightly more advanced Brainfuck-esque language.
Because I got bored one night.
Also, because Brainfuck is a cool language, except that it sucks to use. So, I decided to make it more practical.
Unlike Brainfuck, and sadly the only feature which makes this compiler incapable of fully compiling Brainfuck files, is that
comments must follow a //.
Example:
+>++>+++ // Puts 1,2,3 into memory
Probably the most useful feature, now you can insert numbers directly into memory using the = command.
Example:
=65 // Sets cell 0 to 65
The Second most useful feature, rather than moving between cells one-by-one, you can now move to any cell immediately.
Example:
%10=66 // Sets cell 10 to 66
Moves the cell pointer to the value of the current cell.
Example:
%5=67 // Sets cell 5 to 67
>=5 // Sets cell 6 to 5
&. // Sets pointer to cell 5, then outputs its value (67)
Copies the value of the current cell into the specified cell
Example:
%0=57 // Sets cell 0 to 57
*1 // Copies 57 into cell 1
Good news! Now you don't need to remember every value of an ASCII table. We can now directly enter an ASCII character into a cell.
Example:
='H'>='i'>='!' // Enters "Hi!" into three consecutive cells
Additionally, now we can just input entire strings into memory with ease.
Example:
S"Hello, World!\n"
We begin a string with the S character, and enclose the string with quotes.
Starting at the current cell, we first store the size of the string. Then, in the next cell, we store the the starting position of the string.
In the above example, the program memory would look like this:
[15][2][72][101][108][108] (...)
The number 15 is the length of the string, and the number 2 is the cell of the first letter of the string.
Our most advanced feature, we can now declare functions!
We declare functions as such:
D add_one +;
You start with the character D, then follow it with the name of the function, then the functions code, ending with a semicolon.
I'll warn that the compiler is very picky about function declarations.
- The 'D' must be followed by a space.
- The function name cannot have a space in the name. Besides that, go wild
- The code portion must end with a semicolon.
To call functions:
F(add_one)
We use the `F` character, with the function name surrounded by parenthesis. After the function call, the program will return to the position right after the last parenthesis (this is why you need the semicolon)(So I guess you don't technically need the semicolon).
You now have the option of interpreting values in memory as regular integer numbers rather than ASCII characters.
To switch between ASCII and INT output modes, use the ! command.
Example:
=65 . // Outputs A
! . // Outputs 65
To copy the current memory location to a specified location:
%15=13 // Assigns 13 to cell 15
@0 // Copys current location (15) to cell 0