File rpn.icn

Summary


 A simple reverse-polish calculator (works with numeric and string operations)

   Accepts numeric and string operands, operations, and function calls.
   Strings that "look like" variables can be used as variables.

   Note: given an overloaded operator/function, this
          always calls the largest (one with the most arguments).
          However, can fool by using 'nil' as arguments to ignore.
          So, for example:
               nil "abcdef" *
outputs '6'. Note: cannot handle functions with more than 3 arguments. Note: command line arguments are handled first
Procedures:
Exit, Pop, Write, deref, dup, flip, gettoken, help, main, popstack, printable, showmem, showstack, tokType, tostring, traceoff, traceon, var

Global variables:
mem, stack

This file is part of the (main) package.

Source code.

Details
Procedures:

Exit()

 Quit the calculator


Pop(stack)

 If stack is empty, write an error message and fail


Write(v)

 Display a value


deref(s)

 Dereference 's'.


dup()

 Duplicate the value on top of the stack


flip()

 Flip top two on stack


gettoken(params)

 generate the tokens in the input stream


help()

 Display a help message


main(params)


popstack()

 Pop off stack top


printable(x)

 Produce printable form of a value.


showmem()

 Display calculator memory


showstack()

 Display calculator stack


tokType(s)

 Identify a token as a value or a variable


tostring()

 Convert a value on the stack to a string


traceoff()

 Turn off tracing


traceon()

 Turn on tracing


var(s)

 return s only if it's a legal variable name...


Global variables:
mem -- simulates the calculator's memory...

stack -- and the rpn stack...


This page produced by UniDoc on 2021/04/15 @ 23:59:54.