Prev Up Next
Go backward to Some Preliminaries to LR(1) parsing (cont.)
Go up to Top
Go forward to LR(1) Parsing

SLR(1) Parsing

  1. Given the notion of the "follow" set, we can illustrate the use of look-ahead in LR parsing, by considering the simplest form of look-ahead LR parsing -- SLR(1) parsing (that's S for simple).
  2. Recall the grammar
    < S > a < S > b < S >  | 
  3. The LR(0) machine for this grammar contains three states with LR(0) conflicts (two of which were shown above):
  4. For this grammar, a is not in Follow(S). So, we should never reduce using the production < S > if the next "input" symbol is a. Therefore, the three states with LR(0) conflicts really don't have conflicts at all.
  5. In general, we will say that a set of LR(0) items contains an SLR(1) conflict if either:
    1. It contains two reduce items [ N 1 . ] and [ M 2 . ] such that the intersection of Follow(N) and Follow(M) is non-empty, or
    2. It contains a reduce item [ N 1 . ] and a shift item [ M 2 . x 2 ] such that x Follow(N).
  6. If the LR(0) machine for a grammar G contains no states with SLR(1) conflicts we say that G is an SLR(1) grammar.
  7. An SLR(1) parser for an SLR(1) grammar G behaves as follows in state when the next input symbol is "x":

Computer Science 434
Department of Computer Science
Williams College

Prev Up Next