Stack based (RPN, similar in concept to the likes of Forth and PostScript), 26 variables, if statements, while loops

Based on the Mouse programming language by Peter Grogono
https://en.wikipedia.org/wiki/Mouse_(programming_language)

RobCo MOUSE differs from official specifications, some features are omitted, there are several new symbols and some symbols have a different meaning.

Language symbols:

Mathematical operators:
These require two values to be present on the stack (n1 and n2)
+ - add - n1 + n2
- - subtract - n1 - n2
* - multiply - n1 * n2
/ - divide - n1 / n2
% - modulo - n1 % n2
# - random number between n1 (inclusive) and n2 (non-inclusive)

Data manipulation:
<NUMBER> - numbers in program are stored on stack for further use
<LETTER> - capital letters A-Z identify variables
<LETTER>. - dot immediately after variable - "read value from variable and put it on stack"
<LETTER>: - colon immediately after variable - "pop value from stack and store it in variable"

Input / output:
? - read integer from user input and put it on stack
?' - question mark apostrophe - read single character from user input and put its ASCII charcode on stack
- pop value from stack and print it as integer
!' - exclamation mark apostrophe - pop value from stack and print it as ASCII character
"<string>" - print string between the two double quotes
_ - underscore - new line

Logical operators:
If logical operation returns true, it puts 1 on the stack, else it puts a 0
- less than
> - greater than
- equals
; - not equal

Stack operators:
@ - duplicate value on top of the stack
- flip two values on top of the stack
r - reverse stack
s - sort stack in descending order
e - returns 1 if stack is empty, else 0

If statements:
[ <code> ] - If-block, code inside brackets executes only if the value on top of the stack is 1 (true)

1 2 < [ "Hello" ] - prints out "Hello", 1 < 2 is true
1 2 > [ "Hello" ] - does nothing, 1 > 2 is false

While loops:
( <code> ) - loop-block, if written like this code inside parentheses will execute forever (or until program operation limit is reached)
^ - loop exit, if value on stack is equal to 0 (false), exits the loop

1 N: ( N. 10 ; ^ N. 1 + N: ) 
in MOUSE is equal in C to:
int n = 1;
while(n != 10) { n += 1; }


Comments:
{ <comment> } - comments are any blocks of text inside braces

Other:
$ - exits program before end of code is reached

Article information

Added on

Edited on

Written by

AndyTheDwemer

1 comment

  1. TheUnexpected
    TheUnexpected
    • premium
    • 61 kudos
    For the wiki follow this link instead (or copy paste the text for safty): https://en.wikipedia.org/wiki/Mouse_(programming_language)