relaxed the ;-terminator requirement for parameters

This commit is contained in:
ceriel 1991-08-23 16:23:07 +00:00
parent 3c221691b3
commit b1fdacb99c
6 changed files with 25 additions and 42 deletions

View file

@ -6,7 +6,6 @@ Lpars.c.dist
Lpars.h.dist Lpars.h.dist
Makefile Makefile
alloc.c alloc.c
assert.h
check.c check.c
compute.c compute.c
extern.h extern.h

View file

@ -199,7 +199,7 @@ rule { register p_nont p;
acount = 0; acount = 0;
p->n_lineno = linecount; p->n_lineno = linecount;
} }
[ params(2) { p->n_flags |= PARAMS; [ params { p->n_flags |= PARAMS;
if (nparams > 15) { if (nparams > 15) {
error(linecount,"Too many parameters"); error(linecount,"Too many parameters");
} }
@ -462,7 +462,7 @@ elem (register p_gram pres;)
C_IDENT { pe = search(UNKNOWN,lextoken.t_string,BOTH); C_IDENT { pe = search(UNKNOWN,lextoken.t_string,BOTH);
*pres = *pe; *pres = *pe;
} }
[ params(0) { if (nparams > 14) { [ params { if (nparams > 14) {
error(linecount,"Too many parameters"); error(linecount,"Too many parameters");
} else g_setnpar(pres,nparams+1); } else g_setnpar(pres,nparams+1);
if (g_gettype(pres) == TERMINAL) { if (g_gettype(pres) == TERMINAL) {
@ -480,8 +480,8 @@ elem (register p_gram pres;)
action(1) action(1)
; ;
params(int n;) params
: '(' { copyact('(',')',n,0); } : '(' { 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 * Copy an action to file f. Opening bracket is ch1, closing bracket
* is ch2. * is ch2.
* If flag = 1, copy opening and closing parameters too. * If flag != 0, 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 ';'
*/ */
static int id_seen = 0;
register FILE *f; register FILE *f;
register ch; /* Current char */ register ch; /* Current char */
register match; /* used to read strings */ register match; /* used to read strings */
int saved; /* save linecount */ int saved; /* save linecount */
int semicolon = 0;
f = fact; f = fact;
if (!level) { if (!level) {
saved = linecount; saved = linecount;
id_seen = 0;
nparams = 0; /* count comma's */ nparams = 0; /* count comma's */
putc('\0',f); putc('\0',f);
fprintf(f,"# line %d \"%s\"\n", linecount,f_input); fprintf(f,"# line %d \"%s\"\n", linecount,f_input);
} }
if (level || flag == 1) putc(ch1,f); if (level || flag) putc(ch1,f);
for (;;) { for (;;) {
ch = input(); ch = input();
if (c_class[ch] == ISLET) id_seen = 1;
if (ch == ch2) { if (ch == ch2) {
if (!level) unput(ch); if (!level) unput(ch);
if (level || flag == 1) putc(ch,f); if (level || flag) putc(ch,f);
if ((!level) && flag == 2 && !semicolon) { if (id_seen) nparams++;
error(linecount,"Missing ';'");
}
return; return;
} }
if (c_class[ch] != ISSPA) semicolon = 0;
switch(ch) { switch(ch) {
case ')': case ')':
case '}': case '}':
@ -596,14 +593,13 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; {
ch = '/'; ch = '/';
break; break;
case ';': case ';':
semicolon = 1;
/* Fall through */
case ',': case ',':
if (!level) { /* if (!level) { /*
* Only ','s and ';'s on the * Only ','s and ';'s on the
* outer level are counted * outer level are counted
*/ */
nparams++; nparams++;
id_seen = 0;
} }
break; break;
case '\'': case '\'':

View file

@ -7,7 +7,7 @@ CFLAGS=-O -DNDEBUG $(INCLUDES) $(PROF)
LDFLAGS= 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 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
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 GFILES = tokens.g LLgen.g
LINT = lint -b -DNDEBUG -DNORCSID LINT = lint -b -DNDEBUG -DNORCSID
@ -52,7 +52,6 @@ distr:
# The next lines are generated automatically # The next lines are generated automatically
# AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO # AUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTOAUTO
LLgen.o: Lpars.h LLgen.o: Lpars.h
LLgen.o: assert.h
LLgen.o: cclass.h LLgen.o: cclass.h
LLgen.o: extern.h LLgen.o: extern.h
LLgen.o: io.h LLgen.o: io.h
@ -61,17 +60,14 @@ Lpars.o: Lpars.h
alloc.o: extern.h alloc.o: extern.h
alloc.o: types.h alloc.o: types.h
cclass.o: cclass.h cclass.o: cclass.h
check.o: assert.h
check.o: extern.h check.o: extern.h
check.o: io.h check.o: io.h
check.o: sets.h check.o: sets.h
check.o: types.h check.o: types.h
compute.o: assert.h
compute.o: extern.h compute.o: extern.h
compute.o: io.h compute.o: io.h
compute.o: sets.h compute.o: sets.h
compute.o: types.h compute.o: types.h
gencode.o: assert.h
gencode.o: cclass.h gencode.o: cclass.h
gencode.o: extern.h gencode.o: extern.h
gencode.o: io.h gencode.o: io.h
@ -82,25 +78,20 @@ global.o: io.h
global.o: types.h global.o: types.h
machdep.o: $(EMHOME)/h/em_path.h machdep.o: $(EMHOME)/h/em_path.h
machdep.o: types.h machdep.o: types.h
main.o: assert.h
main.o: extern.h main.o: extern.h
main.o: io.h main.o: io.h
main.o: sets.h main.o: sets.h
main.o: types.h main.o: types.h
name.o: assert.h
name.o: extern.h name.o: extern.h
name.o: io.h name.o: io.h
name.o: types.h name.o: types.h
reach.o: assert.h
reach.o: extern.h reach.o: extern.h
reach.o: io.h reach.o: io.h
reach.o: types.h reach.o: types.h
sets.o: assert.h
sets.o: extern.h sets.o: extern.h
sets.o: sets.h sets.o: sets.h
sets.o: types.h sets.o: types.h
tokens.o: Lpars.h tokens.o: Lpars.h
tokens.o: assert.h
tokens.o: cclass.h tokens.o: cclass.h
tokens.o: extern.h tokens.o: extern.h
tokens.o: io.h tokens.o: io.h

View file

@ -207,7 +207,7 @@ check(p) register p_gram p; {
if (empty(q->t_rule)) { if (empty(q->t_rule)) {
q->t_flags |= EMPTYTERM; q->t_flags |= EMPTYTERM;
retval = 1; retval = 1;
error(p->g_lineno, "Term produces empty"); error(p->g_lineno, "Term with variable repetition count produces empty");
} }
temp = setalloc(); temp = setalloc();
setunion(temp,q->t_first); setunion(temp,q->t_first);

View file

@ -348,21 +348,28 @@ getparams() {
register int l; register int l;
long ftell(); long ftell();
char first; char first;
char add_semi = ' ';
first = ' '; first = ' ';
/* save offset in file to be able to copy the declaration later */ /* save offset in file to be able to copy the declaration later */
off = ftell(fact); off = ftell(fact);
/* First pass through declaration, find the parameter names */ /* First pass through declaration, find the parameter names */
ltext[0] = '\0';
while ((l = gettok()) != ENDDECL) { while ((l = gettok()) != ENDDECL) {
if (l == ';' || l == ',') { if ((l == ';' || l == ',') && ltext[0] != '\0') {
/* /*
* The last identifier found before a ';' or a ',' * The last identifier found before a ';' or a ','
* must be a parameter * must be a parameter
*/ */
fprintf(fpars,"%c%s", first, ltext); fprintf(fpars,"%c%s", first, ltext);
first = ','; first = ',';
ltext[0] = '\0';
} }
} }
if (ltext[0] != '\0') {
fprintf(fpars, "%c%s", first, ltext);
add_semi = ';';
}
fputs(") ",fpars); fputs(") ",fpars);
/* /*
* Now copy the declarations * Now copy the declarations
@ -372,7 +379,7 @@ getparams() {
*/ */
fseek(fact,off,0); fseek(fact,off,0);
getaction(0); getaction(0);
fputs(" {\n",fpars); fprintf(fpars, "%c {\n",add_semi);
} }
STATIC STATIC

View file

@ -236,7 +236,7 @@ error(lineno,s,t,u) string s,t,u; {
++nerrors; ++nerrors;
if (!lineno) lineno = 1; 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); fprintf(stderr,s,t,u);
fputs("\n",stderr); fputs("\n",stderr);
} }
@ -249,7 +249,7 @@ warning(lineno,s,t,u) string s,t,u; {
if (wflag) return; if (wflag) return;
if (!lineno) lineno = 1; 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); fprintf(stderr,s,t,u);
fputs("\n",stderr); fputs("\n",stderr);
} }
@ -339,13 +339,3 @@ install(target, source) string target, source; {
RENAME(f_pars,target); 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