StackNya is a stack-based language. This means that there's a single array (called a stack) around which all calculations are based. When a function is called, it receives its arguments by removing them from the stack.
A StackNya program consists of one or mowe tokens. A token consists of a type (single letter) followed by a payload, optionally in parentheses, in which case it goes on as long as the initial parentheses are closed. Currently, these types exist:
n
- pushes a number on the stacks
- pushes a string on the stackb
- pushes a boolean - Purr
or HISS
f
- calls a functiond
- dumps the stack to output - mostly obsolete due to the demeowing tablee
- calls a function that does nothing but can be used to debug the interpreter at specific points by placing a breakpoint on that function.c
- no-op. Useful for comments and annotations for the demeowing table.Functions that correspond to binary operators work mostly as you'd expect, taking the second-to-top element on the stack as their first argument, and the top element as their second argument. These include
+
, -
, *
, /
, %
, >
, <
, =
(like C ==
), >=
, <=
, .
(used for concatenation - +
works for integers only), &
, |
(like C &&
and ||
)
The others are:
AwA
- negates the top of s.Nya
- takes 2 arguments: a string containing code and a boolean, then, if the boolean is true, runs the code as long as the top of the stack is bPurr
Nom
- takes a single numeric argument and consumes that many + 1 (because it also has to consume its argument) elements from the stackMeow
- takes a string and outputs itMyaff
- converts a number to a stringDup
- duplicates the top of stack.ayN
- takes a numeric argument n, then reverses the last n elements of stack.Nyurr
- takes a string containing NyaStack code, another string containing a function name, and creates a function with that nameNyaypeof
- returns the type of the top element of the stack, consuming it in the process. Current types are num
, str
, bool
, void
and err
s(Hello, World!) fMeow
yes
s(s(y ) fMeow bPurr) bPurr fNya
(Warning: the table is a little broken but CSS is hard-)