Complack is a simple, stack-based language created by User:Olivato. Is based in Simplack created by User:Saka. Complack means Complex Stack is an extension of Simplack, with infinite stacks, labels, more conditional branches, subroutines and more!
In Complack only integers can be stored in the stack, although they can be outputted as characters.
Each instruction is on a separate line.
Comments are any line that start with
Note: All instructions name can be easily changed.
Certain arguments can use values from other items in the stack by using
$n where n is the index that the value will be taken from. These arguments are marked by an asterisk (*) after them.
|use n||Start using the stack n. If the stack don't exist it'll be created. Every stack operation will be done in the selectd stack and it'll exist until program finishes running. Multiple stacks can be used|
|prints t||Print the entire selected stack cell by cell, either character (t = c) or an integer (t = i).|
|push n||Push the integer n to the top of the selected stack.|
|pop n||Pop/remove item at index n of the selected stack.|
|inc i n*||Increase integer at index i by n|
|dec i n*||Increase integer at index i by n|
|set i n*||Set the integer at index i to n|
|label l||Create code label pointer, this can be used by jump functions like goto or if|
|if i n* goto l||If the integer at index i is n, go to label l, otherwise, carry on. NOTE : l can be a line index but is discouraged, use labels instead.|
|nif i n* goto l||If the integer at index i is not n, go to label l, otherwise, carry on.|
|bif i n* goto l||If the integer at index i is bigger than n, go to label l, otherwise, carry on.|
|sif i n* goto l||If the integer at index i is smaller than n, go to label l, otherwise, carry on.|
|goto l||Go to label l. NOTE : l can be a line index but is discouraged, use labels instead.|
|sub n||Create a subroutine with label n. Pushes the address of return in the auxiliary call stack, this stack can't be accessed.|
|end||Pops the call stack returning to the code. Note: Every subroutine needs an end terminator|
|gosub n||Goto subroutine and returns after it concludes|
|output i t||Output item at index i as either character (t = c) or an integer (t = i).|
|input t||Get either character (t = ç) or integer (t = i) input and push it to top of the selected stack. If a string is inputted, each character will get pushed one by one, not as the whole string.|
|exit||End the program.|
Here are some examples: Complack is simplack compatible, so every example of simplack runs too.
# Echo what user input input c prints c
use hello push 72 push 101 push 108 push 108 push 111 push 44 push 32 push 87 push 111 push 114 push 108 push 100 push 33 push 0 prints c
Square of Input
#Calculates the square of whatever input i push 0 push 0 label cont inc 2 $0 inc 1 1 if 1 $0 goto end goto cont label end output 2 i
Fibonacci of the n-th
use fib push 0 push 1 push 0 push 0 push 10 use howManyTimes input i label increment use fib set 3 $0 inc 3 $1 set 2 $3 set 0 $1 set 1 $2 output 3 i output 4 c use howManyTimes dec 0 1 if 0 0 goto finish goto increment label finish
sub pushThreeValues push 0 push 10 push 20 end sub popFirstAndOutput pop 0 output 0 i end gosub pushThreeValues gosub pushThreeValues gosub pushThreeValues gosub popFirstAndOutput gosub popFirstAndOutput
Using multiple stacks
use potato push 112 push 111 push 116 push 97 push 116 push 111 use somethingElse push 10 push 20 push 30 use potato # Prints stack potato as char prints c use somethingElse # Prints stack somethingElse as integer prints i
input i # Discouraged behavior if 0 1 goto 4 output 0 i exit output 0 i push 1 goto 4
Available on GitHub