-3

I've been self teaching my self Swift. I was following the iOS 8 Swift Programming course on iTunes U from Stanford University.
Currently I am following the course and working on a project alongside the professor teaching it. It's a calculator app. He goes quite quickly through the course. So he mentioned the term "operand stack".
I didn't get what it meant. So what does "operand stack" actually mean?

Thank you.

Marcus Rossel
  • 3,196
  • 1
  • 26
  • 41
yousafe007
  • 119
  • 1
  • 8

2 Answers2

0

Does the calculator you are implementing happen to be an RPN calculator?

An operand is a number on which an action is to be performed. An operand stack is a "stack" of numbers. IE a group of numbers where it can be determined what order the numbers were added to the group.

In an RPN calculator, you would push the operands (numbers) in the stack, and then perform some action on them (such as add, subtract etc.)

Daniel T.
  • 32,821
  • 6
  • 50
  • 72
0

Paul Hegarty's example is very similar to so called Polish notation:

Polish notation, also known as Polish prefix notation or simply prefix notation, is a form of notation for logic, arithmetic, and algebra. Its distinguishing feature is that it places operators to the left of their operands. If the arity of the operators is fixed, the result is a syntax lacking parentheses or other brackets that can still be parsed without ambiguity.

The only difference is that he writes the stack from up to down (like the stack is), while the notation implies writing from left to right.

This approach is very convenient for programming as it does not require us to take care of parenthesises and operator precedence.

0x416e746f6e
  • 9,872
  • 5
  • 40
  • 68