Today in CS362: Shift-Reduce Parsing, Concluded Missing Mark, Nathan Admin * Do small tasks immediately * Parser delayed until after break * Class ends early Overview * Review * Using LR(0) tables * SLR parsers * LR(1) parsers * Done Building LR(0) parsing tables/automata. Each state in an LR(0) autom. is a collection of extended productions. Each extended production is a production augmented by a note as to postition in RHS Transitions are labeled by both nonterminals and terminals How to use an LR(0) automataon Push start state repeat look at the state at the top of the stack and the current input symbol if the state on the top of the stack contains an ep with a complete RHS, then REDUCE: pop the RHS off the stack s1 = top of the stack // a state, s1 push LHS on the stack push goto(s1,LHS) on the stack otherwise, // follow the edge labeled by the input symbol SHIFT push current input symbol on stack push goto(old-top,input-symbol) on stack advance input until either (a) The state on top of the stack contains [S' -> S $ .] ACCEPT (b) The state on top of the stack contains no eps. REJECT A few potential problems: (1) In some states, you might be tempted to shift or reduce. Which do you do? SHIFT-REDUCE conflict (a) LR(0) soloution: reduce (b) "Fix" the grammar (c) Reduce only when the next symbol is in Follow(LHS) This modification to LR(0) is called SLR (2) In some states, you might have choices of two things to reduce REDUCE-REDUCE conflict (a) "Fix" the grammar b/c it's probably ambiguous (3) Can you have a SHIFT-SHIFT conflict? NO SLR has problems on some grammars b/c over aggressive in using Follow LR(1): A better way of computing more restrictive follows