Computing Follow(N)TopSLR(1) parsing

SLR(1) parsing

  1. Suppose that we find that after reading some prefix 1 of an input 1 x 2 we end up in a state that contains a reduce item [ N . ] which conflicts with some other item.
  2. We can give the set of symbols that might appear after a non-terminal a name:
    Follow( N ) = { x Vt  | A N x } U { if S N }
  3. 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).
  4. 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).
  5. 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.
  6. 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

Computing Follow(N)TopSLR(1) parsing