| Top-down Parsing |
). At each such
step one must make two choices:
| < 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 |