Professional Documents
Culture Documents
OR
PARSING
Lecture 08
1
LR(1) ITEM
To avoid some of invalid reductions, the states need to carry
more information.
3
INTUITION BEHIND LR (1) ITEMS
4
INTUITION BEHIND LR (1) ITEMS
5
THE CLOSURE FUNCTION
6
THE CLOSURE FUNCTION
7
LR (1) EXAMPLE
S -> CC
C -> cC
C -> d
8
THE GOTO FUNCTION
9
CONSTRUCTION OF LR(1) PARSING TABLES
1. Construct the canonical collection of sets of LR(1) items for G’.
C←{I0,...,In}
.
2. Create the parsing action table as follows
• If a is a terminal, A→α aβ,b in Ii and goto(Ii,a)=Ij then action[i,a]
.
is shift j.
.
• If A→α ,a is in Ii , then action[i,a] is reduce A→α where A≠S’.
• If S’→S ,$ is in Ii , then action[i,$] is accept.
• If any conflicting actions generated by these rules, the grammar is
not LR(1).
.
I1 : A → α ,a .
I2: A → α ,b
.
B → α ,b .
B → α ,c
⇓
.
I12: A → α ,a/b € reduce/reduce conflict
.
B → α ,b/c
Any Questions ?
17