- anything enclosed in
()is a comment - anything enclosed in
~~is a string - anything prefaced by
.is an operation - anything prefaced by
#is a label name - anything else is an integer
- words are separated by spaces or newlines; tabs are SUPPORTED
We provide
stack effect diagrams
to describe the state of the stack before and after each operation. For example
a b -- c means that before the operation the top item on the stack is b,
the second item from the top is a and after the operation the stack contains
only c. In other words, the diagrams describe before -- after and if there
is more than one item on the stack, the top of the stack is the rightmost item.
See also the scripts directory for example use of most functions.
For integer operator where order matters, eg. subtraction, multiplication, etc., we
always use the top of the stack as the "second" number. IE. if the stack
contains a b where b is the top of the stack, .- will push a - b. For
example 3 2 .- will push the result 1 to the stack; not -1.
.+a b -- (a+b)pops two numbers from the stack and pushes their sum.-a b -- (a-b)pops two numbers from the stack and pushes their difference.*a b -- (a*b)pops two numbers from the stack and pushes their multiple./a b -- (a/b)pops two numbers from the stack and pushes the quotient of the second popped number divided by the first popped number.moda b -- (a mod b)pops two numbers from the stack and pushes the remainder of the second popped number divided by the first popped number.=?a b -- (a==b)pops two numbers from the stack and pushes1if they are equal,0otherwise.>?a b -- (a>b)pops two numbers from the stack and pushes1if the second popped number is larger than the first one,0otherwise
.dupa -- a apush a copy of the top item on the stack.swapa b -- b aswaps the two top items on the stack
.cjumpa b --pops two numbers off the stack. if the second number is not0the program jumps by as many tokens as the first number indicates. eg. in1 -3 .cjumpthe number1indicates that a jump should happen and the number-3indicates that the program should jump three tokens back. If the program for instance is... 5 6 .* 1 -3 .cjumpwe will jump back to the token.*..cgotoa b --works like.cjumpbut instead of counting how many words/tokens to go back you can just specify a label prefaced by a#. E.g.1 loop .cgotowill go to the label#loop. Technically a preprocessor directive that gets translated to a.cjumpso the stack diagram is a little inaccurate.
.printa --pop an item from the stack and print it to terminal.newline--output a newline character to terminal; does not alter the stack.