A more precise safety after a term.

This commit is contained in:
ceriel 1985-10-02 22:49:16 +00:00
parent 73153b484b
commit b83ab7873e
2 changed files with 24 additions and 14 deletions

View file

@ -713,7 +713,7 @@ do_safes(p,safe) register p_gram p; {
p++; p++;
continue; continue;
case TERMINAL: case TERMINAL:
retval = 2; safe = NOSCANDONE;
break; break;
case TERM : { case TERM : {
register p_term q; register p_term q;
@ -727,7 +727,7 @@ do_safes(p,safe) register p_gram p; {
if (retval == 2 && (!(q->t_flags & TNOSCAN))) { if (retval == 2 && (!(q->t_flags & TNOSCAN))) {
q->t_flags |= TNOSCAN; q->t_flags |= TNOSCAN;
} }
if (rep != FIXED || retval == 0) retval = 1; safe = t_after(rep, i, q->t_flags & TNOSCAN);
break; } break; }
case ALTERNATION : { case ALTERNATION : {
register p_link l; register p_link l;
@ -748,27 +748,30 @@ do_safes(p,safe) register p_gram p; {
return retval; } return retval; }
case NONTERM : { case NONTERM : {
register p_nont n; register p_nont n;
int nsafe; int nsafe, osafe;;
n = &nonterms[g_getnont(p)]; n = &nonterms[g_getnont(p)];
nsafe = getntsafe(n->n_flags); nsafe = getntsafe(n->n_flags);
if (!(n->n_flags & NNOSCAN)) retval = 1; osafe = safe;
else retval = 2; if (!(n->n_flags & NNOSCAN)) {
if (safe == nsafe) break; safe = SCANDONE;
}
else safe = NOSCANDONE;
if (osafe == nsafe) break;
if (nsafe == NOSAFETY) { if (nsafe == NOSAFETY) {
change = 1; change = 1;
setntsafe(&(n->n_flags), safe); setntsafe(&(n->n_flags), osafe);
break; break;
} }
if (safe == NOSCANDONE || nsafe == NOSCANDONE) { if (osafe == NOSCANDONE || nsafe == NOSCANDONE) {
if (nsafe != SCANDONE) { if (nsafe != SCANDONE) {
change = 1; change = 1;
setntsafe(&(n->n_flags), SCANDONE); setntsafe(&(n->n_flags), SCANDONE);
} }
break; break;
} }
if (safe > nsafe) { if (osafe > nsafe) {
setntsafe(&(n->n_flags), safe); setntsafe(&(n->n_flags), osafe);
change = 1; change = 1;
} }
break; } break; }
@ -776,8 +779,8 @@ do_safes(p,safe) register p_gram p; {
return retval; return retval;
} }
p++; p++;
if (retval == 1) safe = SCANDONE; if (safe == NOSCANDONE) retval = 2;
else safe = NOSCANDONE; else retval = 1;
} }
} }
@ -810,3 +813,11 @@ t_safety(rep, count, persistent, safety) {
} }
/* NOTREACHED */ /* NOTREACHED */
} }
t_after(rep, count, noscan) {
if (count == 0 && (rep == STAR || rep == PLUS)) {
return SAFESCANDONE;
}
if (rep == FIXED && noscan) return NOSCANDONE;
return SCANDONE;
}

View file

@ -761,8 +761,7 @@ codeforterm(q,safety,toplevel) register p_term q; {
fputs(c_close, f);/* Close Register ... */ fputs(c_close, f);/* Close Register ... */
} }
} }
if (rep != FIXED || !noscan) return SCANDONE; return t_after(rep, i, noscan);
return NOSCANDONE;
} }
STATIC STATIC