Annotated edit history of
ReversePolish version 8, including all changes.
View license author blame.
Rev |
Author |
# |
Line |
6 |
AristotlePagaltzis |
1 |
Styles of syntax used for writing expressions or tree-structured data: |
|
|
2 |
|
|
|
3 |
|
|
|
4 |
!!!Infix |
|
|
5 |
|
|
|
6 |
In infix notation you write the operator between the arguments: |
|
|
7 |
|
|
|
8 |
c - (5 + a + x) * b |
|
|
9 |
|
|
|
10 |
Infix notation is the usual. It needs precedence rules and/or brackets to make the order of operations unambiguous. Polish and Reverse Polish don't have that problem, providing the number arguments to each operator is fixed. |
|
|
11 |
|
|
|
12 |
!!!Reverse Polish |
|
|
13 |
|
|
|
14 |
In Reverse Polish, or __postfix__, notation you write the operator after the arguments. |
|
|
15 |
|
|
|
16 |
c 5 a + x + b * - |
|
|
17 |
|
8 |
JohnMcPherson |
18 |
It's very easy to interpret expressions in this notation, you need just a single stack to place intermediate values on, this is why [Forth] and PostScript (which was based on Forth?) use it. |
6 |
AristotlePagaltzis |
19 |
|
|
|
20 |
!!!Polish |
|
|
21 |
|
|
|
22 |
In Polish, or __prefix__, notation you write the operator before the arguments. |
|
|
23 |
|
|
|
24 |
- c * + 5 + a x b |
|
|
25 |
|
|
|
26 |
Polish notation is called that because a famous Polish mathematician first used it for Boolean algebra, and nobody can either remember or pronounce his name without looking it up first. (''You'' go look it up.) |
|
|
27 |
|
|
|
28 |
!!!S-expressions |
|
|
29 |
|
|
|
30 |
In S-expression, or [LISP], notation you write the operator before the arguments, enclosed in brackets: |
|
|
31 |
|
|
|
32 |
(- c (* (+ 5 a x) b)) |
|
|
33 |
|
|
|
34 |
[LISP] operators take any number of arguments so [LISP] expressions need brackets to associate arguments with operators. |
|
|
35 |
|
|
|
36 |
It's very easy to parse this notation into tree structures, which is why [LISP] uses it. |
|
|
37 |
|
|
|
38 |
!!!XML |
|
|
39 |
|
|
|
40 |
In XML notation you bracket the arguments with the operator: |
|
|
41 |
|
|
|
42 |
<subtract> |
|
|
43 |
<variable name="c"/> |
|
|
44 |
<multiply> |
|
|
45 |
<add> |
|
|
46 |
<constant value="5"/> |
|
|
47 |
<variable name="a"/> |
|
|
48 |
<variable name="x"/> |
|
|
49 |
</add> |
|
|
50 |
<variable name="b"/> |
|
|
51 |
</multiply> |
|
|
52 |
</subtract> |
|
|
53 |
|
|
|
54 |
Whoever came up with this had good intentions, I'm sure... |