Chapter 4:Syntax Analysis

Notes on Canonical LR Parser

. Consider the grammar discussed in the previous two slides. The language specified by the grammar is c*dc*d.

. When reading input cc.dcc.d the parser shifts cs into stack and then goes into state 4 after reading d. It then calls for reduction by C d if following symbol is c or d.

. IF $ follows the first d then input string is c*d which is not in the language; parser declares an error

. On an error canonical LR parser never makes a wrong shift/reduce move. It immediately declares an error

. Problem : Canonical LR parse table has a large number of states

An LR parser will not make any wrong shift/reduce unless there is an error. But the number of states in LR parse table is too large. To reduce number of states we will combine all states which have same core and different look ahead symbol.