Post Reply 
why is RPN always reversed (not PN)
05-25-2015, 07:44 AM
Post: #5
RE: why is RPN always reversed (not PN)
(05-25-2015 07:19 AM)StephenG1CMZ Wrote:  To me,
1 2 + 3 *
And
* 3 + 2 1
Would both appear to need a stack capable of storing operands or oprerators in a mixed sequence - but only one might generate an error as you enter 3.14i nstead of 3 (depending on the domain of your + and * functions).

No - as Gerald H has pointed out, the RPN version is able to execute the operators immediately and has no need to store them.

What you are really getting at is the notion of type safety and type promotion. In your example, you use the ADD or + operator, which might cause a syntax error when applied to strings. However, it might not if it really represents string concatenation and it can promote, say, a number higher on the stack to a string to allow that.

And while the prefix version might detect the syntax error as soon as it sees the opening quote of the string, it might not - in fact, probably would not - see that quote until you've entered the entire quoted string, eliminating any keystrong advantage for the prefix approach. Generally, a line won't get parsed until the entire line has been entered by pressing "Enter", whether on a calculator-like device or on a computer keyboard.

--- Les
[http://www.lesbell.com.au]
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: why is RPN always reversed (not PN) - Les Bell - 05-25-2015 07:44 AM



User(s) browsing this thread: 5 Guest(s)