Simple precedence parser


In computer science, a simple precedence parser is a type of bottom-up parser for context-free grammars that can be used only by simple precedence grammars.
The implementation of the parser is quite similar to the generic bottom-up parser. A stack is used to store a viable prefix of a sentential form from a rightmost derivation. Symbols, and are used to identify the pivot, and to know when to Shift or when to Reduce.

Implementation

SearchProductionToReduce
Given the language:

E --> E + T' | T'
T' --> T
T --> T * F | F
F --> | num
E' --> E

num is a terminal, and the lexer parse any integer as num.
and the Parsing table:
EE'TT'F+*num$
E
E'
T
T'
F
+
*
num
$-


STACK PRECEDENCE INPUT ACTION
$ < 2 * $ SHIFT
$ < 2 > * $ REDUCE
$ < F > * $ REDUCE
$ < T = * $ SHIFT
$ < T = * < $ SHIFT
$ < T = * < $ SHIFT
$ < T = * < $ REDUCE 4 times
$ < T = * < $ SHIFT
$ < T = * < $ SHIFT
$ < T = * < $ REDUCE 3 times
$ < T = * < $ REDUCE 2 times
$ < T = * < $ SHIFT
$ < T = * < > $ REDUCE
$ < T = * = F > $ REDUCE
$ < T > $ REDUCE 2 times
$ < E > $ ACCEPT