Files
BrainAssemblyV2/docs/syntax.md

1.7 KiB

Syntax Overview

Each expression of code is separated by a semicolon. Multiple expressions may be in one line.

The syntax for each command is <command name> <arguments>. Each argument is separated by a space.

Use the # character for comments.

Commands

raw

Syntax: raw <code>

Directly appends Brainfuck to the compiled code.

Example usage: raw >>[>+<-]<<

li(num)

Syntax: li(num) <type> <var-name> <malloc> <malloc> ...

The li command allows you to allocate memory to a specific variable. The number after li dictates the dimensions of a list. For a non-list, use li0.

The number of malloc arguments should be equal to the dimensions. The first number dictates the bytes allocated for the entire list, the second number dictates the bytes allocated for the sublists, and so on.

For example, to allocate memory for myList = [[int, int, int], [int, int, int], [int, int, int]], you would use

li2 int myList 36 12; # 36 for entire list (9 4-byte ints), 12 for sublists (3 4-byte ints)

Valid types are char, bool and int.

Note: You cannot change the number of bytes allocated later. There are no safeguards to prevent reading outside of allocated memory, such as into the next variable or other miscellanous garbage data.

set

Syntax: set <var-name> <list indices> <value>

The set command allows you to set a variable to a value. Requires the same number of list indices as list dimensions.

Enclose strings in single quotes.

Currently only literals are supported. This will be changed in the future.

Example usage:

li1 int nums 100;
set nums 0 927;

ptr

The ptr command allows you to manipulate the main pointer.

Syntax: ptr <action> <args>

ptr set <int>: Set the position of the pointer.