![]() | ![]() | ![]() | LR Parsing |
By way of review:
< E >
< E > + < T > | < T >
< T >
a | ( < E > )
< E > |
![]() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
. . . |
Any prefix of any sentential from in such a derivation that does not extend past the handle should be considered a viable prefix.
< E >
< E > +
< E > + < T >
< E >
< E > +
< E > + a
< E > + ( < E > + < T > ) + a
< E > + (
< E > + ( < E >
< E > + ( < E > +
< E > + ( < E > + < T >
Ssuch that![]()
N
![]()
![]()
1
2
As long as the prefix of a sentential form of a shift-reduce parser is a viable prefix for the associated grammar, things are OK (i.e. we have not yet read past the handle and there is at least some possible remaining input that could form a valid sentential form and some hope of finding a rightmost parse of this sentential form).
We will demonstrate this by explaining how to build a finite state machine that recognizes the set of viable prefixes of a context free grammar.
< S >
a < B > | b < A > | b c
< A >
b
< B >
b | c
< S >
b < A >
< A >
b
< S >
b c
[ Nis an LR(0) item or LR(0) configuration for G if N![]()
1 .
2 ]
For example, the configuration set:
< S >
b . < A >
< S >
b . c
< A >
. b
Ssuch that![]()
N
![]()
![]()
1
2
< S >
a < B > | b < A > | b c
< A >
b
< B >
b | c
[ < S >
![]() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
[ < S >
![]() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
[ < S >
![]() |
[ < S >
a . < B > ]
[ < B >
. b ]
[ < B >
. c ]
![]() | ![]() | ![]() | LR Parsing |