From b83ab7873e4db94847f338fa620eb752210066f4 Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 2 Oct 1985 22:49:16 +0000 Subject: [PATCH] A more precise safety after a term. --- util/LLgen/src/compute.c | 35 +++++++++++++++++++++++------------ util/LLgen/src/gencode.c | 3 +-- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/util/LLgen/src/compute.c b/util/LLgen/src/compute.c index 04a1e36b7..9c2c66dec 100644 --- a/util/LLgen/src/compute.c +++ b/util/LLgen/src/compute.c @@ -713,7 +713,7 @@ do_safes(p,safe) register p_gram p; { p++; continue; case TERMINAL: - retval = 2; + safe = NOSCANDONE; break; case TERM : { register p_term q; @@ -727,7 +727,7 @@ do_safes(p,safe) register p_gram p; { if (retval == 2 && (!(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; } case ALTERNATION : { register p_link l; @@ -748,27 +748,30 @@ do_safes(p,safe) register p_gram p; { return retval; } case NONTERM : { register p_nont n; - int nsafe; + int nsafe, osafe;; n = &nonterms[g_getnont(p)]; nsafe = getntsafe(n->n_flags); - if (!(n->n_flags & NNOSCAN)) retval = 1; - else retval = 2; - if (safe == nsafe) break; + osafe = safe; + if (!(n->n_flags & NNOSCAN)) { + safe = SCANDONE; + } + else safe = NOSCANDONE; + if (osafe == nsafe) break; if (nsafe == NOSAFETY) { change = 1; - setntsafe(&(n->n_flags), safe); + setntsafe(&(n->n_flags), osafe); break; } - if (safe == NOSCANDONE || nsafe == NOSCANDONE) { + if (osafe == NOSCANDONE || nsafe == NOSCANDONE) { if (nsafe != SCANDONE) { change = 1; setntsafe(&(n->n_flags), SCANDONE); } break; } - if (safe > nsafe) { - setntsafe(&(n->n_flags), safe); + if (osafe > nsafe) { + setntsafe(&(n->n_flags), osafe); change = 1; } break; } @@ -776,8 +779,8 @@ do_safes(p,safe) register p_gram p; { return retval; } p++; - if (retval == 1) safe = SCANDONE; - else safe = NOSCANDONE; + if (safe == NOSCANDONE) retval = 2; + else retval = 1; } } @@ -810,3 +813,11 @@ t_safety(rep, count, persistent, safety) { } /* NOTREACHED */ } + +t_after(rep, count, noscan) { + if (count == 0 && (rep == STAR || rep == PLUS)) { + return SAFESCANDONE; + } + if (rep == FIXED && noscan) return NOSCANDONE; + return SCANDONE; +} diff --git a/util/LLgen/src/gencode.c b/util/LLgen/src/gencode.c index 260f776bd..e3fe33dda 100644 --- a/util/LLgen/src/gencode.c +++ b/util/LLgen/src/gencode.c @@ -761,8 +761,7 @@ codeforterm(q,safety,toplevel) register p_term q; { fputs(c_close, f);/* Close Register ... */ } } - if (rep != FIXED || !noscan) return SCANDONE; - return NOSCANDONE; + return t_after(rep, i, noscan); } STATIC