From b1fdacb99c160c9bc8d57ce054c9a7ddd0fbf696 Mon Sep 17 00:00:00 2001 From: ceriel Date: Fri, 23 Aug 1991 16:23:07 +0000 Subject: [PATCH] relaxed the ;-terminator requirement for parameters --- util/LLgen/src/.distr | 1 - util/LLgen/src/LLgen.g | 28 ++++++++++++---------------- util/LLgen/src/Makefile | 11 +---------- util/LLgen/src/check.c | 2 +- util/LLgen/src/gencode.c | 11 +++++++++-- util/LLgen/src/main.c | 14 ++------------ 6 files changed, 25 insertions(+), 42 deletions(-) diff --git a/util/LLgen/src/.distr b/util/LLgen/src/.distr index 780d5e3fc..ef79b2480 100644 --- a/util/LLgen/src/.distr +++ b/util/LLgen/src/.distr @@ -6,7 +6,6 @@ Lpars.c.dist Lpars.h.dist Makefile alloc.c -assert.h check.c compute.c extern.h diff --git a/util/LLgen/src/LLgen.g b/util/LLgen/src/LLgen.g index c6ba3c99e..cd60745e7 100644 --- a/util/LLgen/src/LLgen.g +++ b/util/LLgen/src/LLgen.g @@ -199,7 +199,7 @@ rule { register p_nont p; acount = 0; p->n_lineno = linecount; } - [ params(2) { p->n_flags |= PARAMS; + [ params { p->n_flags |= PARAMS; if (nparams > 15) { error(linecount,"Too many parameters"); } @@ -462,7 +462,7 @@ elem (register p_gram pres;) C_IDENT { pe = search(UNKNOWN,lextoken.t_string,BOTH); *pres = *pe; } - [ params(0) { if (nparams > 14) { + [ params { if (nparams > 14) { error(linecount,"Too many parameters"); } else g_setnpar(pres,nparams+1); if (g_gettype(pres) == TERMINAL) { @@ -480,8 +480,8 @@ elem (register p_gram pres;) action(1) ; -params(int n;) - : '(' { copyact('(',')',n,0); } +params + : '(' { copyact('(',')',0,0); } ')' ; @@ -541,35 +541,32 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; { /* * Copy an action to file f. Opening bracket is ch1, closing bracket * is ch2. - * If flag = 1, copy opening and closing parameters too. - * If flag = 2, the copy is a parameter declaration copy. - * Give an error message if not ending on a ';' + * If flag != 0, copy opening and closing parameters too. */ + static int id_seen = 0; register FILE *f; register ch; /* Current char */ register match; /* used to read strings */ int saved; /* save linecount */ - int semicolon = 0; f = fact; if (!level) { saved = linecount; + id_seen = 0; nparams = 0; /* count comma's */ putc('\0',f); fprintf(f,"# line %d \"%s\"\n", linecount,f_input); } - if (level || flag == 1) putc(ch1,f); + if (level || flag) putc(ch1,f); for (;;) { ch = input(); + if (c_class[ch] == ISLET) id_seen = 1; if (ch == ch2) { if (!level) unput(ch); - if (level || flag == 1) putc(ch,f); - if ((!level) && flag == 2 && !semicolon) { - error(linecount,"Missing ';'"); - } + if (level || flag) putc(ch,f); + if (id_seen) nparams++; return; } - if (c_class[ch] != ISSPA) semicolon = 0; switch(ch) { case ')': case '}': @@ -596,14 +593,13 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; { ch = '/'; break; case ';': - semicolon = 1; - /* Fall through */ case ',': if (!level) { /* * Only ','s and ';'s on the * outer level are counted */ nparams++; + id_seen = 0; } break; case '\'': diff --git a/util/LLgen/src/Makefile b/util/LLgen/src/Makefile index 839d49c99..ac039d782 100644 --- a/util/LLgen/src/Makefile +++ b/util/LLgen/src/Makefile @@ -7,7 +7,7 @@ CFLAGS=-O -DNDEBUG $(INCLUDES) $(PROF) LDFLAGS= 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 -FILES =types.h tunable.h extern.h io.h sets.h assert.h tokens.g LLgen.g main.c name.c compute.c sets.c gencode.c global.c check.c reach.c alloc.c machdep.c Makefile cclass.c +FILES =types.h tunable.h extern.h io.h sets.h tokens.g LLgen.g main.c name.c compute.c sets.c gencode.c global.c check.c reach.c alloc.c machdep.c Makefile cclass.c GFILES = tokens.g LLgen.g LINT = lint -b -DNDEBUG -DNORCSID @@ -52,7 +52,6 @@ distr: # The next lines are generated automatically # AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO LLgen.o: Lpars.h -LLgen.o: assert.h LLgen.o: cclass.h LLgen.o: extern.h LLgen.o: io.h @@ -61,17 +60,14 @@ Lpars.o: Lpars.h alloc.o: extern.h alloc.o: types.h cclass.o: cclass.h -check.o: assert.h check.o: extern.h check.o: io.h check.o: sets.h check.o: types.h -compute.o: assert.h compute.o: extern.h compute.o: io.h compute.o: sets.h compute.o: types.h -gencode.o: assert.h gencode.o: cclass.h gencode.o: extern.h gencode.o: io.h @@ -82,25 +78,20 @@ global.o: io.h global.o: types.h machdep.o: $(EMHOME)/h/em_path.h machdep.o: types.h -main.o: assert.h main.o: extern.h main.o: io.h main.o: sets.h main.o: types.h -name.o: assert.h name.o: extern.h name.o: io.h name.o: types.h -reach.o: assert.h reach.o: extern.h reach.o: io.h reach.o: types.h -sets.o: assert.h sets.o: extern.h sets.o: sets.h sets.o: types.h tokens.o: Lpars.h -tokens.o: assert.h tokens.o: cclass.h tokens.o: extern.h tokens.o: io.h diff --git a/util/LLgen/src/check.c b/util/LLgen/src/check.c index 3292ac9bf..67a6f0631 100644 --- a/util/LLgen/src/check.c +++ b/util/LLgen/src/check.c @@ -207,7 +207,7 @@ check(p) register p_gram p; { if (empty(q->t_rule)) { q->t_flags |= EMPTYTERM; retval = 1; - error(p->g_lineno, "Term produces empty"); + error(p->g_lineno, "Term with variable repetition count produces empty"); } temp = setalloc(); setunion(temp,q->t_first); diff --git a/util/LLgen/src/gencode.c b/util/LLgen/src/gencode.c index bc2edeadf..0e8634dff 100644 --- a/util/LLgen/src/gencode.c +++ b/util/LLgen/src/gencode.c @@ -348,21 +348,28 @@ getparams() { register int l; long ftell(); char first; + char add_semi = ' '; first = ' '; /* save offset in file to be able to copy the declaration later */ off = ftell(fact); /* First pass through declaration, find the parameter names */ + ltext[0] = '\0'; while ((l = gettok()) != ENDDECL) { - if (l == ';' || l == ',') { + if ((l == ';' || l == ',') && ltext[0] != '\0') { /* * The last identifier found before a ';' or a ',' * must be a parameter */ fprintf(fpars,"%c%s", first, ltext); first = ','; + ltext[0] = '\0'; } } + if (ltext[0] != '\0') { + fprintf(fpars, "%c%s", first, ltext); + add_semi = ';'; + } fputs(") ",fpars); /* * Now copy the declarations @@ -372,7 +379,7 @@ getparams() { */ fseek(fact,off,0); getaction(0); - fputs(" {\n",fpars); + fprintf(fpars, "%c {\n",add_semi); } STATIC diff --git a/util/LLgen/src/main.c b/util/LLgen/src/main.c index d410fb4b6..7e0e7c2a0 100644 --- a/util/LLgen/src/main.c +++ b/util/LLgen/src/main.c @@ -236,7 +236,7 @@ error(lineno,s,t,u) string s,t,u; { ++nerrors; if (!lineno) lineno = 1; - fprintf(stderr,"\"%s\", line %d : ",f_input, lineno); + fprintf(stderr,"\"%s\", line %d: ",f_input, lineno); fprintf(stderr,s,t,u); fputs("\n",stderr); } @@ -249,7 +249,7 @@ warning(lineno,s,t,u) string s,t,u; { if (wflag) return; if (!lineno) lineno = 1; - fprintf(stderr,"\"%s\", line %d : (Warning) ",f_input, lineno); + fprintf(stderr,"\"%s\", line %d: (Warning) ",f_input, lineno); fprintf(stderr,s,t,u); fputs("\n",stderr); } @@ -339,13 +339,3 @@ install(target, source) string target, source; { RENAME(f_pars,target); } } - -#ifndef NDEBUG -badassertion(asstr,file,line) char *asstr, *file; { - - fprintf(stderr,"Assertion \"%s\" failed %s(%d)\n",asstr,file,line); - if (fact != NULL) fclose(fact); - if (fpars != NULL) fclose(fpars); - abort(); -} -#endif -- 2.34.1