Stack

lin uses an unconventional syntax called RPN (Reverse Polish Notation). Normally in infix notation, an expression would be written as:

(1 + 8) ÷ 3 * 6 ^ 2

In RPN, this would be written as:

1 8 + 7 ÷ 6 3 ^ *

Both expressions can be represented by a syntax tree:

1 8
│ │
├─┘ 
+ 3 6 2
│ │ │ │
└─┤ ├─┘
  ÷ ^
  ├─┘
  *

lin's implementation of RPN utilizes stacks -- data structures which store all data used by lin. Values are always pushed to the top of the stack, and commands can be used to manipulate the stack in various ways. Using the above example, the process might look something like this:

CMD    STACK
1      1
8      1 8
+      9
3      9 3
÷      3
6      3 6
2      3 6 2
^      3 36
*      108

results matching ""

    No results matching ""