| Crates.io | stackathon |
| lib.rs | stackathon |
| version | 0.5.0 |
| created_at | 2025-11-30 18:30:53.623448+00 |
| updated_at | 2025-12-13 03:00:43.226061+00 |
| description | The interpreter for the Stackathon language |
| homepage | |
| repository | https://github.com/RishabhOke-Dev/stackathon |
| max_upload_size | |
| id | 1958596 |
| size | 81,701 |
Stackathon is a stack based language, similar to Forth.
Comments sit between two ;.
Any numbers, strings, or functions are immediatly pushed to the stack.
2 2 "hello" my_function
;Stack is now [2, 2, "hello", my_function];
The operators '+', '-', '/', and '*' work on the top two items on the stack.
2 2 +
;The + operator adds 2 + 2;
When using the / with a string and an int, lets say n, the nth character in the string is pushed.
"Hello" 2 / print
;Prints 'e';
Use the print keyword to print the top of the stack. Currently, when printing blocks, the output is not as clean as the other types.
2 3 * print
;prints 6;
In stackathon, there are two types of functions. Names functions, and blocks, or anonymous functions.
To define a named function, use the @ operator, with the body in {}.
@foo {
2 +
;Adds two to its input;
}
To define a block, simply put the body in {}, and they will be pushed to the stack
{
2 2 + print
}
;Stack now contains the block;
To call either of these, use the $ operator.
The $ operator runs any function on the top of the stack.
@foo {
2 +
}
100 foo $ print ;Prints 102;
3
{
2 *
}
$
print
;Prints 6;
To exit a function early, use the exit keyword.
In order to make a loop, use the loop keyword.
The loop keyword acts similarly to a while loop in other langauges.
The loop keyword expects a function on the top of the stack, and an initial condition below it.
The function is run every cycle. Unlike a while loop, the initial condition, is dropped after its first use.
The function is required to put a boolean on the top of the stack every time it finishes.
15 ;15 is the iteration amount; true {
"one loop" print
- 1 ;Decrease iter amount;
0 = !;Check if it is done, if not then we continue, so we also negate it;
} loop
This behavior allows the loop keyword, to be made into many different types of loops.
A gate is the same as an if else gate in other languages.
The gate keyword requires the true function on the top of the stack, an optional false block below it, and a condition below it.
5 4 < {
"true!" print
}
gate
;prints nothing;
In stackathon, you can check the type of a value using the type keyword. Here is a list of all the types and examples of them.
int eg. 5float eg. 5.1string eg. "Hello"bool eg. trueblock eg. A function or a block
Tags are functions with no bodies, you define them like @name. They are used for custom types, and can be pushed by writing out their name.@int
2 type int = ;The type keyword pushes a tag!;
In stackathon, libraries are actually compiled! Any named functions and tags, are serialized into a .stk.lib file. In order to tell the interpreter to treat your .stk as a library, use the argument --lib after the name of your file. In order to use a library, use the use keyword. After the use keyword, put the path to your library. After the keyword, you can use any function that is available in the function.
;my_lib.stk;
@foo {
"foo" print
}
;my_program.stk;
use my_lib
foo $
;Works!;
print Prints the top of the stacktrue Pushes boolean true to the top of the stackfalse Pushes boolean false to the top of the stackexit Exits a function earlyloop Used to make loopsgate Used to make if else Gatesdup Duplicates top of the stackdrop Deletes top of the stackswap Swaps top two values on the stackdepth Pushes length of stackrot Puts 3rd item of the stack on the topnrot Puts top of the stack into the 3rd space on the stackover Duplicates the 2nd item of the stacktuck Duplicates the top item, and puts it under the second item, (in the third slot of the stack)pick Copies the nth item of the stack to the top, where n is on the top of the stack when it is calledroll Pulls the nth item of the stack to the top, where n is on the top of the stack when it is calledclear Clears the entire stacktype Pushes type of the top of the stack onto the stack.use Invokes a stackathon library.input Pushes the user input as a stringstrlen Pushes the length of a string, in Unicode Scalar values.