SLR(1) parsing
- 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.
- If we decide to reduce using the production in this item,
we are basically assuming that
S
N x
2

x
2
1 x
2
- That is, we are assuming that there is some sentential form in
which an x can follow an N.
- 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 }
- 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).
- In general, we will say that a set of LR(0) items contains an SLR(1)
conflict if either:
- It contains two reduce items [ N
1 . ] and
[ M
2 . ] such that the intersection of
Follow(N) and Follow(M) is non-empty, or
- It contains a reduce item [ N
1 . ] and
a shift item [ M
2 . x
2 ] such that
x
Follow(N).
- 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.
- An SLR(1) parser for an SLR(1) grammar G behaves as follows in state
when the next input symbol is "x":
- reduce using production N
if
[ N
. ] 
, and
x
Follow(N).
- shift in next input if
contains one or more items of the form
[ N
. x
].
- error otherwise.
Computer Science 434
Department of Computer Science
Williams College