Advanced Brainfq - PreyMa/advanced-brainfq GitHub Wiki
Advanced Brainfq adds some basic functionalities to Brainfuck, which solve some anoying problems of this programming language.
If you want to set the currently selected memory cell to a predefined value, you would normaly have to write as many increment commands until yo reach your desired value. This is fixed by adding the value set command '='. By writing the command and a value after it, the cell will be set to this value. For example: ' =256 ' The same goes for the pointer set command '%', which sets the memory cell pointer a predefined position, like: ' %32 ', this sets the pointer to the 33rd cell.
In addition you can also use the value get and pointer get commands to retrieve a value for one of the situations above. This might be useful, if you want to calculate pointer to a specific cell:
- '=;' sets the current cell to the current pointer position -> sets the cell to it's own address
- '%$' sets the pointer position to the current cell value
- '=$' and '%;' are quite stupid and are optimized away by the interpreter.
To do arithmetics Advanced Brainfq offers some new things too. Invertig of the current memory cell is done with '!'. For an AND operation '&' is written. Like for all other operations which expect to values the interpreter takes the next cell executes the command with the current cell and saves the result in it. The next cell remains untouched in it's state. These operations are:
- and '&'
- or '|'
- add '*'
- subtract '_'
- move '~' (the target address is specified in the next cell)
If you want to tackle repeating problems you would use functions in higher programming languages which are called when needed. The implemlentation of this principle was one of the main goals of this project and is solved by indicating functions with ':'. The charractes is placed like brackets at the beginning and end of the function. Since there do not exist names for these functions, only numbers are used. The first function gets the id 0 and will be called as the main function by the interpreter at startup. From the main function all other ones are called with '#' and a value afterwards. Something like this '#0' would produce a recursion of the main function for example. The calling operator also supports ';' and '$'. This enables calculating function calls and by using smart function numbering, you might save some branching in your code.