[Instructions] [Search] [Current] [News] [Syllabus] [Handouts] [Outlines] [Assignments]
Held Monday, September 21, 1998
Notes
function parseN(TokenList tl) {
switch (tl.head) {
case S1:
code for rhs one;
break;
case S2:
code for rhs two;
break;
...
default:
error();
}
} // parseN
S's should be the symbols that
start the right-hand-sides.
function first(s1 ... sn) {
if (isToken(s1)) {
return setOf(s1);
}
else {
tmp = First(s1);
if (Nullable(s1)) {
return union(tmp, first(s2 ... sn))
}
}
} // first
for each nonterminal N, First(N) = emptySet();
repeat
for each production N ::= RHS
First(N) = union(First(N), first(RHS))
end for
until no changes are made
function nullable(s1 ... sn) {
// The empty string can derive the empty string
if (n == 0) {
return true;
}
// If we begin with a token, we're not nullable
if (isToken(s1)) {
return false;
}
// Otherwise, we begin with a nonterminal. That nonterminal must
// be nullable, as must the rest of the sequence.
else {
return Nullable(s1) &&
nullable(s2..sn);
}
} // nullable
foreach nonterminal N, Nullable(N) = false
repeat
for each production N := RHS
if nullable(RHS) {
Nullable(N) = true;
}
end for
until no changes are made
Back to An Expression Grammar. On to Predictive parsing, continued.
History
[Instructions] [Search] [Current] [News] [Syllabus] [Handouts] [Outlines] [Assignments]
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
Source text last modified Mon Sep 28 11:15:40 1998.
This page generated on Mon Sep 28 11:31:40 1998 by SiteWeaver.
Contact our webmaster at rebelsky@math.grin.edu