![]() | ![]() | ![]() | Top-down Parsing |
< S >
a < R > | b < S > b < R >
< R >
b < R > | a
Matched terminals | Tail of sentential form | Pending input |
< S > | bbaababa | |
b | < S > b < R > | baababa |
bb | < S > b < R > b < R > | aababa |
bba | < R > b < R > b < R > | ababa |
bbaab | < R > b < R > | aba |
bbaabab | < R > | a |
bbaababa | ![]() | ![]() |
< stmt > |
![]() | if < expr > then < stmt > end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| | if < expr > then < stmt > else < stmt > end |
< stmt > |
![]() | if < expr > then < stmt > < iftail > | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
< iftail > |
![]() | else < stmt > end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
A grammar with these two properties is said to be an S-grammar. Any S-grammar is LL(1).
< S >
a < R > | b < S > b < R >
< R >
b < R > | a
procedure R; if ch = 'b' then getnextchar; R; else if ch = 'a' then getnextchar; else error end end R; procedure S; if ch = 'a' then getnextchar; R; else if ch = 'b' then getnextchar; S; if ch = 'b' then getnextchar; else error; end; R; end end R
![]() | ![]() | ![]() | Top-down Parsing |