Syntax: Reverse Polish Notation

This is a calculator which mainly operates on signed integer numbers. Numbers and operators are typed into the "Input" field and submitted with carriage return. The TOS is the top-of-stack, which is the most recent number pushed on it; the NOS is the next number below the top-of-stack. The API is in jdocs and more detailed information in Section 8 in FI.pdf.
Operators external.png are one of
  • + add top 2 items of the stack
  • 1+ increase TOS by 1
  • 2+ increase TOS by 2
  • - subtract top 2 items of the stack
  • 1- decrease TOS by 1
  • 2- decrease TOS by 2
  • * multiply top 2 items of the stack
  • 2* multiply TOS by 2
  • / integer division of top 2 items of the stack, NOS/TOS
  • 2/ divide TOS by 2 (arithmetic shift right)
  • */ multiply 2nd and 3rd item from top of the stack and divide through top of the stack
  • MOD remainder of top 2 items of the stack, NOS mod TOS.
  • /MOD remainder and divisor of top 2 items of the stack
  • */MOD multiply 2nd and 3rd item of stack and leave remainder and divisor of dividing the product by top item of stack
  • AND bitwise AND of top 2 items of the stack
  • OR bitwise OR of top 2 items of the stack
  • XOR bitwise XOR of top 2 items of the stack
  • NEGATE flip sign of TOS
  • ABS build positive absolute value of TOS
  • MIN maximum of the top 2 items of the stack
  • MAX minimum of the top 2 items of the stack
  • DUP duplicate TOS
  • ?DUP duplicate TOS if nonzero
  • DROP remove TOS
  • SWAP exchange top 2 items on the stack
  • OVER duplicate NOS
  • TUCK copy a duplicate of top stack item before first but last item
  • NIP remove NOS
  • ROT rotate the 3 topmost items of the stack
  • ROLL rotate as many items of the stack is indicated by the TOS (plus 1)
  • PICK copy an item from the stack at the position indicated by the top item
  • 2DUP copy 2 items of the top of the stack
  • 2DROP remove NOS and TOS
  • 2SWAP swap the two pairs of the 4 topmost items on the stack
  • 2OVER copy the pair of numbers below TOS and NOS on top of the stack
  • TRUE Push TRUE (-1) on the TOS
  • FALSE Push FALSE (0) on the TOS
  • >R push item from stack to return stack
  • R@ copy top of return stack to stack
  • R> move top of return stack to stack
  • ! Store NOS to the variable named by the TOS
  • +! Add the value of the NOS to the variable named by the TOS
  • @ Replace the variable named by the TOS by its value.
  • QUIT remove all items from return stack
  • 2>R move 2 items from stack to return stack
  • 2R> move 2 items from return stack to stack
  • < evaluate to true if 2nd item of stack less than top of stack
  • > evaluate to true if 2nd item of stack is greater than top of stack
  • = evaluate to true if 2nd item of stack equals top of stack
  • <> evaluate to true if 2nd item of stack differs from top of stack
  • 0= evaluate to true if top of stack equals zero
  • 0<> evaluate to true if top of stack differs from zero
  • within evaluate to true if n3≤n2<n1 where n1, n2 and n3 are the topmost items on the stack
  • DECIMAL switch to number base 10
  • HEX switch to number base 16
Operators may be written in uppercase or lowercase letters, and act in RPN external.png style on numbers on the stack. There is limited support for fractions: if a word keyed in contains a single slash, it will be reduced to a fraction, on which the operators will operate according to the arithmetic standards. If the result of such an operation is integer, it will be treated as such by the followup operations. Characters between parenthesis (surrounded by blanks) or after a backslash in a line are comments and ignored (but copied to the history).

Examples

The syntax is inherited from Forth (Wikipedia). external.png The main difference are: there are no loops or branches implemented here. Numbers here have an unlimited count of digits and there is no distinction between single-length, double-length or signed/unsigned numbers.
See also other Online calculators external.png

Richard J Mathar, www.mpia.de/~mathar