














Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Shift-reduce conflicts, a common issue in parsing where ambiguities in the grammar lead to conflicting actions. The concept of shift-reduce conflicts, their causes, and a classic example of dangling else statements. It also explains how to resolve such conflicts by prioritizing the shift action.
Typology: Slides
1 / 22
This page cannot be seen from the preview
Don't miss anything!















2 Stack Input ¤0 id – id × id $ s ¤0id4 – id × id $ r6 F→ id ¤0F3 – id × id $ r5 T→ F ¤0T2 – id × id $ s ¤0T2–5 id × id $ s
4 Stack Input ¤0 id – id × id $ s ¤0id4 – id × id $ r6 F→ id ¤0F – id × id $ r5 T→ F ¤0T2 – id × id $ s ¤0T2–5 id × id $ s
5 Action Goto id – × $ E T F 0 s4 1 2 3 1 acc 2 s5 r 3 r5 s6 r 4 r6 r6 r 5 s4 7 2 3 6 s4 8 3 7 r 8 r4 r
7 Stack Input ¤0 id – id × id $ s ¤0id4 – id × id $ r6 F→ id ¤0F3 – id × id $ r5 T→ F ¤0T2 – id × id $ s ¤0T2–5 id × id $ s
8 Stack Input ¤0T2–5id4 × id $ r6 F→ id ¤0T2–5F3 × id $ s ¤0T2–5F3× 6 id $ s ¤0T2–5F3×6id4 $ r6 F→ id ¤0T2–5F3×6F3 $ r5 T→ F ¤0T2–5F3×6T8 $^ r4 T→ F×T
10
stack.push(dummy); stack.push(0); done = false; token = scanner.next(); while (!done) { s = stack.top(); if( Action[s,token] == “reduce A→β”) { stack.pop(2×|β|); s = stack.top(); stack.push(A); stack.push(Goto[s,A]); }
11 else if( Action[s,token] == “shift i”){ stack.push(token); stack.push(i); token = scanner.next(); } else if(Action[s,token] == “accept” && token == “$” ) done = true; else report error and recover; } report success;
13 Shift/Reduce Conflicts
14 Shift/Reduce Conflicts
16 Shift/Reduce Conflicts
17 Shift/Reduce Conflicts
19 Shift/Reduce Conflicts
[stmt → if E then stmt•, else] [stmt → if E then stmt • else stmt, x]
20 Shift/Reduce Conflicts
[stmt → if E then stmt • else stmt, x]
[stmt → if E then stmt•, else]