Professional Documents
Culture Documents
lr0 SLR 1
lr0 SLR 1
March 2, 2010
1 Key Points
• Item Automata
• Shift-reduce Parsing
(a) Add a new start symbol s0 which produces the original start symbol s
(b) Computer the closure of s0 → ·s as the initial state
(c) Make transitions from the initial state until reach the complete item
E → (L)|a
L → L, E|E
• A grammar is LR(0) grammar iff for any state in the item automata that contains a
complete item x → A·, then it can contain no other items
• A grammar is SLR(1) grammar iff in the item automata,
– any state contains item x → α · Xβ should not contain item y → γ· where X ∈
follow(y), and,
– any state contains complete items A → α and B → β, follow(a) ∩ follow(b) = ∅.
Exercise 2. According to the item automata constructed in Exercise 1., determine if the gram-
mar is LR(0) and SLR(1) grammar.
1
3. HOWTO: draw the LR(0) or SLR(1) parsing table
• When draw the SLR(1) parsing table, the number after the reduce action is the rule
number, specifying which rule to use to do reducing, and,
• the number after the shift action is the state number, specifying which state is transfered
to.
Exercise 3. Draw the LR(0) and SLR(1) parsing table for the grammar in Exercise 1..
Exercise 4. Show the SLR(1) parsing of ((a), a, (a, a)) according to the SLR(1) parsing table
created in Exercise 3.