BrainASM is an esoteric language interpreter, made fully on Lua
VERSION: 0.3
This project is distributed under GNU GPLv3-or-later license.
The most basic code looks like this
@ This is BrainASM code. All comments in here start from '@'
@ Every line with it gets ignored
@ This code asks user for input and prints the printed number
: 2
fc
: 1
p+
: 3
fc
Note! - the running file should be named 'main.basm'! The interpreter will not load any other name!
The interpretator starts with 10 variables - they are controlled by pointer. Pointer can be up to 10, representing each variable's position. It starts from first variable, or 1. The whole code runs through instructions, introduced as little words or character combinations. Sometimes they are mnemonics(Assembler-like commands, ex: ib, p+, stre) or one-char instructions(Brainfuck-like, ex: :, !, #) (That's, by the way, the reason it was renamed from BrainASM to BrainASM). Language combines Brainfuck's esoteric soul and Assembler's strictness and instructions.
Keep in mind, that's not all functions and there are more of them.
: (num) command sets variable's value to (num)
p+ moves pointer forward, 1 -> 2
p-, as you could guess, moves pointer backwards, 1 <- 2
! (as 'halt!') stops code's execution entirely
ib (num) - 'if bigger than...' works as 'if VAR(pointer) > num'
il (num) - 'if less than...' works as 'if VAR(pointer) < num'
iq (num) - 'if equals to...' works as 'if VAR(pointer) == num'
Note! - Logical operators didn't support any bodies and could check only one instruction once ago, but now you can enclose them by 'ei' instruction! ('end if')
That means this:
ib 5
@ This line will be executed if condition is true
: 5
@ But this line is NOT a part of 'if's body and will run with main thread along,
@ whenever past condition is true or false.
fc
Is now this:
@ This all is now in 'if' body
ib 5
: 5
fc
ei
fc is a special function that works as syscall in Linux. First variable means function's number. There is two functions that are very common in BASM programs:
1 - print(<var2> - address to variable) - prints variable's value which argument says to
2 - input() - asks for input number. Moves result to 5th variable.
Advantage of fc is that you can make custom scripts or upgrade existing ones in 'main.lua' file.
=====
For more information about syntax and extra commands check /docs/syntax.md
Let's check much more complex program(in 'main.basm'):
@ This is BASM code. It will check if number > than some value. If it is
@ then it will halt execution
: 2
fc
: 1
p+
: 5
p+
ib 5
!
ei
fc
: 2; fc - we are setting first variable's value to 2 and do function call(it will call input() function)
: 1; p+; : 3 - then, we are setting first variable's value to 1(print() function), then move pointer forward and set second variable's value to 5(it means print() function will check fifth variable to print it)
p+; ib 5 - we move pointer to third variable so 'if' statement checked it. Now, 'ib' checks: 'is third variable bigger than five?'
!; ei; fc - if so, '!' gets called and it stops code fully, then if-statement ends with 'ei'. Otherwise, 'fc' gets called as it calls print()
=====
For more examples of BASM usage and extra projects check /docs/examples