Operator-Precedence Parser: Example
Precedence-table for Gexpr2:
+
Gexpr2 = (N, T, P, E), where N = {E}, T = {i, +, *, (, )},
P = { 1: E ® E+E, 2: E ® E*E, 3: E ® (E), 4: E ® i}
Note: Operator associativity and precedence rules underlie the precedence table:
E
E
E
+
*
i
i
i
E
E
E
E
E
+
*
i
i
i
E
E
*
(
)
i
$
+
*
(
)
i
$
>
>
>
>
<
<
<
>
>
>
<
<
<
<
<
<
>
>
>
>
=
<
<
<
<
>
>
>
>
Input token
Textové pole: Pushddown topmost token
Pushddown topmost token
Right parse:
44142
Right parse:
44421
4
4
4
2
1
4
4
4
2
1
J Right tree:
L Wrong tree:
6/42