some bug fixes

This commit is contained in:
ceriel 1987-05-12 18:23:09 +00:00
parent debba57b43
commit 985a52b415
13 changed files with 172 additions and 119 deletions

View file

@ -28,19 +28,18 @@
# ifndef NORCSID # ifndef NORCSID
static string rcsid = "$Header$"; static string rcsid = "$Header$";
# endif # endif
p_mem alloc(), new_mem(); p_mem alloc(), ralloc();
string store(); string store();
p_gram search(); p_gram search();
static int nparams; /* parameter count for nonterminals */ static int nparams; /* parameter count for nonterminals */
static int acount; /* count #of global actions */ static int acount; /* count #of global actions */
static t_info term_info,
link_info;
static p_order order, static p_order order,
maxorder; maxorder;
static p_term t_list;
static int t_cnt;
/* Here are defined : */ /* Here are defined : */
extern a_init();
STATIC p_order neworder(); STATIC p_order neworder();
STATIC copyact(); STATIC copyact();
STATIC mkalt(); STATIC mkalt();
@ -48,14 +47,6 @@ STATIC mkterm();
STATIC p_gram copyrule(); STATIC p_gram copyrule();
/* and of course LLparse() */ /* and of course LLparse() */
a_init() {
term_info.i_esize = sizeof (t_term);
term_info.i_incr = 100;
link_info.i_esize = sizeof (t_link);
link_info.i_incr = 100;
name_init();
}
STATIC p_order STATIC p_order
neworder(index) { neworder(index) {
register p_order po; register p_order po;
@ -111,7 +102,7 @@ def { register string p; }
temp = search(NONTERM,lextoken.t_string,BOTH); temp = search(NONTERM,lextoken.t_string,BOTH);
ff = (p_start) alloc(sizeof(t_start)); ff = (p_start) alloc(sizeof(t_start));
ff->ff_nont = g_getnont(temp); ff->ff_nont = g_getcont(temp);
ff->ff_name = p; ff->ff_name = p;
ff->ff_next = start; ff->ff_next = start;
start = ff; start = ff;
@ -155,7 +146,7 @@ rule { register p_nont p;
* grammar for a production rule * grammar for a production rule
*/ */
C_IDENT { temp = search(NONTERM,lextoken.t_string,BOTH); C_IDENT { temp = search(NONTERM,lextoken.t_string,BOTH);
p = &nonterms[g_getnont(temp)]; p = &nonterms[g_getcont(temp)];
if (p->n_rule) { if (p->n_rule) {
error(linecount, error(linecount,
"nonterminal %s already defined", lextoken.t_string); "nonterminal %s already defined", lextoken.t_string);
@ -185,7 +176,7 @@ rule { register p_nont p;
* Do not use p->n_rule now! The nonterms array * Do not use p->n_rule now! The nonterms array
* might have been re-allocated. * might have been re-allocated.
*/ */
{ nonterms[g_getnont(temp)].n_rule = rr;} { nonterms[g_getcont(temp)].n_rule = rr;}
; ;
action(int n;) action(int n;)
@ -205,8 +196,9 @@ productions(p_gram *p;)
int conflres = 0; int conflres = 0;
int t = 0; int t = 0;
int haddefault = 0; int haddefault = 0;
t_gram alts[100]; p_gram alts = (p_gram) alloc(200 * sizeof(t_gram));
register p_gram p_alts = alts; register p_gram p_alts = alts;
unsigned n_alts = 200;
int o_lc, n_lc; int o_lc, n_lc;
} : } :
{ o_lc = linecount; } { o_lc = linecount; }
@ -215,9 +207,12 @@ productions(p_gram *p;)
[ [
[ '|' { n_lc = linecount; } [ '|' { n_lc = linecount; }
simpleproduction(&prod,&t) simpleproduction(&prod,&t)
{ if (p_alts - alts >= 97) { { if (p_alts - alts == n_alts) {
error(n_lc,"Too many alternatives"); alts = (p_gram) ralloc(
p_alts = alts; (p_mem) alts,
(n_alts+100)*sizeof(t_gram));
p_alts = alts + n_alts;
n_alts += 100;
} }
if (t & DEF) { if (t & DEF) {
if (haddefault) { if (haddefault) {
@ -253,6 +248,7 @@ productions(p_gram *p;)
*/ */
} }
] ]
{ free((p_mem) alts); }
; ;
{ {
@ -261,25 +257,32 @@ mkalt(prod,condition,lc,res) p_gram prod; register p_gram res; {
/* /*
* Create an alternation and initialise it. * Create an alternation and initialise it.
*/ */
register int hulp;
register p_link l; register p_link l;
static p_link list;
static int cnt;
l = (p_link) new_mem(&link_info); if (! cnt) {
links = (p_link) link_info.i_ptr; cnt = 50;
hulp = l - links; list = (p_link) alloc(50 * sizeof(t_link));
}
cnt--;
l = list++;
l->l_rule = prod; l->l_rule = prod;
l->l_flag = condition; l->l_flag = condition;
g_setcont(res,hulp); g_setlink(res,l);
g_settype(res,ALTERNATION); g_settype(res,ALTERNATION);
res->g_lineno = lc; res->g_lineno = lc;
nalts++;
} }
} }
simpleproduction(p_gram *p; register int *conflres;) simpleproduction(p_gram *p; register int *conflres;)
{ t_gram rule[100]; { p_gram rule = (p_gram) alloc(200 * sizeof(t_gram));
unsigned n_rule = 200;
t_gram elem; t_gram elem;
register p_gram p_rule = rule; register p_gram p_rule = rule;
int cnt, kind; int cnt, kind;
int termdeleted = 0;
} : } :
[ C_DEFAULT { *conflres = DEF; } [ C_DEFAULT { *conflres = DEF; }
]? ]?
@ -292,9 +295,12 @@ simpleproduction(p_gram *p; register int *conflres;)
| C_AVOID { *conflres |= AVOIDING; } | C_AVOID { *conflres |= AVOIDING; }
]? ]?
[ %persistent elem(&elem) [ %persistent elem(&elem)
{ if (p_rule - rule >= 98) { { if (p_rule - rule >= n_rule - 1) {
error(linecount,"Production too long"); rule = (p_gram) ralloc(
p_rule = rule; (p_mem) rule,
(n_rule+100)*sizeof(t_gram));
p_rule = rule + n_rule - 1;
n_rule += 100;
} }
kind = FIXED; kind = FIXED;
cnt = 0; cnt = 0;
@ -309,10 +315,37 @@ simpleproduction(p_gram *p; register int *conflres;)
&elem); &elem);
} }
} }
]? { if (g_gettype(&elem) == TERM) { |
{ if (g_gettype(&elem) == TERM) {
register p_term q = g_getterm(&elem);
if (g_gettype(q->t_rule) != ALTERNATION &&
g_gettype(q->t_rule) != EORULE) {
while (g_gettype(q->t_rule) != EORULE) {
*p_rule++ = *q->t_rule++;
if (p_rule - rule >= n_rule - 1) {
rule = (p_gram) ralloc(
(p_mem) rule,
(n_rule+100)*sizeof(t_gram));
p_rule = rule + n_rule - 1;
n_rule += 100;
}
}
elem = *--(q->t_rule);
p_rule--;
if (q == t_list - 1) {
t_list--;
nterms--;
t_cnt++;
}
termdeleted = 1;
}
}
}
] { if (!termdeleted && g_gettype(&elem) == TERM) {
register p_term q; register p_term q;
q = &terms[g_getcont(&elem)]; q = g_getterm(&elem);
r_setkind(q,kind); r_setkind(q,kind);
r_setnum(q,cnt); r_setnum(q,cnt);
if ((q->t_flags & RESOLVER) && if ((q->t_flags & RESOLVER) &&
@ -339,40 +372,44 @@ simpleproduction(p_gram *p; register int *conflres;)
*p = 0; *p = 0;
if (g_gettype(&rule[0]) == TERM && if (g_gettype(&rule[0]) == TERM &&
p_rule-rule == 1) { p_rule-rule == 1) {
q = &terms[g_getcont(&rule[0])]; q = g_getterm(&rule[0]);
if (r_getkind(q) == FIXED && if (r_getkind(q) == FIXED &&
r_getnum(q) == 0) { r_getnum(q) == 0) {
*p = q->t_rule; *p = q->t_rule;
} }
} }
if (!*p) *p = copyrule(rule,p_rule-rule+1); if (!*p) *p = copyrule(rule,p_rule-rule+1);
free((p_mem) rule);
} }
; ;
{ {
STATIC STATIC
mkterm(prod,flags,lc, result) p_gram prod; register p_gram result; { mkterm(prod,flags,lc,result) p_gram prod; register p_gram result; {
/* /*
* Create a term, initialise it and return * Create a term, initialise it and return
* a grammar element containing it * a grammar element containing it
*/ */
register p_term q; register p_term q;
unsigned hulp;
q = (p_term) new_mem(&term_info); if (! t_cnt) {
terms = (p_term) term_info.i_ptr; t_cnt = 50;
hulp = q - terms; t_list = (p_term) alloc(50 * sizeof(t_term));
}
t_cnt--;
q = t_list++;
q->t_rule = prod; q->t_rule = prod;
q->t_contains = 0; q->t_contains = 0;
q->t_flags = flags; q->t_flags = flags;
g_settype(result,TERM); g_settype(result,TERM);
g_setcont(result,hulp); g_setterm(result,q);
result->g_lineno = lc; result->g_lineno = lc;
nterms++;
} }
} }
elem (register p_gram pres;) elem (register p_gram pres;)
{ register short t = 0; { register int t = 0;
p_gram p1; p_gram p1;
int ln; int ln;
p_gram pe; p_gram pe;
@ -456,7 +493,7 @@ firsts { register string p; }
temp = search(NONTERM,lextoken.t_string,BOTH); temp = search(NONTERM,lextoken.t_string,BOTH);
ff = (p_first) alloc(sizeof(t_first)); ff = (p_first) alloc(sizeof(t_first));
ff->ff_nont = g_getnont(temp); ff->ff_nont = g_getcont(temp);
ff->ff_name = p; ff->ff_name = p;
ff->ff_next = pfile->f_firsts; ff->ff_next = pfile->f_firsts;
pfile->f_firsts = ff; pfile->f_firsts = ff;

View file

@ -1,7 +1,9 @@
# $Header$ # $Header$
EMHOME=../../..
PROF= PROF=
LLOPT= # -vvv -x LLOPT= # -vvv -x
CFLAGS=-O -DNDEBUG $(PROF) INCLUDES = -I$(EMHOME)/h
CFLAGS=-O -DNDEBUG $(INCLUDES) $(PROF)
LDFLAGS=-i LDFLAGS=-i
OBJECTS = main.o gencode.o compute.o LLgen.o tokens.o check.o reach.o global.o name.o sets.o Lpars.o alloc.o machdep.o cclass.o OBJECTS = main.o gencode.o compute.o LLgen.o tokens.o check.o reach.o global.o name.o sets.o Lpars.o alloc.o machdep.o cclass.o
CFILES = main.c gencode.c compute.c LLgen.c tokens.c check.c reach.c global.c name.c sets.c Lpars.c alloc.c machdep.c cclass.c CFILES = main.c gencode.c compute.c LLgen.c tokens.c check.c reach.c global.c name.c sets.c Lpars.c alloc.c machdep.c cclass.c
@ -25,7 +27,7 @@ pr :
@pr $(FILES) ../lib/rec ../lib/incl Makefile @pr $(FILES) ../lib/rec ../lib/incl Makefile
lint: lint:
$(LINT) $(CFILES) $(LINT) $(INCLUDES) $(CFILES)
clean: clean:
-rm -f *.o LL.temp LL.xxx LL.output LLgen -rm -f *.o LL.temp LL.xxx LL.output LLgen

View file

@ -19,6 +19,7 @@
# include "types.h" # include "types.h"
# include "extern.h" # include "extern.h"
# include <local.h>
# ifndef NORCSID # ifndef NORCSID
static string rcsid = "$Header$"; static string rcsid = "$Header$";
@ -67,7 +68,13 @@ new_mem(p) register p_info p; {
if (p->i_max >= p->i_top) { /* No more free elements */ if (p->i_max >= p->i_top) { /* No more free elements */
sz = p->i_size; sz = p->i_size;
#if BIGMACHINE
p->i_size += p->i_size;
if (! p->i_size)
p->i_size += p->i_incr * p->i_esize; p->i_size += p->i_incr * p->i_esize;
#else
p->i_size += p->i_incr * p->i_esize;
#endif
p->i_ptr = !p->i_ptr ? p->i_ptr = !p->i_ptr ?
alloc(p->i_size) : alloc(p->i_size) :
ralloc(p->i_ptr, p->i_size); ralloc(p->i_ptr, p->i_size);

View file

@ -186,7 +186,7 @@ check(p) register p_gram p; {
case NONTERM : { case NONTERM : {
register p_nont n; register p_nont n;
n = &nonterms[g_getnont(p)]; n = &nonterms[g_getcont(p)];
if (g_getnpar(p) != getntparams(n)) { if (g_getnpar(p) != getntparams(n)) {
error(p->g_lineno, error(p->g_lineno,
"Call of %s : parameter count mismatch", "Call of %s : parameter count mismatch",
@ -196,7 +196,7 @@ check(p) register p_gram p; {
case TERM : { case TERM : {
register p_term q; register p_term q;
q = &terms[g_getcont(p)]; q = g_getterm(p);
retval |= check(q->t_rule); retval |= check(q->t_rule);
if (r_getkind(q) == FIXED) break; if (r_getkind(q) == FIXED) break;
if (setempty(q->t_first)) { if (setempty(q->t_first)) {
@ -237,7 +237,7 @@ check(p) register p_gram p; {
case ALTERNATION : { case ALTERNATION : {
register p_link l; register p_link l;
l = &links[g_getcont(p)]; l = g_getlink(p);
temp = setalloc(); temp = setalloc();
setunion(temp,l->l_symbs); setunion(temp,l->l_symbs);
if(!setintersect(temp,l->l_others)) { if(!setintersect(temp,l->l_others)) {
@ -300,7 +300,7 @@ prrule(p) register p_gram p; {
register p_term q; register p_term q;
register int c; register int c;
q = &terms[g_getcont(p)]; q = g_getterm(p);
if (present) prline("\n"); if (present) prline("\n");
fputs("[ ",f); fputs("[ ",f);
level += 4; level += 4;
@ -347,7 +347,7 @@ prrule(p) register p_gram p; {
case ALTERNATION : { case ALTERNATION : {
register p_link l; register p_link l;
l = &links[g_getcont(p)]; l = g_getlink(p);
if (firstalt) { if (firstalt) {
firstalt = 0; firstalt = 0;
} }
@ -385,7 +385,7 @@ prrule(p) register p_gram p; {
"'%s' " : "%s ", pt->t_string); "'%s' " : "%s ", pt->t_string);
break; } break; }
case NONTERM : case NONTERM :
fprintf(f,"%s ",nonterms[g_getnont(p)].n_name); fprintf(f,"%s ",nonterms[g_getcont(p)].n_name);
break; break;
} }
p++; p++;
@ -428,12 +428,12 @@ resolve(p) register p_gram p; {
case EORULE : case EORULE :
return; return;
case TERM : case TERM :
resolve(terms[g_getcont(p)].t_rule); resolve(g_getterm(p)->t_rule);
break; break;
case ALTERNATION : { case ALTERNATION : {
register p_link l; register p_link l;
l = &links[g_getcont(p)]; l = g_getlink(p);
if (l->l_flag & AVOIDING) { if (l->l_flag & AVOIDING) {
/* /*
* On conflicting symbols, this rule * On conflicting symbols, this rule
@ -462,7 +462,7 @@ propagate(set,p) p_set set; register p_gram p; {
* p will not be chosen. * p will not be chosen.
*/ */
while (g_gettype(p) != EORULE) { while (g_gettype(p) != EORULE) {
setminus(links[g_getcont(p)].l_symbs,set); setminus(g_getlink(p)->l_symbs,set);
p++; p++;
} }
} }

View file

@ -155,7 +155,7 @@ walk(p) register p_gram p; {
case TERM : { case TERM : {
register p_term q; register p_term q;
q = &terms[g_getcont(p)]; q = g_getterm(p);
q->t_first = get_set(); q->t_first = get_set();
q->t_follow = get_set(); q->t_follow = get_set();
walk(q->t_rule); walk(q->t_rule);
@ -163,7 +163,7 @@ walk(p) register p_gram p; {
case ALTERNATION : { case ALTERNATION : {
register p_link l; register p_link l;
l = &links[g_getcont(p)]; l = g_getlink(p);
l->l_symbs = get_set(); l->l_symbs = get_set();
l->l_others = get_set(); l->l_others = get_set();
walk(l->l_rule); walk(l->l_rule);
@ -209,19 +209,19 @@ empty(p) register p_gram p; {
case TERM : { case TERM : {
register p_term q; register p_term q;
q = &terms[g_getcont(p)]; q = g_getterm(p);
if (r_getkind(q) == STAR if (r_getkind(q) == STAR
|| r_getkind(q) == OPT || r_getkind(q) == OPT
|| empty(q->t_rule) ) break; || empty(q->t_rule) ) break;
return 0; } return 0; }
case ALTERNATION : case ALTERNATION :
if (empty(links[g_getcont(p)].l_rule)) { if (empty(g_getlink(p)->l_rule)) {
return 1; return 1;
} }
if (g_gettype(p+1) == EORULE) return 0; if (g_gettype(p+1) == EORULE) return 0;
break; break;
case NONTERM : case NONTERM :
if (nonterms[g_getnont(p)].n_flags & EMPTY) { if (nonterms[g_getcont(p)].n_flags & EMPTY) {
break; break;
} }
/* Fall through */ /* Fall through */
@ -262,7 +262,7 @@ first(setp,p,flag) p_set setp; register p_gram p; {
case TERM : { case TERM : {
register p_term q; register p_term q;
q = &terms[g_getcont(p)]; q = g_getterm(p);
if (flag == 0) { if (flag == 0) {
if (first(q->t_first,q->t_rule,0))/*nothing*/; if (first(q->t_first,q->t_rule,0))/*nothing*/;
} }
@ -275,7 +275,7 @@ first(setp,p,flag) p_set setp; register p_gram p; {
case ALTERNATION : { case ALTERNATION : {
register p_link l; register p_link l;
l = &links[g_getcont(p)]; l = g_getlink(p);
if (flag == 0) { if (flag == 0) {
if (first(l->l_symbs,l->l_rule,0))/*nothing*/; if (first(l->l_symbs,l->l_rule,0))/*nothing*/;
} }
@ -299,10 +299,10 @@ first(setp,p,flag) p_set setp; register p_gram p; {
case NONTERM : { case NONTERM : {
register p_nont n; register p_nont n;
n = &nonterms[g_getnont(p)]; n = &nonterms[g_getcont(p)];
if (noenter == 0) { if (noenter == 0) {
s |= setunion(setp,n->n_first); s |= setunion(setp,n->n_first);
if (ntneeded) NTPUTIN(setp,g_getnont(p)); if (ntneeded) NTPUTIN(setp,g_getcont(p));
} }
p++; p++;
if (n->n_flags & EMPTY) continue; if (n->n_flags & EMPTY) continue;
@ -338,7 +338,7 @@ follow(setp,p) p_set setp; register p_gram p; {
case TERM : { case TERM : {
register p_term q; register p_term q;
q = &terms[g_getcont(p)]; q = g_getterm(p);
if (empty(p+1)) { if (empty(p+1)) {
/* /*
* If what follows the term can be empty, * If what follows the term can be empty,
@ -372,12 +372,12 @@ follow(setp,p) p_set setp; register p_gram p; {
/* /*
* Just propagate setp * Just propagate setp
*/ */
s |= follow(setp,links[g_getcont(p)].l_rule); s |= follow(setp,g_getlink(p)->l_rule);
break; break;
case NONTERM : { case NONTERM : {
register p_nont n; register p_nont n;
n = &nonterms[g_getnont(p)]; n = &nonterms[g_getcont(p)];
s |= first(n->n_follow,p+1,1); s |= first(n->n_follow,p+1,1);
if (empty(p+1)) { if (empty(p+1)) {
/* /*
@ -407,7 +407,7 @@ co_dirsymb(setp,p) p_set setp; register p_gram p; {
case TERM : { case TERM : {
register p_term q; register p_term q;
q = &terms[g_getcont(p)]; q = g_getterm(p);
co_dirsymb(q->t_follow,q->t_rule); co_dirsymb(q->t_follow,q->t_rule);
break; } break; }
case ALTERNATION : { case ALTERNATION : {
@ -416,7 +416,7 @@ co_dirsymb(setp,p) p_set setp; register p_gram p; {
* Save first alternative * Save first alternative
*/ */
if (!s) s = p; if (!s) s = p;
l = &links[g_getcont(p)]; l = g_getlink(p);
co_dirsymb(setp,l->l_rule); co_dirsymb(setp,l->l_rule);
if (empty(l->l_rule)) { if (empty(l->l_rule)) {
/* /*
@ -449,9 +449,9 @@ co_others(p) register p_gram p; {
*/ */
register p_link l1,l2; register p_link l1,l2;
l1 = &links[g_getcont(p)]; l1 = g_getlink(p);
p++; p++;
l2 = &links[g_getcont(p)]; l2 = g_getlink(p);
setunion(l1->l_others,l2->l_symbs); setunion(l1->l_others,l2->l_symbs);
if (g_gettype(p+1) != EORULE) { if (g_gettype(p+1) != EORULE) {
/* /*
@ -493,8 +493,6 @@ do_lengthcomp() {
*/ */
register p_length pl; register p_length pl;
register p_nont p; register p_nont p;
register p_start st;
int change = 1;
p_mem alloc(); p_mem alloc();
length = (p_length) alloc((unsigned) (nnonterms * sizeof(*length))); length = (p_length) alloc((unsigned) (nnonterms * sizeof(*length)));
@ -538,7 +536,7 @@ complength(p,le) register p_gram p; p_length le; {
X.cnt = INFINITY; X.cnt = INFINITY;
X.val = INFINITY; X.val = INFINITY;
while (g_gettype(p) != EORULE) { while (g_gettype(p) != EORULE) {
l = &links[g_getcont(p)]; l = g_getlink(p);
complength(l->l_rule,&i); complength(l->l_rule,&i);
if (l->l_flag & DEF) { if (l->l_flag & DEF) {
X = i; X = i;
@ -557,7 +555,7 @@ complength(p,le) register p_gram p; p_length le; {
case TERM : { case TERM : {
register int rep; register int rep;
q = &terms[g_getcont(p)]; q = g_getterm(p);
rep = r_getkind(q); rep = r_getkind(q);
if ((q->t_flags&PERSISTENT) || if ((q->t_flags&PERSISTENT) ||
rep==FIXED || rep==PLUS) { rep==FIXED || rep==PLUS) {
@ -577,7 +575,7 @@ complength(p,le) register p_gram p; p_length le; {
} }
break; } break; }
case NONTERM : { case NONTERM : {
int nn = g_getnont(p); int nn = g_getcont(p);
register p_length pl = &length[nn]; register p_length pl = &length[nn];
int x = pl->cnt; int x = pl->cnt;
@ -621,7 +619,7 @@ setdefaults(p) register p_gram p; {
case EORULE: case EORULE:
return; return;
case TERM: case TERM:
setdefaults(terms[g_getcont(p)].t_rule); setdefaults(g_getterm(p)->t_rule);
break; break;
case ALTERNATION: { case ALTERNATION: {
register p_link l, l1; register p_link l, l1;
@ -630,9 +628,9 @@ setdefaults(p) register p_gram p; {
count.cnt = INFINITY; count.cnt = INFINITY;
count.val = INFINITY; count.val = INFINITY;
l1 = &links[g_getcont(p)]; l1 = g_getlink(p);
do { do {
l = &links[g_getcont(p)]; l = g_getlink(p);
complength(l->l_rule,&i); complength(l->l_rule,&i);
if (l->l_flag & DEF) temp = 1; if (l->l_flag & DEF) temp = 1;
temp1 = compare(&i, &count); temp1 = compare(&i, &count);
@ -696,7 +694,7 @@ contains(p,set) register p_gram p; register p_set set; {
register p_term q; register p_term q;
int rep; int rep;
q = &terms[g_getcont(p)]; q = g_getterm(p);
rep = r_getkind(q); rep = r_getkind(q);
if ((q->t_flags & PERSISTENT) || if ((q->t_flags & PERSISTENT) ||
rep == PLUS || rep == FIXED) { rep == PLUS || rep == FIXED) {
@ -723,17 +721,17 @@ contains(p,set) register p_gram p; register p_set set; {
case NONTERM : { case NONTERM : {
register p_nont n; register p_nont n;
n = &nonterms[g_getnont(p)]; n = &nonterms[g_getcont(p)];
do_contains(n); do_contains(n);
if (set) { if (set) {
setunion(set, n->n_contains); setunion(set, n->n_contains);
if (ntneeded) NTPUTIN(set, g_getnont(p)); if (ntneeded) NTPUTIN(set, g_getcont(p));
} }
break; } break; }
case ALTERNATION : { case ALTERNATION : {
register p_link l; register p_link l;
l = &links[g_getcont(p)]; l = g_getlink(p);
contains(l->l_rule, contains(l->l_rule,
(l->l_flag & DEF) ? set : (p_set) 0); (l->l_flag & DEF) ? set : (p_set) 0);
break; } break; }
@ -792,7 +790,7 @@ do_safes(p,safe,ch) register p_gram p; register int *ch; {
register p_term q; register p_term q;
int i,rep; int i,rep;
q = &terms[g_getcont(p)]; q = g_getterm(p);
i = r_getnum(q); i = r_getnum(q);
rep = r_getkind(q); rep = r_getkind(q);
retval = do_safes(q->t_rule, retval = do_safes(q->t_rule,
@ -806,7 +804,7 @@ do_safes(p,safe,ch) register p_gram p; register int *ch; {
f = 1; f = 1;
while (g_gettype(p) == ALTERNATION) { while (g_gettype(p) == ALTERNATION) {
l = &links[g_getcont(p)]; l = g_getlink(p);
if (safe > SAFE && (l->l_flag & DEF)) { if (safe > SAFE && (l->l_flag & DEF)) {
i = do_safes(l->l_rule,SAFESCANDONE,ch); i = do_safes(l->l_rule,SAFESCANDONE,ch);
} }
@ -827,7 +825,7 @@ do_safes(p,safe,ch) register p_gram p; register int *ch; {
register p_nont n; register p_nont n;
register int nsafe, osafe; register int nsafe, osafe;
n = &nonterms[g_getnont(p)]; n = &nonterms[g_getcont(p)];
nsafe = getntsafe(n); nsafe = getntsafe(n);
osafe = safe; osafe = safe;
safe = getntout(n); safe = getntout(n);

View file

@ -34,6 +34,8 @@
extern char ltext[]; /* input buffer */ extern char ltext[]; /* input buffer */
extern int nnonterms; /* number of nonterminals */ extern int nnonterms; /* number of nonterminals */
extern int ntokens; /* number of terminals */ extern int ntokens; /* number of terminals */
extern int nterms; /* number of terms */
extern int nalts; /* number of alternatives */
extern p_start start; /* will contain startsymbols */ extern p_start start; /* will contain startsymbols */
extern int linecount; /* line number */ extern int linecount; /* line number */
extern int assval; /* to create difference between literals extern int assval; /* to create difference between literals
@ -70,5 +72,3 @@ extern string LLgenid; /* LLgen identification string */
extern t_token lextoken; /* the current token */ extern t_token lextoken; /* the current token */
extern int nerrors; extern int nerrors;
extern string rec_file, incl_file; extern string rec_file, incl_file;
extern p_term terms;
extern p_link links;

View file

@ -454,7 +454,7 @@ rulecode(p,safety,mustscan,mustpop) register p_gram p; {
safety = NOSCANDONE; safety = NOSCANDONE;
break; } break; }
case NONTERM : { case NONTERM : {
register p_nont n = &nonterms[g_getnont(p)]; register p_nont n = &nonterms[g_getcont(p)];
if (safety == NOSCANDONE && if (safety == NOSCANDONE &&
getntsafe(n) < NOSCANDONE) { getntsafe(n) < NOSCANDONE) {
@ -472,7 +472,7 @@ rulecode(p,safety,mustscan,mustpop) register p_gram p; {
safety = getntout(n); safety = getntout(n);
break; break;
} }
fprintf(f,"L%d_%s(\n",g_getnont(p), n->n_name); fprintf(f,"L%d_%s(\n",g_getcont(p), n->n_name);
if (g_getnpar(p)) { if (g_getnpar(p)) {
controlline(); controlline();
getaction(0); getaction(0);
@ -481,7 +481,7 @@ rulecode(p,safety,mustscan,mustpop) register p_gram p; {
safety = getntout(n); safety = getntout(n);
break; } break; }
case TERM : case TERM :
safety = codeforterm(&terms[g_getcont(p)], safety = codeforterm(g_getterm(p),
safety, safety,
toplevel); toplevel);
break; break;
@ -510,7 +510,7 @@ alternation(p, safety, mustscan, mustpop, lb) register p_gram p; {
p_set setalloc(); p_set setalloc();
assert(safety < NOSCANDONE); assert(safety < NOSCANDONE);
l = &links[g_getcont(p)]; l = g_getlink(p);
hulp = nlabel++; hulp = nlabel++;
hulp1 = nlabel++; hulp1 = nlabel++;
hulp2 = nlabel++; hulp2 = nlabel++;
@ -525,7 +525,7 @@ alternation(p, safety, mustscan, mustpop, lb) register p_gram p; {
} }
fputs("switch(LLcsymb) {\n", f); fputs("switch(LLcsymb) {\n", f);
while (g_gettype(p) != EORULE) { while (g_gettype(p) != EORULE) {
l = &links[g_getcont(p)]; l = g_getlink(p);
if (unsafe && (l->l_flag & DEF)) { if (unsafe && (l->l_flag & DEF)) {
haddefault = 1; haddefault = 1;
fprintf(f, fprintf(f,
@ -569,7 +569,7 @@ alternation(p, safety, mustscan, mustpop, lb) register p_gram p; {
p++; p++;
fprintf(f,"L_%d : ;\n",hulp); fprintf(f,"L_%d : ;\n",hulp);
if (g_gettype(p+1) == EORULE) { if (g_gettype(p+1) == EORULE) {
setminus(links[g_getcont(p)].l_symbs, set); setminus(g_getlink(p)->l_symbs, set);
free((p_mem) set); free((p_mem) set);
continue; continue;
} }
@ -609,7 +609,7 @@ dopush(p,safety,toplevel,pp) register p_gram p; register int *pp; {
register p_term q; register p_term q;
int rep, cnt; int rep, cnt;
q = &terms[g_getcont(p)]; q = g_getterm(p);
rep = r_getkind(q); rep = r_getkind(q);
cnt = r_getnum(q); cnt = r_getnum(q);
if (!(toplevel > 0 && safety <= SAFESCANDONE && if (!(toplevel > 0 && safety <= SAFESCANDONE &&
@ -630,7 +630,7 @@ dopush(p,safety,toplevel,pp) register p_gram p; register int *pp; {
case NONTERM : { case NONTERM : {
register p_nont n; register p_nont n;
n = &nonterms[g_getnont(p)]; n = &nonterms[g_getcont(p)];
if (toplevel == 0 || if (toplevel == 0 ||
(g_gettype(n->n_rule) == ALTERNATION && (g_gettype(n->n_rule) == ALTERNATION &&
getntsafe(n) > SAFESCANDONE)) { getntsafe(n) > SAFESCANDONE)) {

View file

@ -32,6 +32,7 @@ int nnonterms;
p_token tokens; p_token tokens;
p_token maxt; p_token maxt;
int ntokens; int ntokens;
int nterms, nalts;
p_order porder, sorder; p_order porder, sorder;
p_start start; p_start start;
int linecount; int linecount;
@ -60,5 +61,3 @@ string LLgenid = "/* LLgen generated code from source %s */\n";
t_token lextoken; t_token lextoken;
int nerrors; int nerrors;
string rec_file, incl_file; string rec_file, incl_file;
p_link links;
p_term terms;

View file

@ -18,7 +18,7 @@
*/ */
# include "../../../h/em_path.h" # include <em_path.h>
# include "types.h" # include "types.h"
# ifndef NORCSID # ifndef NORCSID

View file

@ -117,7 +117,7 @@ main(argc,argv) register string argv[]; {
fputs("Cannot create temporary\n",stderr); fputs("Cannot create temporary\n",stderr);
exit(1); exit(1);
} }
a_init(); name_init();
readgrammar(argc,argv); readgrammar(argc,argv);
setinit(ntneeded); setinit(ntneeded);
maxnt = &nonterms[nnonterms]; maxnt = &nonterms[nnonterms];
@ -138,6 +138,15 @@ main(argc,argv) register string argv[]; {
else gencode(argc); else gencode(argc);
UNLINK(f_temp); UNLINK(f_temp);
UNLINK(f_pars); UNLINK(f_pars);
if (verbose) {
extern char *sbrk(), *end;
fprintf(stderr, "number of nonterminals: %d\n", nnonterms);
fprintf(stderr, "number of tokens: %d\n", ntokens);
fprintf(stderr, "number of term structures: %d\n", nterms);
fprintf(stderr, "number of alternation structures: %d\n", nalts);
fprintf(stderr, "total memory used: %d\n", sbrk(0) - (char *) &end);
}
exit(0); exit(0);
} }

View file

@ -48,9 +48,9 @@ p_mem new_mem();
name_init() { name_init() {
token_info.i_esize = sizeof (t_token); token_info.i_esize = sizeof (t_token);
token_info.i_incr = 100; token_info.i_incr = 50;
nont_info.i_esize = sizeof (t_nont); nont_info.i_esize = sizeof (t_nont);
nont_info.i_incr = 100; nont_info.i_incr = 50;
search(TERMINAL,"EOFILE",ENTERING); search(TERMINAL,"EOFILE",ENTERING);
} }
@ -233,6 +233,7 @@ search(type,str,option) register string str; {
q->n_contains = 0; q->n_contains = 0;
g_settype(&(p->h_type), NONTERM); g_settype(&(p->h_type), NONTERM);
g_setcont(&(p->h_type), nnonterms); g_setcont(&(p->h_type), nnonterms);
g_setnpar(&(p->h_type), 0);
nnonterms++; nnonterms++;
return &(p->h_type); return &(p->h_type);
} }

View file

@ -97,13 +97,13 @@ reachwalk(p) register p_gram p; {
for (;;) { for (;;) {
switch(g_gettype(p)) { switch(g_gettype(p)) {
case ALTERNATION : case ALTERNATION :
reachwalk(links[g_getcont(p)].l_rule); reachwalk(g_getlink(p)->l_rule);
break; break;
case TERM : case TERM :
reachwalk(terms[g_getcont(p)].t_rule); reachwalk(g_getterm(p)->t_rule);
break; break;
case NONTERM : case NONTERM :
reachable(&nonterms[g_getnont(p)]); reachable(&nonterms[g_getcont(p)]);
break; break;
case EORULE : case EORULE :
return; return;

View file

@ -40,23 +40,21 @@ typedef struct token {
typedef struct gram { typedef struct gram {
short x; /* for lay-out see comment below */ short x; /* for lay-out see comment below */
short g_lineno; /* element found on this line number */ short g_lineno; /* element found on this line number */
union {
int g_index;
struct term * g_term;
struct link * g_link;
} g_i;
} t_gram,*p_gram; } t_gram,*p_gram;
/* /*
* Layout of the field x: * Layout of the field x:
* *
* 15 13 12 9 8 0 * 15 ....... 7 6 ........ 3 2 .... 0
* ------------------------------------------ * -----------------------------------
* | type | nparams | index | * | unused | | nparams | | type |
* ------------------------------------------ * -----------------------------------
* of
* 15 13 12 0
* ------------------------------------------
* | type | index |
* ------------------------------------------
* dependant on type
*/ */
# define UNDEFINED 000777
# define EORULE 00 /* End of (sub)rule */ # define EORULE 00 /* End of (sub)rule */
# define ACTION 01 /* Imbedded action */ # define ACTION 01 /* Imbedded action */
# define NONTERM 02 /* A nonterminal */ # define NONTERM 02 /* A nonterminal */
@ -68,14 +66,16 @@ typedef struct gram {
/* /*
* Access macros for the x-field of a grammar element * Access macros for the x-field of a grammar element
*/ */
# define g_gettype(p) (((p)->x>>13)&07) # define g_gettype(p) ((p)->x&07)
# define g_getcont(p) ((p)->x&017777) # define g_getcont(p) ((p)->g_i.g_index)
# define g_getnont(p) ((p)->x&0777) # define g_getterm(p) ((p)->g_i.g_term)
# define g_getnpar(p) (((p)->x>>9)&017) # define g_getlink(p) ((p)->g_i.g_link)
# define g_settype(p,s) { assert(((unsigned)(s))<=07);(p)->x=((p)->x&017777)|((s)<<13);} # define g_getnpar(p) (((p)->x>>3)&017)
# define g_setcont(p,s) { assert(((unsigned)(s))<=017777);(p)->x=((p)->x&0160000)|(s);} # define g_settype(p,s) { assert(((unsigned)(s))<=07);(p)->x=((p)->x&~07)|(s);}
# define g_setnont(p,s) { assert(((unsigned)(s))<=0777);(p)->x=((p)->x&0177000)|(s);} # define g_setcont(p,s) ((p)->g_i.g_index=(s))
# define g_setnpar(p,s) { assert(((unsigned)(s))<=017);(p)->x=((p)->x&0160777)|((s)<<9);} # define g_setterm(p,s) ((p)->g_i.g_term = (s))
# define g_setlink(p,s) ((p)->g_i.g_link = (s))
# define g_setnpar(p,s) { assert(((unsigned)(s))<=017);(p)->x=((p)->x&~0170)|((s)<<3);}
/* /*
* Some constants to communicate with the symbol table search routine * Some constants to communicate with the symbol table search routine