Welcome to the Brainlack language documentation. Brainlack is a simple, yet powerful language that uses a unique set of commands to manipulate memory cells and pointers. Let's dive into the commands:
[
: This command increments the value in the current memory cell by 1. If the current value is
5, after this command it will be 6.]
: This command decrements the value in the current memory cell by 1. If the current value is
5, after this command it will be 4.*
: This command doubles the value in the current memory cell. If the current value is 5, after
this command it will be 10.,
: This command triples the value in the current memory cell. If the current value is 5, after
this command it will be 15.(
: This command moves the memory pointer one step to the right.)
: This command moves the memory pointer one step to the left..
: This command outputs the ASCII value of the current memory cell. For example, if the current
value is 65, it will output 'A'.%
: This command clears the memory, setting all cells to 0.#
: This command sets the value at the memory location to 0.@
: This command prints the integer value. (for debugging)/
: This command prints a newline character&
: This command prints a whitespace (or an actual space)For a list of ASCII characters, please see the ASCII Table
Brainlack reads commands from a file and executes them one by one. If the file cannot be opened, the interpreter will print an error message and exit. Let's learn about it!
In Brainlack, memory is represented as an array of cells, and there's a pointer that can move left or right to different cells. Each cell can hold a numerical value, and the commands you write will manipulate these values and the position of the pointer.
To make comments, you would place a ;
along with the comment you want to put and end it off with
another ;
.
; This is a comment.;
Let's write a simple Brainlack program that increments a memory cell, moves the pointer, and then decrements the new memory cell. Here's how:
[.(.]
This program will increment the value in the first memory cell, move the pointer to the right, and then decrement the value in the second memory cell.
If your program isn't working as expected, here are some debugging tips:
@
operator.[..*,,(.*).]
This command sequence will increment the value in the current memory cell twice, double it, triple it twice,
move the memory pointer to the right, double the value in the new memory cell, output the ASCII value, move
the memory pointer to the left, and output the ASCII value again.