My understanding of calculators is that they are stack-based. When you use most calculators, if you type 1 + 2 [enter] [enter]
you get 5
. 1
is pushed on the stack, +
is the operator, then 2
is pushed on the stack. The 1st [enter]
should pop 1
and 2
off the stack, add them to get 3
then push 3
back on the stack. The 2nd [enter]
shouldn't have access to the 2
because it effectively doesn't exist anywhere.
How is the 2
retained so that the 2nd [enter]
can use it?
Is 2
pushed back onto the stack before the 3
or is it retained somewhere else for later use? If it is pushed back on the stack, can you conceivably cause a stack overflow by repeatedly doing [operator] [number] [enter] [enter]
?