Reverse Polish Notation Language

I love RPN calculators.  My favorite is Hypatia which I use regularly for calculations.  I love being able to order my calculation to avoid brackets and being able to enter a list of numbers and add them up with a single command:

hy 12 23.4 43 94 3 d SUM

Now I am wondering about a full computer language built from the ground up as an RPN language?

A bit of googling led me to RPL or Reverse Polish Lisp which is close.  I wonder if this direction has been explored in other languages.

I am imagining a language where assignment is pretty straight forward (with explanatory pseudocode comment):

1 a = # a = 1

boolean expressions are just regular RPN:

a 1 + b > # a + 1 > b

and an if control structure would look like:

; bf ; bt ; a if # if a then bt else bf;

the meaning of the “;” token is to push following tokens (until the next structural token) unevaluated onto the stack as a single entry.  The if token evaluates the top stack entry (a) and then evaluates either the second (bt) or the third (bf).

A do while loop would look like this:

; b ; a dowhile # do b while a;

The dowhile token evaluates the second stack entry (b) and then the first (a) and repeats until a is false.

A key of RPN expressions is that there are no brackets required – by analogy in a RPN language there would be no nested statements!

Open question.  Can this idea be developed into a usable programming language?

Comments

  1. I also found: http://search.cpan.org/~szabgab/Math-RPN-1.11/lib/Math/RPN.pm

    I like a RPN language, becouse it can be interpreted on tiny machines (like uC). I want to implemented in on PIC microcontroler (i have already write few RPN calculator/translator in C).
    I think that the problem could be IF statment (on microcontrolers its vary hard to use structures), in the link above the costruction quite similar to Yours is use:
    1,{,5,3,+,10,*,},{,1,2,3,+,+,},IF
    which translate to:
    if 1 {,5,3,+,10,*,} else {,1,2,3,+,+,}
    but i think it would be better to use:
    1,IF,{,5,3,+,10,*,},{,1,2,3,+,+,}
    and than you exactly know which bracket expression must be calculated (don’t need to go back with stack).
    On the other hand when there is IF in IF it can coused problems.
    Right now only option ( to use infite number IF statment in RPN) is only 3 argument if, but it is not efficiency (evaluating all – even unused calculations) and coused problem when there is some assigment in IFs.
    Any ideas how to solve this problem on tiny machines (used infite number of IFs with skipping unused code and without lot’s of memory)?

Trackbacks

  1. […] I have created Ambi Calculator and Programming Language as a result of investigation about the possibility of a Reverse Polish Notation Language. […]

Speak Your Mind

*