CS453 LR(1), LALR, AMBIGUITY
CS453 Shift-Reduce Cont' 1
CS453 LR(1), LALR, AMBIGUITY CS453 Shift-Reduce Cont' 1 LR(1), - - PowerPoint PPT Presentation
CS453 LR(1), LALR, AMBIGUITY CS453 Shift-Reduce Cont' 1 LR(1), LALR, Ambiguity The plan: Shift reduce parsing LR(1) and LALR Ambiguous grammars - Precedence and associativity rules - Dangling else Java-cup precedence and associativity
CS453 Shift-Reduce Cont' 1
CS453 Shift-Reduce Cont' 2
The plan: Shift reduce parsing LR(1) and LALR Ambiguous grammars
Java-cup precedence and associativity declarations Shift Reduce conflict in dangling else
Let’s build the SLR parse table:
CS453 Shift-Reduce Cont' 3
x * = $ S V E 1 s5 s6 g2 g3 g4 2 a 3 s7,r3 4 r2 5 r4 r4 6 s5 s6 g9 g8 7 s5 s6 g9 g10 8 r5 r5 9 r3 r3 10 r1 r1
CS453 Shift-Reduce Cont' 4
CS453 Shift-Reduce Cont' 5
CS453 Shift-Reduce Cont' 6
CS453 Shift-Reduce Cont' 7
CS453 Shift-Reduce Cont' 8
CS453 Shift-Reduce Cont' 9
0: S‘à E$ 1: Eà E+E 2: Eà E*E 3: Eà (E) 4: Eà id
CS453 Shift-Reduce Cont' 10
0: S‘à E$ 1: Eà E^E 2: Eàid // ^ for exponent
CS453 Shift-Reduce Cont' 11
1: S à if c S else S 2: S à if c S 3: S à other abstracted to: 1: Sà i S e S 2: i S 3: o
CS453 Shift-Reduce Cont' 12
1: EàE+E 2: E à ( byte ) E 3: E à ( E ) 4: E à id
CS453 Shift-Reduce Cont' 13