Share your repls and programming experiences

← Back to all posts
StackLang Alpha
h
CodeLongAndPros (559)

StackLang is a ... Stack based language!

All operands are based on pushing and popping values off the stack.

Generic functions:

push [string|int|float]
pop

call [function|funcode|section]

examples:

push "Hello World"
call 13
push "Num1: "
call 14
push "Num2: "
call 14
call 15
call 6
call 15
call 6
call 15
call 1
call 7
call 13
call 0

FuncCodes:

-2 - Dumps stack
-1 - brt. Exits with error code pop. [i]
0 - ext. Exits
1 - add. Takes pop + pop, and pushes [i/f, i/f]
2 - sub. Take pop - pop, and subtracts them. [i/f, i/f]
NI 3 - mul. Takes pop * pop and pushes. [i/f, i/f]
NI 4 - div. Take pop / pop and pushes. [i/f, i/f]
5 - jnz - Jumps to line pop(), if pop() and pop() are equal [*, * lineno]
6 - toi - tries to convert to int
7 - tos - tries to convert to string
8 - tof - Tries to convert to float
9 - cat - Concats pop and pop together
10 - TBD
11 - TBD
12 - TBD
13 - prn. Prints pop to standard output. [String]
14 - inp - Pushes the user's input to prompt pop [String, String]
15 - swp - swaps first two values in the stack

Defining sections (Functions):

You define a section with:
section

endsect

For example:

section hello_world
push "Hello World"
call 13
endsect

You call a section using:

call [section]

Complete example:

section hello_world
push "Hello World"
call 13
endsect

call hello_world
call 0

Including other files:

You include a file with

%include filename

Filename has to have no spaces.

Anything in the %included file is executed.

For example:

header.stk:

section mali
call 15
endsect

call mali

And any program that has:

%include header.stk

Will have the stack changed.

Best pratices:

End a program with call 0

Do not name your sections after numbers.