Contents    Page-10    Prev    Next    Page+10    Index   

Operator Precedence Parsing

Operator precedence parsing is easily done using auxiliary stacks for operands and operators. Tokens are read and processed as follows:

reduce combines the two top operands and the top operator into a subtree, which is pushed onto the operand stack.

The = part of the test for operators implements left associativity, the usual case. For right associativity, use > instead.