do not allow ',' as separator in parameter declarations; this results in bad C-code
This commit is contained in:
parent
2b0a61d143
commit
68cebfb733
1 changed files with 11 additions and 7 deletions
|
@ -214,7 +214,7 @@ rule { register p_nont p;
|
||||||
p->n_lineno = linecount;
|
p->n_lineno = linecount;
|
||||||
p->n_off = ftell(fact);
|
p->n_off = ftell(fact);
|
||||||
}
|
}
|
||||||
[ params { if (nparams > 0) {
|
[ params(1) { if (nparams > 0) {
|
||||||
p->n_flags |= PARAMS;
|
p->n_flags |= PARAMS;
|
||||||
if (nparams > 15) {
|
if (nparams > 15) {
|
||||||
error(linecount,"Too many parameters");
|
error(linecount,"Too many parameters");
|
||||||
|
@ -479,7 +479,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 { if (nparams > 15) {
|
[ params(0) { if (nparams > 15) {
|
||||||
error(linecount,"Too many parameters");
|
error(linecount,"Too many parameters");
|
||||||
} else g_setnpar(pres,nparams);
|
} else g_setnpar(pres,nparams);
|
||||||
if (g_gettype(pres) == TERMINAL) {
|
if (g_gettype(pres) == TERMINAL) {
|
||||||
|
@ -497,11 +497,11 @@ elem (register p_gram pres;)
|
||||||
action(1)
|
action(1)
|
||||||
;
|
;
|
||||||
|
|
||||||
params
|
params(int formal)
|
||||||
{
|
{
|
||||||
long off = ftell(fact);
|
long off = ftell(fact);
|
||||||
}
|
}
|
||||||
: '(' { copyact('(',')',0,0); }
|
: '(' { copyact('(', ')', formal ? 2 : 0, 0); }
|
||||||
')'
|
')'
|
||||||
{ if (nparams == 0) {
|
{ if (nparams == 0) {
|
||||||
fseek(fact, off, 0);
|
fseek(fact, off, 0);
|
||||||
|
@ -565,7 +565,8 @@ 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 != 0, copy opening and closing parameters too.
|
* If flag & 1, copy opening and closing parameters too.
|
||||||
|
* If flag & 2, don't allow ','.
|
||||||
*/
|
*/
|
||||||
static int text_seen = 0;
|
static int text_seen = 0;
|
||||||
register FILE *f;
|
register FILE *f;
|
||||||
|
@ -581,7 +582,7 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; {
|
||||||
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) putc(ch1,f);
|
if (level || (flag & 1)) putc(ch1,f);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ch = input();
|
ch = input();
|
||||||
if (ch == ch2) {
|
if (ch == ch2) {
|
||||||
|
@ -589,7 +590,7 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; {
|
||||||
unput(ch);
|
unput(ch);
|
||||||
if (text_seen) nparams++;
|
if (text_seen) nparams++;
|
||||||
}
|
}
|
||||||
if (level || flag) putc(ch,f);
|
if (level || (flag & 1)) putc(ch,f);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch(ch) {
|
switch(ch) {
|
||||||
|
@ -626,6 +627,9 @@ copyact(ch1,ch2,flag,level) char ch1,ch2; {
|
||||||
if (! level && text_seen) {
|
if (! level && text_seen) {
|
||||||
text_seen = 0;
|
text_seen = 0;
|
||||||
nparams++;
|
nparams++;
|
||||||
|
if (ch == ',' && (flag & 2)) {
|
||||||
|
error(linecount, "Parameters may not be separated with a ','");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '\'':
|
case '\'':
|
||||||
|
|
Loading…
Reference in a new issue