SBL
SBL is a stack-based programming language, made by User:Alex s168, which focuses on being easy to use.
It consists of multiple code blocks, which can be called and executed. The code in a block will be executed line-by-line. One Line can contain multiple Operations by separating them with a space.
It has two stacks: a main stack and a data stack. Most operations run on the main stack.
Single-line comments are declared with ";"
Instructions
SBL has the following commands:
Code | Description |
---|---|
r | reverses the stack |
r- | reverses the top x elements of the stack (x is popped from the stack) |
. | pops and prints one element from the stack |
.c | pops and prints one element from the stack and outputs it as ASCII char |
_ | pops and prints x elements from the stack (x is popped from the stack) |
_s | pops and prints x elements from the stack and outputs them as ASCII string (x is popped from the stack) |
\ | prints a new line |
__ | dumps the whole stack to the console (doesn't clear the stack) |
d_ | dumps the whole data stack to the console (doesn't clear the data stack) |
>d | pops one element from the stack and pushes it onto the data stack |
<d | pops one element from the data stack and pushes it onto the stack |
p | peeks the top element on the stack and pushes it onto the stack (= copies the top element onto the stack) |
p2 | peeks the second top element on the stack and pushes it onto the stack (= copies the second top element onto the stack) |
id | pushes the ID of the current code block onto the stack |
c | clears the whole stack |
c- | clears the x elements from the top of the stack (x is popped from the stack) |
s | pushes the size of the stack onto the stack |
s | pushes the size of the data stack onto the stack |
sw | swaps the top two elements on the stack |
> | reads a input (console) and pushes the char(s) to the stack |
>. | reads one char from the input (console) and pushes it onto the stack |
sc | sets the condition flag |
cc | clears/unsets the condition flag |
ic | inverts the condition flag |
cp | compares the top two elements on the stack (and pops them) and if they are equal/not equal, sets/unsets the condition flag |
ls | compares the top two elements on the stack (and pops them) and if the first one is less than the second one, sets/unsets the condition flag |
gr | compares the top two elements on the stack (and pops them) and if the first one is greater than the second one, sets/unsets the condition flag |
c> | pushes the condition flag onto the stack (0 or 1) |
c< | pops the condition flag from the stack (0 or 1) |
< | jumps to the code block with id x (x is popped from the stack) if the condition flag is 1 / true |
<* | jumps to the code block with id x (x is popped from the stack) as a sub-routine if the condition flag is 1 / true |
+ | adds the top two elements on the stack and pushes the result onto the stack (a + b) (a is popped from the stack, then b) |
- | subtracts the top two elements on the stack and pushes the result onto the stack (a - b) (b is popped from the stack, then a) |
* | multiplies the top two elements on the stack and pushes the result onto the stack (a * b) (a is popped from the stack, then b) |
/ | divides the top two elements on the stack and pushes the result onto the stack (a / b) (b is popped from the stack, then a) |
% | applies the modulo operation on the top two elements on the stack and pushes the result onto the stack (a % b) (b is popped from the stack, then a) |
bitwise or (and pop) the top two elements from the stack and pushes the result onto the stack | |
& | bitwise and (and pop) the top two elements from the stack and pushes the result onto the stack |
! | bitwise not (and pop) the top element from the stack and pushes the result onto the stack |
la | loads all data from a data block (id pushed to the stack) (added in v1.2) |
The stack is a float-stack, and objects can be pushed onto the stack by simply writing a number, a char (surrounded by ' ), a string (surrounded by " ), a code block name (pushes the block`s id onto the stack) or an I/O object name (pushes its id onto the stack)
Code blocks
Code blocks are defined by using "name:", where "name" is a custom name.
In version 1.2, code block modifiers were added:
(public) D-TO-S: do stuff
and:
(data) COOLDATA: 1 99 2 9 55 0 88
public code blocks can be used across all files that link this file as library.
data code blocks can NOT contain instructions.
The code in a code block has to have an offset of exactly offset 4 spaces!
The program will be executed from a code block named "run", "start" or "main"
Linking files as libraries
Code blocks from other .sbl files (libraries) can be included by writing "link PATH" where "PATH" is the path to the file. This includes all code blocks from the file.
The "link" command can only be used at the beginning, outside of code blocks!
I/O files
I/O files can be defined by writing "io file NAME PATH" where "NAME" is a custom name and "PATH" is the path to the file.
The "io" command can only be used at the beginning, outside of code-blocks!
Built-in subroutine code-blocks
There are currently two built-in code blocks.
Block name | Description |
---|---|
EXIT | exits the program |
DELAY | waits x milliseconds (x is popped from the stack) |
FILE_SIZE | pushes the size of the content of the file with I/O id x onto the stack (amount of chars) (x is popped from the stack) |
FILE_READ | gets the content of the file with id x (in chars) and pushes the content one-by-one from left to right onto the data stack (x is popped from the stack) |
FILE_WRITE | sets the content of the file with id x (in chars). content is popped from the data stack, converted to ASCII, and written from left to right. It writes y chars (x is popped from the stack; y is popped from the stack) (If the file does not exist, it creates it) |
Examples
Hello world:
run: "Hello, world!" r s _s
Copy x elements from data-stack to stack
D-TO-S: 0 ; iteration value D-TO-S_loop <* ; temporary solution till get code line and ability to return to code lines (requires interpreter rewrite) sc ; resets the condition flag 3 c- ; clears temp variables D-TO-S_loop: <d sw ; max iterations - data - iteration (-> top) >d sw <d ; data - max iterations - iteration (-> top) 1 + ; increments iteration p2 p2 ; duplicates max iterations and iteration element cp ic ; compares if not equal D-TO-S_loop <* ; temporary solution till get code line and ability to return to code lines (requires interpreter rewrite)
Interpreter
Source code: https://github.com/SuperCraftAlex/sblang (v1.1)
Downloads: https://github.com/SuperCraftAlex/sblang/releases (v1.1)
Succesor
- SBL-X