The Forth input line
decimal 2 5 73 -16
ok<#,ram>
leaves the parameter stack in the state
cell # | contents | comment |
0 |
![]() |
TOS (Top Of Stack) |
1 |
![]() |
NOS (Next On Stack) |
2 |
![]() |
|
3 |
![]() |
|
Suppose that we followed the original input line with the line
+ - * .
xxx
ok<#,ram>
What would the xxx be?
The operations would produce the successive stacks:
word executed | + | - | * | . | ||
stack result | TOS NOS |
-16 73 5 2 |
57 5 2 |
-52 2 |
-104 |
decimal 2 5 73 -16 ok<#,ram>2 5 73 65520 + - * . -104 ok<#,ram>Note that FlashForth conveniently displays the stack elements on interpreting each line and that the value of -16 is displayed as the 16-bit unsigned integer 65520. Also, the word ``.'' consumes the -104 data value, leaving the stack empty. If we execute ``.'' on the now-empty stack, the outer interpreter aborts with a stack pointer error (
SP ?
).
The programming notation where the operands appear first,
followed by the operator(s) is called reverse Polish notation (RPN).
It will be familiar to students who own RPN calculators made by Hewlett-Packard.