Always also produce ANSI-C, depending on __STDC__ and __cplusplus
This commit is contained in:
parent
ed4afc99f6
commit
7ec968fb03
4 changed files with 59 additions and 35 deletions
|
@ -504,7 +504,7 @@ expr : '(' { copyact('(',')',1,0); }
|
||||||
')'
|
')'
|
||||||
;
|
;
|
||||||
|
|
||||||
repeats(int *kind, *cnt;) { int t1 = 0; } :
|
repeats(int *kind; int *cnt;) { int t1 = 0; } :
|
||||||
[
|
[
|
||||||
'?' { *kind = OPT; }
|
'?' { *kind = OPT; }
|
||||||
| [ '*' { *kind = STAR; }
|
| [ '*' { *kind = STAR; }
|
||||||
|
|
|
@ -63,7 +63,7 @@ extern int ntprint; /* ntprint = 1 if they must be printed too in
|
||||||
*/
|
*/
|
||||||
# ifndef NDEBUG
|
# ifndef NDEBUG
|
||||||
extern int debug;
|
extern int debug;
|
||||||
# endif not NDEBUG
|
# endif /* not NDEBUG */
|
||||||
extern p_file files,pfile; /* pointers to file structure.
|
extern p_file files,pfile; /* pointers to file structure.
|
||||||
* "files" points to the start of the
|
* "files" points to the start of the
|
||||||
* list */
|
* list */
|
||||||
|
|
|
@ -100,6 +100,18 @@ mk_tokenlist()
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STATIC
|
||||||
|
genhdr()
|
||||||
|
{
|
||||||
|
if (!firsts) fputs("#define LLNOFIRSTS\n", fpars);
|
||||||
|
if (ansi_c) fputs("#define LL_ANSI_C 1\n", fpars);
|
||||||
|
else {
|
||||||
|
fputs("#if __STDC__ || __cplusplus\n#define LL_ANSI_C 1\n#endif\n", fpars);
|
||||||
|
}
|
||||||
|
fprintf(fpars, "#define LL_LEXI %s\n", lexical);
|
||||||
|
copyfile(incl_file);
|
||||||
|
}
|
||||||
|
|
||||||
gencode(argc) {
|
gencode(argc) {
|
||||||
register p_file p = files;
|
register p_file p = files;
|
||||||
|
|
||||||
|
@ -115,9 +127,7 @@ gencode(argc) {
|
||||||
opentemp(f_input);
|
opentemp(f_input);
|
||||||
correct_prefix();
|
correct_prefix();
|
||||||
/* generate code ... */
|
/* generate code ... */
|
||||||
if (!firsts) fputs("#define LLNOFIRSTS\n", fpars);
|
genhdr();
|
||||||
if (ansi_c) fputs("#define LL_ANSI_C 1\n", fpars);
|
|
||||||
fprintf(fpars, "#define LL_LEXI %s\n", lexical);
|
|
||||||
copyfile(incl_file);
|
copyfile(incl_file);
|
||||||
generate(p);
|
generate(p);
|
||||||
getaction(2);
|
getaction(2);
|
||||||
|
@ -171,10 +181,7 @@ genrecovery() {
|
||||||
opentemp((string) 0);
|
opentemp((string) 0);
|
||||||
f = fpars;
|
f = fpars;
|
||||||
correct_prefix();
|
correct_prefix();
|
||||||
if (!firsts) fputs("#define LLNOFIRSTS\n", f);
|
genhdr();
|
||||||
if (ansi_c) fputs("#define LL_ANSI_C 1\n", f);
|
|
||||||
fprintf(f, "#define LL_LEXI %s\n", lexical);
|
|
||||||
copyfile(incl_file);
|
|
||||||
for (st = start; st; st = st->ff_next) {
|
for (st = start; st; st = st->ff_next) {
|
||||||
/* Make sure that every set the parser needs is in the list
|
/* Make sure that every set the parser needs is in the list
|
||||||
* before generating a define of the number of them!
|
* before generating a define of the number of them!
|
||||||
|
@ -192,15 +199,16 @@ genrecovery() {
|
||||||
ntokens);
|
ntokens);
|
||||||
if (onerror) fprintf(f,"#define LL_USERHOOK %s\n", onerror);
|
if (onerror) fprintf(f,"#define LL_USERHOOK %s\n", onerror);
|
||||||
/* Now generate the routines that call the startsymbols */
|
/* Now generate the routines that call the startsymbols */
|
||||||
if (ansi_c) for (st = start; st; st = st->ff_next) {
|
fputs("#if LL_ANSI_C\n", f);
|
||||||
|
for (st = start; st; st = st->ff_next) {
|
||||||
p = &nonterms[st->ff_nont];
|
p = &nonterms[st->ff_nont];
|
||||||
fputs("void ", f);
|
fputs("void ", f);
|
||||||
genextname(st->ff_nont, p->n_name, f);
|
genextname(st->ff_nont, p->n_name, f);
|
||||||
fputs("(void);\n", f);
|
fputs("(void);\n", f);
|
||||||
}
|
}
|
||||||
|
fputs("#endif\n", f);
|
||||||
for (st = start; st; st = st->ff_next) {
|
for (st = start; st; st = st->ff_next) {
|
||||||
if (ansi_c) fputs("void ", f);
|
fprintf(f, "#if LL_ANSI_C\nvoid %s(void)\n#else\n%s()\n#endif\n", st->ff_name, st->ff_name);
|
||||||
fprintf(f, "%s(%s)", st->ff_name, ansi_c ? "void" : "");
|
|
||||||
p = &nonterms[st->ff_nont];
|
p = &nonterms[st->ff_nont];
|
||||||
fputs(" {\n\tunsigned int s[LL_NTERMINALS+LL_NSETS+2];\n\tLLnewlevel(s);\n\tLLread();\n", f);
|
fputs(" {\n\tunsigned int s[LL_NTERMINALS+LL_NSETS+2];\n\tLLnewlevel(s);\n\tLLread();\n", f);
|
||||||
if (g_gettype(p->n_rule) == ALTERNATION) {
|
if (g_gettype(p->n_rule) == ALTERNATION) {
|
||||||
|
@ -275,16 +283,21 @@ generate(f) p_file f; {
|
||||||
}
|
}
|
||||||
if (is_first) genprototypes(f);
|
if (is_first) genprototypes(f);
|
||||||
is_first = 0;
|
is_first = 0;
|
||||||
if (p->n_flags & GENSTATIC) fputs("static ", fpars);
|
if (p->n_flags & GENSTATIC) fputs("static\n", fpars);
|
||||||
if (ansi_c) fputs("void ", fpars);
|
fputs("#if LL_ANSI_C\nvoid\n#endif\n", fpars);
|
||||||
genextname(s, p->n_name, fpars);
|
genextname(s, p->n_name, fpars);
|
||||||
if (p->n_flags & PARAMS) {
|
if (p->n_flags & PARAMS) {
|
||||||
fputs("(\n", fpars);
|
long off = ftell(fact);
|
||||||
|
fputs("(\n#if LL_ANSI_C\n", fpars);
|
||||||
controlline();
|
controlline();
|
||||||
if (ansi_c) getansiparams(1);
|
getansiparams(1);
|
||||||
else getparams();
|
fseek(fact, off, 0);
|
||||||
|
fputs("#else\n", fpars);
|
||||||
|
controlline();
|
||||||
|
getparams();
|
||||||
|
fputs("#endif\n{\n", fpars);
|
||||||
}
|
}
|
||||||
else fprintf(fpars, "(%s) {\n", ansi_c ? "void" : "");
|
else fputs("(\n#if LL_ANSI_C\nvoid\n#endif\n) {\n", fpars);
|
||||||
if (p->n_flags & LOCALS) getaction(1);
|
if (p->n_flags & LOCALS) getaction(1);
|
||||||
i = getntsafe(p);
|
i = getntsafe(p);
|
||||||
mustpop = NOPOP;
|
mustpop = NOPOP;
|
||||||
|
@ -397,7 +410,7 @@ getparams() {
|
||||||
*/
|
*/
|
||||||
fseek(fact,off,0);
|
fseek(fact,off,0);
|
||||||
getaction(0);
|
getaction(0);
|
||||||
fprintf(fpars, "%c {\n",add_semi);
|
fprintf(fpars, "%c\n",add_semi);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC
|
||||||
|
@ -411,6 +424,7 @@ genprototypes(f)
|
||||||
register p_nont p;
|
register p_nont p;
|
||||||
long off = ftell(fact);
|
long off = ftell(fact);
|
||||||
|
|
||||||
|
fputs("#if LL_ANSI_C\n", fpars);
|
||||||
for (i = 0; i < nnonterms; i++) {
|
for (i = 0; i < nnonterms; i++) {
|
||||||
if (! IN(f->f_used, i)) continue;
|
if (! IN(f->f_used, i)) continue;
|
||||||
p = &nonterms[i];
|
p = &nonterms[i];
|
||||||
|
@ -418,21 +432,31 @@ genprototypes(f)
|
||||||
getntparams(p) == 0) {
|
getntparams(p) == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (ansi_c || (p->n_flags & GENSTATIC)) {
|
if (p->n_flags & GENSTATIC) fputs("static ", fpars);
|
||||||
if (p->n_flags & GENSTATIC) fputs("static ", fpars);
|
fputs("void ", fpars);
|
||||||
if (ansi_c) fputs("void ", fpars);
|
genextname(i, p->n_name, fpars);
|
||||||
genextname(i, p->n_name, fpars);
|
if (p->n_flags & PARAMS) {
|
||||||
if (! ansi_c) fputs("();\n", fpars);
|
fputs("(\n", fpars);
|
||||||
else if (p->n_flags & PARAMS) {
|
fseek(fact, p->n_off, 0);
|
||||||
fputs("(\n", fpars);
|
controlline();
|
||||||
fseek(fact, p->n_off, 0);
|
getansiparams(0);
|
||||||
controlline();
|
|
||||||
getansiparams(0);
|
|
||||||
fseek(fact, off, 0);
|
|
||||||
}
|
|
||||||
else fputs("(void);\n", fpars);
|
|
||||||
}
|
}
|
||||||
|
else fputs("(void);\n", fpars);
|
||||||
}
|
}
|
||||||
|
fseek(fact, off, 0);
|
||||||
|
fputs("#else\n", fpars);
|
||||||
|
for (i = 0; i < nnonterms; i++) {
|
||||||
|
if (! IN(f->f_used, i)) continue;
|
||||||
|
p = &nonterms[i];
|
||||||
|
if (g_gettype(p->n_rule) == EORULE &&
|
||||||
|
getntparams(p) == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (p->n_flags & GENSTATIC) fputs("static ", fpars);
|
||||||
|
genextname(i, p->n_name, fpars);
|
||||||
|
fputs("();\n", fpars);
|
||||||
|
}
|
||||||
|
fputs("#endif\n", fpars);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC
|
||||||
|
@ -461,7 +485,7 @@ getansiparams(mkdef) {
|
||||||
else if (l == IDENT) fprintf(fpars, "%s", ltext);
|
else if (l == IDENT) fprintf(fpars, "%s", ltext);
|
||||||
else fputc(l, fpars);
|
else fputc(l, fpars);
|
||||||
}
|
}
|
||||||
fprintf(fpars, ") %c\n", mkdef ? '{' : ';');
|
fprintf(fpars, ") %c\n", mkdef ? ' ' : ';');
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC
|
STATIC
|
||||||
|
|
|
@ -244,6 +244,6 @@ typedef struct info_alloc {
|
||||||
|
|
||||||
# ifdef NDEBUG
|
# ifdef NDEBUG
|
||||||
# define STATIC static
|
# define STATIC static
|
||||||
# else not NDEBUG
|
# else /* not NDEBUG */
|
||||||
# define STATIC extern
|
# define STATIC extern
|
||||||
# endif not NDEBUG
|
# endif /* not NDEBUG */
|
||||||
|
|
Loading…
Reference in a new issue