Contents    Page-10    Prev    Next    Page+10    Index   

Example of Operator Precedence

An operator precedence parser examines the current operator and the preceding operator on the stack to decide whether to shift the current operator onto the stack or to reduce (group) the preceding operator and its operands.


1 2 3 4 5 6 7 8
A + B * C + D

Pos Operand Stack Operator Stack
1 A
2 A +
3 A B +
4 A B + *
5 A B C + *
6 A (* B C) +
(+ A (* B C))
(+ A (* B C)) +
7 (+ A (* B C)) D +
8 (+ (+ A (* B C)) D)