summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Carbonneaux2015-03-04 16:56:35 -0500
committerQuentin Carbonneaux2015-03-04 16:56:35 -0500
commit1d0c341f1a68a11bef37ebc711b6fe82827c85be (patch)
tree4e46a130d306d685385608af500f48926ae2d5e9
parent10682053c0a5ad56de16e4bd608b36999cd39fda (diff)
improve first interface
-rw-r--r--miniyacc.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/miniyacc.c b/miniyacc.c
index 668ebc8..e3a1bb6 100644
--- a/miniyacc.c
+++ b/miniyacc.c
@@ -177,16 +177,15 @@ tsunion(TSet *tsa, TSet *tsb)
}
void
-first(TSet *ts, Sym *stnc, Sym last)
+first(TSet *ts, Sym *stnc, TSet *last)
{
Sym f;
f = stnc[0];
if (f == S) {
- if (last==S)
- return;
- assert(last<ntk);
- f = last;
+ if (last)
+ tsunion(ts, last);
+ return;
}
if (f < ntk) {
SetBit(ts->t, f);
@@ -217,7 +216,7 @@ ginit()
i->nul = 1;
nonul:
tszero(&ts);
- first(&ts, r->rhs, S);
+ first(&ts, r->rhs, 0);
chg |= tsunion(&i->fst, &ts);
}
} while (chg);
@@ -237,7 +236,7 @@ tcmp(Term *a, Term *b)
int
tcmpv(const void *a, const void *b)
{
- return tcmp((Term *)a, (Term *) b);
+ return tcmp((Term *)a, (Term *)b);
}
int
@@ -261,12 +260,13 @@ iclose(Item *i)
{
Rule *r;
Term *t, t1;
- Sym s, *rem, l;
+ Sym s, *rem;
int chg, n;
do {
chg = 0;
- for (n=0, t=i->ts; n<i->nt; n++, t++) {
+ for (n=0; n<i->nt; n++) {
+ t = &i->ts[n];
rem = &t->rule->rhs[t->dot];
s = *rem++;
if (s < ntk || s == S)
@@ -274,11 +274,8 @@ iclose(Item *i)
r = rfind(s);
if (!r)
die("some non-terminals are not defined");
- l = -1;
tszero(&t1.lk);
- for (l=0; l<ntk; l++)
- if (GetBit(t->lk.t, l))
- first(&t1.lk, rem, l);
+ first(&t1.lk, rem, &t->lk);
for (; r-rs<nrl && r->lhs==s; r++) {
t1.rule = r;
t1.dot = 0;