Monky
Jump to navigation
Jump to search
MONKY is a language currently under development by User:Menguinponky.
It draws inspiration from FORTH, FALSE and C, it uses a data stack and reverse polish notation.
- All values on the stack are uint8_t
- All keywords are single special symbols
- Literals are signed integers
- Tokens are separated by spaces
- Extra spaces are ignored
- Stack underflow will read as 0
Stack effect notation:
(stack before -- stack after in C syntax)
List of all keywords:
| Op | Name | Stack effect | Meaning | Example → Output |
|---|---|---|---|---|
n
|
push int
|
(-- n)
|
Push signed integer value onto stack | 1, -2
|
c
|
push char
|
(-- c)
|
Push ASCII character onto stack | a, T
|
.
|
pop int
|
(n --)
|
Pop integer literal from stack and print | 3 . → 3, a . → 97
|
,
|
pop char
|
(c --)
|
Pop ASCII character from stack and print | a , → a, 97 , → a
|
_
|
drop
|
(n --)
|
Discard top of stack | 4 a _ . → 4
|
+
|
add
|
(n1 n2 -- n1+n2)
|
Add two top elements of stack | 1 2 + . → 3
|
-
|
sub
|
(n1 n2 -- n1-n2)
|
Subtract top element from previous | 3 1 - . → 2
|
*
|
mul
|
(n1 n2 -- n1*n2)
|
Multiply two top elements | 2 3 * . → 6
|
/
|
div
|
(n1 n2 -- n1/n2)
|
Integer divide previous element by top | 6 2 / . → 3
|
%
|
dup
|
(n -- n n)
|
Duplicate top of stack | 3 % . . → 3 3
|
$
|
swap
|
(n1 n2 -- n2 n1)
|
Swap two top elements | 1 2 $ . . → 2 1
|
^
|
over
|
(n1 n2 -- n1 n2 n1)
|
Copy previous element to top | 1 2 ^ . . . → 1 2 1
|
@
|
rot
|
(n1 n2 n3 -- n2 n3 n1)
|
Rotate three top elements to the left | 1 2 3 @ . . . → 2 3 1
|
&
|
and
|
(n1 n2 -- n1&n2)
|
Bitwise AND two top elements | 12 10 & . → 8
|
|
|
or
|
(n1 n2 -- n1|n2)
|
Bitwise OR two top elements | 12 10 | . → 14
|
#
|
xor
|
(n1 n2 -- n1^n2)
|
Bitwise XOR two topmost elements | 12 10 # . → 6
|
~
|
not
|
(n -- ~n)
|
Apply bitwise NOT to top element | 127 ~ . → 128
|
!
|
inv
|
(n -- !n)
|
Logical invert top element | 0 ! . → 1, 1 ! . → 0
|
=
|
equal
|
(n1 n2 -- n1==n2)
|
Replace two top elements by 1 if equal, 0 if not | 1 2 = . → 0, 3 3 = . → 1
|
<
|
less
|
(n1 n2 -- n2<n1)
|
Push 1 if top is smaller than previous, 0 if not | 1 2 < . → 0, 2 1 < . → 1
|
>
|
greater
|
(n1 n2 -- n2>n1)
|
Push 1 if top is greater than previous, 0 if not | 1 2 > . → 1, 1 2 > . → 0
|