summaryrefslogtreecommitdiff
path: root/usr.bin/yacc
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2014-03-07 19:34:50 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2014-03-07 19:34:50 +0000
commite92167b869ba0c328673443fb683f03386ff4723 (patch)
tree1992059c2145ba71ceb64ef2d7b75119aba3f158 /usr.bin/yacc
parent0902a77a72ae84b4c0bea1112a7ae7df013018f2 (diff)
drag this code into modern style. ok zhuk
Diffstat (limited to 'usr.bin/yacc')
-rw-r--r--usr.bin/yacc/output.c1856
-rw-r--r--usr.bin/yacc/skeleton.c657
2 files changed, 1211 insertions, 1302 deletions
diff --git a/usr.bin/yacc/output.c b/usr.bin/yacc/output.c
index 97e391da08d..14729c81d21 100644
--- a/usr.bin/yacc/output.c
+++ b/usr.bin/yacc/output.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: output.c,v 1.20 2014/02/21 02:18:00 tedu Exp $ */
+/* $OpenBSD: output.c,v 1.21 2014/03/07 19:34:49 tedu Exp $ */
/* $NetBSD: output.c,v 1.4 1996/03/19 03:21:41 jtc Exp $ */
/*
@@ -80,352 +80,335 @@ void free_reductions(void);
void
output(void)
{
- free_itemsets();
- free_shifts();
- free_reductions();
- output_prefix();
- output_stored_text();
- output_defines();
- output_rule_data();
- output_yydefred();
- output_actions();
- free_parser();
- output_debug();
- output_stype();
- if (rflag) write_section(tables);
- write_section(header);
- output_trailing_text();
- write_section(body);
- output_semantic_actions();
- write_section(trailer);
+ free_itemsets();
+ free_shifts();
+ free_reductions();
+ output_prefix();
+ output_stored_text();
+ output_defines();
+ output_rule_data();
+ output_yydefred();
+ output_actions();
+ free_parser();
+ output_debug();
+ output_stype();
+ if (rflag)
+ write_section(tables);
+ write_section(header);
+ output_trailing_text();
+ write_section(body);
+ output_semantic_actions();
+ write_section(trailer);
}
void
output_prefix(void)
{
- if (symbol_prefix == NULL)
- symbol_prefix = "yy";
- else
- {
- ++outline;
- fprintf(code_file, "#define yyparse %sparse\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yylex %slex\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yyerror %serror\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yychar %schar\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yyval %sval\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yylval %slval\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yydebug %sdebug\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yynerrs %snerrs\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yyerrflag %serrflag\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yyss %sss\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yysslim %ssslim\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yyssp %sssp\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yyvs %svs\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yyvsp %svsp\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yystacksize %sstacksize\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yylhs %slhs\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yylen %slen\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yydefred %sdefred\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yydgoto %sdgoto\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yysindex %ssindex\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yyrindex %srindex\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yygindex %sgindex\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yytable %stable\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yycheck %scheck\n", symbol_prefix);
- ++outline;
- fprintf(code_file, "#define yyname %sname\n", symbol_prefix);
+ if (symbol_prefix == NULL)
+ symbol_prefix = "yy";
+ else {
+ ++outline;
+ fprintf(code_file, "#define yyparse %sparse\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yylex %slex\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yyerror %serror\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yychar %schar\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yyval %sval\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yylval %slval\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yydebug %sdebug\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yynerrs %snerrs\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yyerrflag %serrflag\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yyss %sss\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yysslim %ssslim\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yyssp %sssp\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yyvs %svs\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yyvsp %svsp\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yystacksize %sstacksize\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yylhs %slhs\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yylen %slen\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yydefred %sdefred\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yydgoto %sdgoto\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yysindex %ssindex\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yyrindex %srindex\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yygindex %sgindex\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yytable %stable\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yycheck %scheck\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yyname %sname\n", symbol_prefix);
+ ++outline;
+ fprintf(code_file, "#define yyrule %srule\n", symbol_prefix);
+ }
++outline;
- fprintf(code_file, "#define yyrule %srule\n", symbol_prefix);
- }
- ++outline;
- fprintf(code_file, "#define YYPREFIX \"%s\"\n", symbol_prefix);
+ fprintf(code_file, "#define YYPREFIX \"%s\"\n", symbol_prefix);
}
void
output_rule_data(void)
{
- int i;
- int j;
-
- fprintf(output_file,
- "const short %slhs[] =\n"
- "\t{%42d,", symbol_prefix, symbol_value[start_symbol]);
+ int i;
+ int j;
+
+ fprintf(output_file,
+ "const short %slhs[] =\n"
+ "\t{%42d,", symbol_prefix, symbol_value[start_symbol]);
+
+ j = 10;
+ for (i = 3; i < nrules; i++) {
+ if (j >= 10) {
+ if (!rflag)
+ ++outline;
+ putc('\n', output_file);
+ j = 1;
+ } else
+ ++j;
- j = 10;
- for (i = 3; i < nrules; i++)
- {
- if (j >= 10)
- {
- if (!rflag) ++outline;
- putc('\n', output_file);
- j = 1;
+ fprintf(output_file, "%5d,", symbol_value[rlhs[i]]);
}
- else
- ++j;
-
- fprintf(output_file, "%5d,", symbol_value[rlhs[i]]);
- }
- if (!rflag) outline += 2;
- fprintf(output_file, "\n};\n");
-
- fprintf(output_file,
- "const short %slen[] =\n"
- "\t{%42d,", symbol_prefix, 2);
-
- j = 10;
- for (i = 3; i < nrules; i++)
- {
- if (j >= 10)
- {
- if (!rflag) ++outline;
- putc('\n', output_file);
- j = 1;
- }
- else
- j++;
+ if (!rflag)
+ outline += 2;
+ fprintf(output_file, "\n};\n");
+
+ fprintf(output_file,
+ "const short %slen[] =\n"
+ "\t{%42d,", symbol_prefix, 2);
+
+ j = 10;
+ for (i = 3; i < nrules; i++) {
+ if (j >= 10) {
+ if (!rflag)
+ ++outline;
+ putc('\n', output_file);
+ j = 1;
+ } else
+ j++;
- fprintf(output_file, "%5d,", rrhs[i + 1] - rrhs[i] - 1);
- }
- if (!rflag) outline += 2;
- fprintf(output_file, "\n};\n");
+ fprintf(output_file, "%5d,", rrhs[i + 1] - rrhs[i] - 1);
+ }
+ if (!rflag)
+ outline += 2;
+ fprintf(output_file, "\n};\n");
}
void
output_yydefred(void)
{
- int i, j;
-
- fprintf(output_file,
- "const short %sdefred[] =\n"
- "\t{%39d,",
- symbol_prefix, (defred[0] ? defred[0] - 2 : 0));
-
- j = 10;
- for (i = 1; i < nstates; i++)
- {
- if (j < 10)
- ++j;
- else
- {
- if (!rflag) ++outline;
- putc('\n', output_file);
- j = 1;
- }
+ int i, j;
+
+ fprintf(output_file,
+ "const short %sdefred[] =\n"
+ "\t{%39d,",
+ symbol_prefix, (defred[0] ? defred[0] - 2 : 0));
+
+ j = 10;
+ for (i = 1; i < nstates; i++) {
+ if (j < 10)
+ ++j;
+ else {
+ if (!rflag)
+ ++outline;
+ putc('\n', output_file);
+ j = 1;
+ }
- fprintf(output_file, "%5d,", (defred[i] ? defred[i] - 2 : 0));
- }
+ fprintf(output_file, "%5d,", (defred[i] ? defred[i] - 2 : 0));
+ }
- if (!rflag) outline += 2;
- fprintf(output_file, "\n};\n");
+ if (!rflag)
+ outline += 2;
+ fprintf(output_file, "\n};\n");
}
void
output_actions(void)
{
- nvectors = 2*nstates + nvars;
-
- froms = NEW2(nvectors, short *);
- tos = NEW2(nvectors, short *);
- tally = NEW2(nvectors, short);
- width = NEW2(nvectors, short);
-
- token_actions();
- free(lookaheads);
- free(LA);
- free(LAruleno);
- free(accessing_symbol);
-
- goto_actions();
- free(goto_map + ntokens);
- free(from_state);
- free(to_state);
-
- sort_actions();
- pack_table();
- output_base();
- output_table();
- output_check();
+ nvectors = 2 * nstates + nvars;
+
+ froms = NEW2(nvectors, short *);
+ tos = NEW2(nvectors, short *);
+ tally = NEW2(nvectors, short);
+ width = NEW2(nvectors, short);
+
+ token_actions();
+ free(lookaheads);
+ free(LA);
+ free(LAruleno);
+ free(accessing_symbol);
+
+ goto_actions();
+ free(goto_map + ntokens);
+ free(from_state);
+ free(to_state);
+
+ sort_actions();
+ pack_table();
+ output_base();
+ output_table();
+ output_check();
}
void
token_actions(void)
{
- int i, j;
- int shiftcount, reducecount;
- int max, min;
- short *actionrow, *r, *s;
- action *p;
-
- actionrow = NEW2(2*ntokens, short);
- for (i = 0; i < nstates; ++i)
- {
- if (parser[i])
- {
- for (j = 0; j < 2*ntokens; ++j)
- actionrow[j] = 0;
-
- shiftcount = 0;
- reducecount = 0;
- for (p = parser[i]; p; p = p->next)
- {
- if (p->suppressed == 0)
- {
- if (p->action_code == SHIFT)
- {
- ++shiftcount;
- actionrow[p->symbol] = p->number;
- }
- else if (p->action_code == REDUCE && p->number != defred[i])
- {
- ++reducecount;
- actionrow[p->symbol + ntokens] = p->number;
- }
- }
- }
-
- tally[i] = shiftcount;
- tally[nstates+i] = reducecount;
- width[i] = 0;
- width[nstates+i] = 0;
- if (shiftcount > 0)
- {
- froms[i] = r = NEW2(shiftcount, short);
- tos[i] = s = NEW2(shiftcount, short);
- min = MAXSHORT;
- max = 0;
- for (j = 0; j < ntokens; ++j)
- {
- if (actionrow[j])
- {
- if (min > symbol_value[j])
- min = symbol_value[j];
- if (max < symbol_value[j])
- max = symbol_value[j];
- *r++ = symbol_value[j];
- *s++ = actionrow[j];
- }
- }
- width[i] = max - min + 1;
- }
- if (reducecount > 0)
- {
- froms[nstates+i] = r = NEW2(reducecount, short);
- tos[nstates+i] = s = NEW2(reducecount, short);
- min = MAXSHORT;
- max = 0;
- for (j = 0; j < ntokens; ++j)
- {
- if (actionrow[ntokens+j])
- {
- if (min > symbol_value[j])
- min = symbol_value[j];
- if (max < symbol_value[j])
- max = symbol_value[j];
- *r++ = symbol_value[j];
- *s++ = actionrow[ntokens+j] - 2;
- }
+ int i, j;
+ int shiftcount, reducecount;
+ int max, min;
+ short *actionrow, *r, *s;
+ action *p;
+
+ actionrow = NEW2(2*ntokens, short);
+ for (i = 0; i < nstates; ++i) {
+ if (parser[i]) {
+ for (j = 0; j < 2 * ntokens; ++j)
+ actionrow[j] = 0;
+
+ shiftcount = 0;
+ reducecount = 0;
+ for (p = parser[i]; p; p = p->next) {
+ if (p->suppressed == 0) {
+ if (p->action_code == SHIFT) {
+ ++shiftcount;
+ actionrow[p->symbol] = p->number;
+ } else if (p->action_code == REDUCE &&
+ p->number != defred[i]) {
+ ++reducecount;
+ actionrow[p->symbol + ntokens] = p->number;
+ }
+ }
+ }
+
+ tally[i] = shiftcount;
+ tally[nstates+i] = reducecount;
+ width[i] = 0;
+ width[nstates+i] = 0;
+ if (shiftcount > 0) {
+ froms[i] = r = NEW2(shiftcount, short);
+ tos[i] = s = NEW2(shiftcount, short);
+ min = MAXSHORT;
+ max = 0;
+ for (j = 0; j < ntokens; ++j) {
+ if (actionrow[j]) {
+ if (min > symbol_value[j])
+ min = symbol_value[j];
+ if (max < symbol_value[j])
+ max = symbol_value[j];
+ *r++ = symbol_value[j];
+ *s++ = actionrow[j];
+ }
+ }
+ width[i] = max - min + 1;
+ }
+ if (reducecount > 0) {
+ froms[nstates+i] = r = NEW2(reducecount, short);
+ tos[nstates+i] = s = NEW2(reducecount, short);
+ min = MAXSHORT;
+ max = 0;
+ for (j = 0; j < ntokens; ++j) {
+ if (actionrow[ntokens+j]) {
+ if (min > symbol_value[j])
+ min = symbol_value[j];
+ if (max < symbol_value[j])
+ max = symbol_value[j];
+ *r++ = symbol_value[j];
+ *s++ = actionrow[ntokens+j] - 2;
+ }
+ }
+ width[nstates+i] = max - min + 1;
+ }
}
- width[nstates+i] = max - min + 1;
- }
}
- }
- free(actionrow);
+ free(actionrow);
}
void
goto_actions(void)
{
- int i, j, k;
+ int i, j, k;
- state_count = NEW2(nstates, short);
+ state_count = NEW2(nstates, short);
- k = default_goto(start_symbol + 1);
- fprintf(output_file,
+ k = default_goto(start_symbol + 1);
+ fprintf(output_file,
"const short %sdgoto[] =\n"
"\t{%40d,", symbol_prefix, k);
- save_column(start_symbol + 1, k);
+ save_column(start_symbol + 1, k);
- j = 10;
- for (i = start_symbol + 2; i < nsyms; i++)
- {
- if (j >= 10)
- {
- if (!rflag) ++outline;
- putc('\n', output_file);
- j = 1;
- }
- else
- ++j;
+ j = 10;
+ for (i = start_symbol + 2; i < nsyms; i++) {
+ if (j >= 10) {
+ if (!rflag)
+ ++outline;
+ putc('\n', output_file);
+ j = 1;
+ } else
+ ++j;
- k = default_goto(i);
- fprintf(output_file, "%5d,", k);
- save_column(i, k);
- }
+ k = default_goto(i);
+ fprintf(output_file, "%5d,", k);
+ save_column(i, k);
+ }
- if (!rflag) outline += 2;
- fprintf(output_file, "\n};\n");
- free(state_count);
+ if (!rflag)
+ outline += 2;
+ fprintf(output_file, "\n};\n");
+ free(state_count);
}
int
default_goto(int symbol)
{
- int i;
- int m;
- int n;
- int default_state;
- int max;
+ int i;
+ int m;
+ int n;
+ int default_state;
+ int max;
- m = goto_map[symbol];
- n = goto_map[symbol + 1];
+ m = goto_map[symbol];
+ n = goto_map[symbol + 1];
- if (m == n) return (0);
+ if (m == n) return (0);
- memset(state_count, 0, nstates * sizeof(short));
+ memset(state_count, 0, nstates * sizeof(short));
- for (i = m; i < n; i++)
+ for (i = m; i < n; i++)
state_count[to_state[i]]++;
- max = 0;
- default_state = 0;
- for (i = 0; i < nstates; i++)
- {
- if (state_count[i] > max)
- {
- max = state_count[i];
- default_state = i;
+ max = 0;
+ default_state = 0;
+ for (i = 0; i < nstates; i++) {
+ if (state_count[i] > max) {
+ max = state_count[i];
+ default_state = i;
+ }
}
- }
- return (default_state);
+ return (default_state);
}
@@ -433,124 +416,119 @@ default_goto(int symbol)
void
save_column(int symbol, int default_state)
{
- int i;
- int m;
- int n;
- short *sp;
- short *sp1;
- short *sp2;
- int count;
- int symno;
-
- m = goto_map[symbol];
- n = goto_map[symbol + 1];
-
- count = 0;
- for (i = m; i < n; i++)
- {
- if (to_state[i] != default_state)
- ++count;
- }
- if (count == 0) return;
-
- symno = symbol_value[symbol] + 2*nstates;
-
- froms[symno] = sp1 = sp = NEW2(count, short);
- tos[symno] = sp2 = NEW2(count, short);
-
- for (i = m; i < n; i++)
- {
- if (to_state[i] != default_state)
- {
- *sp1++ = from_state[i];
- *sp2++ = to_state[i];
+ int i;
+ int m;
+ int n;
+ short *sp;
+ short *sp1;
+ short *sp2;
+ int count;
+ int symno;
+
+ m = goto_map[symbol];
+ n = goto_map[symbol + 1];
+
+ count = 0;
+ for (i = m; i < n; i++) {
+ if (to_state[i] != default_state)
+ ++count;
}
- }
+ if (count == 0)
+ return;
- tally[symno] = count;
- width[symno] = sp1[-1] - sp[0] + 1;
+ symno = symbol_value[symbol] + 2*nstates;
+
+ froms[symno] = sp1 = sp = NEW2(count, short);
+ tos[symno] = sp2 = NEW2(count, short);
+
+ for (i = m; i < n; i++) {
+ if (to_state[i] != default_state) {
+ *sp1++ = from_state[i];
+ *sp2++ = to_state[i];
+ }
+ }
+
+ tally[symno] = count;
+ width[symno] = sp1[-1] - sp[0] + 1;
}
void
sort_actions(void)
{
- int i;
- int j;
- int k;
- int t;
- int w;
-
- order = NEW2(nvectors, short);
- nentries = 0;
-
- for (i = 0; i < nvectors; i++)
- {
- if (tally[i] > 0)
- {
- t = tally[i];
- w = width[i];
- j = nentries - 1;
+ int i;
+ int j;
+ int k;
+ int t;
+ int w;
- while (j >= 0 && (width[order[j]] < w))
- j--;
+ order = NEW2(nvectors, short);
+ nentries = 0;
- while (j >= 0 && (width[order[j]] == w) && (tally[order[j]] < t))
- j--;
+ for (i = 0; i < nvectors; i++) {
+ if (tally[i] > 0) {
+ t = tally[i];
+ w = width[i];
+ j = nentries - 1;
- for (k = nentries - 1; k > j; k--)
- order[k + 1] = order[k];
+ while (j >= 0 && (width[order[j]] < w))
+ j--;
- order[j + 1] = i;
- nentries++;
+ while (j >= 0 && (width[order[j]] == w) &&
+ (tally[order[j]] < t))
+ j--;
+
+ for (k = nentries - 1; k > j; k--)
+ order[k + 1] = order[k];
+
+ order[j + 1] = i;
+ nentries++;
+ }
}
- }
}
void
pack_table(void)
{
- int i;
- int place;
- int state;
-
- base = NEW2(nvectors, short);
- pos = NEW2(nentries, short);
-
- maxtable = 1000;
- table = NEW2(maxtable, short);
- check = NEW2(maxtable, short);
-
- lowzero = 0;
- high = 0;
-
- for (i = 0; i < maxtable; i++)
- check[i] = -1;
-
- for (i = 0; i < nentries; i++)
- {
- state = matching_vector(i);
-
- if (state < 0)
- place = pack_vector(i);
- else
- place = base[state];
-
- pos[i] = place;
- base[order[i]] = place;
- }
-
- for (i = 0; i < nvectors; i++)
- {
- if (froms[i])
- free(froms[i]);
- if (tos[i])
- free(tos[i]);
- }
-
- free(froms);
- free(tos);
- free(pos);
+ int i;
+ int place;
+ int state;
+
+ base = NEW2(nvectors, short);
+ pos = NEW2(nentries, short);
+
+ maxtable = 1000;
+ table = NEW2(maxtable, short);
+ check = NEW2(maxtable, short);
+
+ lowzero = 0;
+ high = 0;
+
+ for (i = 0; i < maxtable; i++)
+ check[i] = -1;
+
+ for (i = 0; i < nentries; i++) {
+ state = matching_vector(i);
+
+ if (state < 0)
+ place = pack_vector(i);
+ else
+ place = base[state];
+
+ pos[i] = place;
+ base[order[i]] = place;
+ }
+
+ for (i = 0; i < nvectors; i++) {
+ if (froms[i])
+ free(froms[i]);
+ if (tos[i])
+ free(tos[i]);
+ }
+
+ free(froms);
+ free(tos);
+ free(pos);
}
@@ -573,39 +551,38 @@ pack_table(void)
int
matching_vector(int vector)
{
- int i;
- int j;
- int k;
- int t;
- int w;
- int match;
- int prev;
-
- i = order[vector];
- if (i >= 2*nstates)
- return (-1);
-
- t = tally[i];
- w = width[i];
-
- for (prev = vector - 1; prev >= 0; prev--)
- {
- j = order[prev];
- if (width[j] != w || tally[j] != t)
- return (-1);
+ int i;
+ int j;
+ int k;
+ int t;
+ int w;
+ int match;
+ int prev;
+
+ i = order[vector];
+ if (i >= 2*nstates)
+ return (-1);
+
+ t = tally[i];
+ w = width[i];
+
+ for (prev = vector - 1; prev >= 0; prev--) {
+ j = order[prev];
+ if (width[j] != w || tally[j] != t)
+ return (-1);
+
+ match = 1;
+ for (k = 0; match && k < t; k++) {
+ if (tos[j][k] != tos[i][k] ||
+ froms[j][k] != froms[i][k])
+ match = 0;
+ }
- match = 1;
- for (k = 0; match && k < t; k++)
- {
- if (tos[j][k] != tos[i][k] || froms[j][k] != froms[i][k])
- match = 0;
+ if (match)
+ return (j);
}
- if (match)
- return (j);
- }
-
- return (-1);
+ return (-1);
}
@@ -613,76 +590,70 @@ matching_vector(int vector)
int
pack_vector(int vector)
{
- int i, j, k, l;
- int t;
- int loc;
- int ok;
- short *from;
- short *to;
- int newmax;
-
- i = order[vector];
- t = tally[i];
- assert(t);
-
- from = froms[i];
- to = tos[i];
-
- j = lowzero - from[0];
- for (k = 1; k < t; ++k)
- if (lowzero - from[k] > j)
- j = lowzero - from[k];
- for (;; ++j)
- {
- if (j == 0)
- continue;
- ok = 1;
- for (k = 0; ok && k < t; k++)
- {
- loc = j + from[k];
- if (loc >= maxtable)
- {
- if (loc >= MAXTABLE)
- fatal("maximum table size exceeded");
-
- newmax = maxtable;
- do { newmax += 200; } while (newmax <= loc);
- table = (short *) realloc(table, newmax*sizeof(short));
- if (table == 0) no_space();
- check = (short *) realloc(check, newmax*sizeof(short));
- if (check == 0) no_space();
- for (l = maxtable; l < newmax; ++l)
- {
- table[l] = 0;
- check[l] = -1;
+ int i, j, k, l;
+ int t;
+ int loc;
+ int ok;
+ short *from;
+ short *to;
+ int newmax;
+
+ i = order[vector];
+ t = tally[i];
+ assert(t);
+
+ from = froms[i];
+ to = tos[i];
+
+ j = lowzero - from[0];
+ for (k = 1; k < t; ++k)
+ if (lowzero - from[k] > j)
+ j = lowzero - from[k];
+ for (;; ++j) {
+ if (j == 0)
+ continue;
+ ok = 1;
+ for (k = 0; ok && k < t; k++) {
+ loc = j + from[k];
+ if (loc >= maxtable) {
+ if (loc >= MAXTABLE)
+ fatal("maximum table size exceeded");
+
+ newmax = maxtable;
+ do { newmax += 200; } while (newmax <= loc);
+ table = (short *) realloc(table, newmax*sizeof(short));
+ if (table == 0) no_space();
+ check = (short *) realloc(check, newmax*sizeof(short));
+ if (check == 0) no_space();
+ for (l = maxtable; l < newmax; ++l) {
+ table[l] = 0;
+ check[l] = -1;
+ }
+ maxtable = newmax;
+ }
+
+ if (check[loc] != -1)
+ ok = 0;
}
- maxtable = newmax;
- }
+ for (k = 0; ok && k < vector; k++) {
+ if (pos[k] == j)
+ ok = 0;
+ }
+ if (ok) {
+ for (k = 0; k < t; k++) {
+ loc = j + from[k];
+ table[loc] = to[k];
+ check[loc] = from[k];
+ if (loc > high)
+ high = loc;
+ }
- if (check[loc] != -1)
- ok = 0;
- }
- for (k = 0; ok && k < vector; k++)
- {
- if (pos[k] == j)
- ok = 0;
- }
- if (ok)
- {
- for (k = 0; k < t; k++)
- {
- loc = j + from[k];
- table[loc] = to[k];
- check[loc] = from[k];
- if (loc > high) high = loc;
- }
-
- while (check[lowzero] != -1)
- ++lowzero;
-
- return (j);
+ while (check[lowzero] != -1)
+ ++lowzero;
+
+ return (j);
+ }
}
- }
}
@@ -690,602 +661,546 @@ pack_vector(int vector)
void
output_base(void)
{
- int i, j;
+ int i, j;
- fprintf(output_file,
+ fprintf(output_file,
"const short %ssindex[] =\n"
"\t{%39d,", symbol_prefix, base[0]);
- j = 10;
- for (i = 1; i < nstates; i++)
- {
- if (j >= 10)
- {
- if (!rflag) ++outline;
- putc('\n', output_file);
- j = 1;
- }
- else
- ++j;
-
- fprintf(output_file, "%5d,", base[i]);
- }
-
- if (!rflag) outline += 2;
- fprintf(output_file,
- "};\n"
- "const short %srindex[] =\n"
- "\t{%39d,", symbol_prefix, base[nstates]);
-
- j = 10;
- for (i = nstates + 1; i < 2*nstates; i++)
- {
- if (j >= 10)
- {
- if (!rflag) ++outline;
- putc('\n', output_file);
- j = 1;
+ j = 10;
+ for (i = 1; i < nstates; i++) {
+ if (j >= 10) {
+ if (!rflag)
+ ++outline;
+ putc('\n', output_file);
+ j = 1;
+ } else
+ ++j;
+
+ fprintf(output_file, "%5d,", base[i]);
}
- else
- ++j;
-
- fprintf(output_file, "%5d,", base[i]);
- }
-
- if (!rflag) outline += 2;
- fprintf(output_file,
- "};\n"
- "const short %sgindex[] =\n"
- "\t{%39d,", symbol_prefix, base[2*nstates]);
-
- j = 10;
- for (i = 2*nstates + 1; i < nvectors - 1; i++)
- {
- if (j >= 10)
- {
- if (!rflag) ++outline;
- putc('\n', output_file);
- j = 1;
+
+ if (!rflag)
+ outline += 2;
+ fprintf(output_file,
+ "};\n"
+ "const short %srindex[] =\n"
+ "\t{%39d,", symbol_prefix, base[nstates]);
+
+ j = 10;
+ for (i = nstates + 1; i < 2*nstates; i++) {
+ if (j >= 10) {
+ if (!rflag)
+ ++outline;
+ putc('\n', output_file);
+ j = 1;
+ } else
+ ++j;
+
+ fprintf(output_file, "%5d,", base[i]);
}
- else
- ++j;
- fprintf(output_file, "%5d,", base[i]);
- }
+ if (!rflag)
+ outline += 2;
+ fprintf(output_file,
+ "};\n"
+ "const short %sgindex[] =\n"
+ "\t{%39d,", symbol_prefix, base[2*nstates]);
+
+ j = 10;
+ for (i = 2*nstates + 1; i < nvectors - 1; i++) {
+ if (j >= 10) {
+ if (!rflag)
+ ++outline;
+ putc('\n', output_file);
+ j = 1;
+ } else
+ ++j;
+
+ fprintf(output_file, "%5d,", base[i]);
+ }
- if (!rflag) outline += 2;
- fprintf(output_file, "\n};\n");
- free(base);
+ if (!rflag)
+ outline += 2;
+ fprintf(output_file, "\n};\n");
+ free(base);
}
void
output_table(void)
{
- int i;
- int j;
+ int i;
+ int j;
- ++outline;
- fprintf(code_file, "#define YYTABLESIZE %d\n", high);
- fprintf(output_file,
+ ++outline;
+ fprintf(code_file, "#define YYTABLESIZE %d\n", high);
+ fprintf(output_file,
"const short %stable[] =\n"
"\t{%40d,", symbol_prefix, table[0]);
- j = 10;
- for (i = 1; i <= high; i++)
- {
- if (j >= 10)
- {
- if (!rflag) ++outline;
- putc('\n', output_file);
- j = 1;
- }
- else
- ++j;
+ j = 10;
+ for (i = 1; i <= high; i++) {
+ if (j >= 10) {
+ if (!rflag)
+ ++outline;
+ putc('\n', output_file);
+ j = 1;
+ } else
+ ++j;
- fprintf(output_file, "%5d,", table[i]);
- }
+ fprintf(output_file, "%5d,", table[i]);
+ }
- if (!rflag) outline += 2;
- fprintf(output_file, "\n};\n");
- free(table);
+ if (!rflag)
+ outline += 2;
+ fprintf(output_file, "\n};\n");
+ free(table);
}
void
output_check(void)
{
- int i;
- int j;
+ int i;
+ int j;
- fprintf(output_file,
+ fprintf(output_file,
"const short %scheck[] =\n"
"\t{%40d,", symbol_prefix, check[0]);
- j = 10;
- for (i = 1; i <= high; i++)
- {
- if (j >= 10)
- {
- if (!rflag) ++outline;
- putc('\n', output_file);
- j = 1;
- }
- else
- ++j;
+ j = 10;
+ for (i = 1; i <= high; i++) {
+ if (j >= 10) {
+ if (!rflag)
+ ++outline;
+ putc('\n', output_file);
+ j = 1;
+ } else
+ ++j;
- fprintf(output_file, "%5d,", check[i]);
- }
+ fprintf(output_file, "%5d,", check[i]);
+ }
- if (!rflag) outline += 2;
- fprintf(output_file, "\n};\n");
- free(check);
+ if (!rflag)
+ outline += 2;
+ fprintf(output_file, "\n};\n");
+ free(check);
}
int
is_C_identifier(char *name)
{
- char *s;
- int c;
-
- s = name;
- c = (unsigned char)*s;
- if (c == '"')
- {
- c = (unsigned char)*++s;
+ char *s;
+ int c;
+
+ s = name;
+ c = (unsigned char)*s;
+ if (c == '"') {
+ c = (unsigned char)*++s;
+ if (!isalpha(c) && c != '_' && c != '$')
+ return (0);
+ while ((c = (unsigned char)*++s) != '"') {
+ if (!isalnum(c) && c != '_' && c != '$')
+ return (0);
+ }
+ return (1);
+ }
+
if (!isalpha(c) && c != '_' && c != '$')
- return (0);
- while ((c = (unsigned char)*++s) != '"')
- {
- if (!isalnum(c) && c != '_' && c != '$')
return (0);
+ while ((c = (unsigned char)*++s)) {
+ if (!isalnum(c) && c != '_' && c != '$')
+ return (0);
}
return (1);
- }
-
- if (!isalpha(c) && c != '_' && c != '$')
- return (0);
- while ((c = (unsigned char)*++s))
- {
- if (!isalnum(c) && c != '_' && c != '$')
- return (0);
- }
- return (1);
}
void
output_defines(void)
{
- int c, i;
- char *s;
-
- for (i = 2; i < ntokens; ++i)
- {
- s = symbol_name[i];
- if (is_C_identifier(s))
- {
- fprintf(code_file, "#define ");
- if (dflag) fprintf(defines_file, "#define ");
- c = (unsigned char)*s;
- if (c == '"')
- {
- while ((c = (unsigned char)*++s) != '"')
- {
- putc(c, code_file);
- if (dflag) putc(c, defines_file);
- }
- }
- else
- {
- do
- {
- putc(c, code_file);
- if (dflag) putc(c, defines_file);
+ int c, i;
+ char *s;
+
+ for (i = 2; i < ntokens; ++i) {
+ s = symbol_name[i];
+ if (is_C_identifier(s)) {
+ fprintf(code_file, "#define ");
+ if (dflag)
+ fprintf(defines_file, "#define ");
+ c = (unsigned char)*s;
+ if (c == '"') {
+ while ((c = (unsigned char)*++s) != '"') {
+ putc(c, code_file);
+ if (dflag) putc(c, defines_file);
+ }
+ } else {
+ do {
+ putc(c, code_file);
+ if (dflag) putc(c, defines_file);
+ } while ((c = (unsigned char)*++s));
+ }
+ ++outline;
+ fprintf(code_file, " %d\n", symbol_value[i]);
+ if (dflag)
+ fprintf(defines_file, " %d\n", symbol_value[i]);
}
- while ((c = (unsigned char)*++s));
- }
- ++outline;
- fprintf(code_file, " %d\n", symbol_value[i]);
- if (dflag) fprintf(defines_file, " %d\n", symbol_value[i]);
}
- }
-
- ++outline;
- fprintf(code_file, "#define YYERRCODE %d\n", symbol_value[1]);
-
- if (dflag && unionized)
- {
- fclose(union_file);
- union_file = fopen(union_file_name, "r");
- if (union_file == NULL) open_error(union_file_name);
- while ((c = getc(union_file)) != EOF)
- putc(c, defines_file);
- fprintf(defines_file, " YYSTYPE;\n");
- fprintf(defines_file, "#endif /* YYSTYPE_DEFINED */\n");
- fprintf(defines_file, "extern YYSTYPE %slval;\n",
- symbol_prefix);
- }
+
+ ++outline;
+ fprintf(code_file, "#define YYERRCODE %d\n", symbol_value[1]);
+
+ if (dflag && unionized) {
+ fclose(union_file);
+ union_file = fopen(union_file_name, "r");
+ if (union_file == NULL)
+ open_error(union_file_name);
+ while ((c = getc(union_file)) != EOF)
+ putc(c, defines_file);
+ fprintf(defines_file, " YYSTYPE;\n");
+ fprintf(defines_file, "#endif /* YYSTYPE_DEFINED */\n");
+ fprintf(defines_file, "extern YYSTYPE %slval;\n",
+ symbol_prefix);
+ }
}
void
output_stored_text(void)
{
- int c;
- FILE *in, *out;
-
- fclose(text_file);
- text_file = fopen(text_file_name, "r");
- if (text_file == NULL)
- open_error(text_file_name);
- in = text_file;
- if ((c = getc(in)) == EOF)
- return;
- out = code_file;
- if (c == '\n')
- ++outline;
- putc(c, out);
- while ((c = getc(in)) != EOF)
- {
- if (c == '\n')
- ++outline;
+ int c;
+ FILE *in, *out;
+
+ fclose(text_file);
+ text_file = fopen(text_file_name, "r");
+ if (text_file == NULL)
+ open_error(text_file_name);
+ in = text_file;
+ if ((c = getc(in)) == EOF)
+ return;
+ out = code_file;
+ if (c == '\n')
+ ++outline;
putc(c, out);
- }
- if (!lflag)
- fprintf(out, line_format, ++outline + 1, code_file_name);
+ while ((c = getc(in)) != EOF) {
+ if (c == '\n')
+ ++outline;
+ putc(c, out);
+ }
+ if (!lflag)
+ fprintf(out, line_format, ++outline + 1, code_file_name);
}
void
output_debug(void)
{
- int i, j, k, max;
- char **symnam, *s;
-
- ++outline;
- fprintf(code_file, "#define YYFINAL %d\n", final_state);
- outline += 3;
- fprintf(code_file, "#ifndef YYDEBUG\n#define YYDEBUG %d\n#endif\n",
- tflag);
- if (rflag)
- fprintf(output_file, "#ifndef YYDEBUG\n#define YYDEBUG %d\n#endif\n",
- tflag);
+ int i, j, k, max;
+ char **symnam, *s;
- max = 0;
- for (i = 2; i < ntokens; ++i)
- if (symbol_value[i] > max)
- max = symbol_value[i];
- ++outline;
- fprintf(code_file, "#define YYMAXTOKEN %d\n", max);
-
- symnam = (char **) calloc(max+1, sizeof(char *));
- if (symnam == 0) no_space();
-
- for (i = ntokens - 1; i >= 2; --i)
- symnam[symbol_value[i]] = symbol_name[i];
- symnam[0] = "end-of-file";
-
- if (!rflag) ++outline;
- fprintf(output_file,
- "#if YYDEBUG\n"
- "const char * const %sname[] =\n"
- "\t{", symbol_prefix);
- j = 80;
- for (i = 0; i <= max; ++i)
- {
- if ((s = symnam[i]) != '\0')
- {
- if (s[0] == '"')
- {
- k = 7;
- while (*++s != '"')
- {
- ++k;
- if (*s == '\\')
- {
- k += 2;
- if (*++s == '\\')
- ++k;
- }
- }
- j += k;
- if (j > 80)
- {
- if (!rflag) ++outline;
- putc('\n', output_file);
- j = k;
- }
- fprintf(output_file, "\"\\\"");
- s = symnam[i];
- while (*++s != '"')
- {
- if (*s == '\\')
- {
- fprintf(output_file, "\\\\");
- if (*++s == '\\')
- fprintf(output_file, "\\\\");
- else
- putc(*s, output_file);
- }
- else
- putc(*s, output_file);
- }
- fprintf(output_file, "\\\"\",");
- }
- else if (s[0] == '\'')
- {
- if (s[1] == '"')
- {
- j += 7;
- if (j > 80)
- {
- if (!rflag) ++outline;
- putc('\n', output_file);
- j = 7;
- }
- fprintf(output_file, "\"'\\\"'\",");
- }
- else
- {
- k = 5;
- while (*++s != '\'')
- {
- ++k;
- if (*s == '\\')
- {
- k += 2;
- if (*++s == '\\')
- ++k;
+ ++outline;
+ fprintf(code_file, "#define YYFINAL %d\n", final_state);
+ outline += 3;
+ fprintf(code_file, "#ifndef YYDEBUG\n#define YYDEBUG %d\n#endif\n",
+ tflag);
+ if (rflag)
+ fprintf(output_file, "#ifndef YYDEBUG\n#define YYDEBUG %d\n#endif\n",
+ tflag);
+
+ max = 0;
+ for (i = 2; i < ntokens; ++i)
+ if (symbol_value[i] > max)
+ max = symbol_value[i];
+ ++outline;
+ fprintf(code_file, "#define YYMAXTOKEN %d\n", max);
+
+ symnam = (char **) calloc(max+1, sizeof(char *));
+ if (symnam == 0) no_space();
+
+ for (i = ntokens - 1; i >= 2; --i)
+ symnam[symbol_value[i]] = symbol_name[i];
+ symnam[0] = "end-of-file";
+
+ if (!rflag)
+ ++outline;
+ fprintf(output_file,
+ "#if YYDEBUG\n"
+ "const char * const %sname[] =\n"
+ "\t{", symbol_prefix);
+ j = 80;
+ for (i = 0; i <= max; ++i) {
+ if ((s = symnam[i]) != '\0') {
+ if (s[0] == '"') {
+ k = 7;
+ while (*++s != '"') {
+ ++k;
+ if (*s == '\\') {
+ k += 2;
+ if (*++s == '\\')
+ ++k;
+ }
+ }
+ j += k;
+ if (j > 80) {
+ if (!rflag) ++outline;
+ putc('\n', output_file);
+ j = k;
+ }
+ fprintf(output_file, "\"\\\"");
+ s = symnam[i];
+ while (*++s != '"') {
+ if (*s == '\\') {
+ fprintf(output_file, "\\\\");
+ if (*++s == '\\')
+ fprintf(output_file, "\\\\");
+ else
+ putc(*s, output_file);
+ } else
+ putc(*s, output_file);
+ }
+ fprintf(output_file, "\\\"\",");
+ } else if (s[0] == '\'') {
+ if (s[1] == '"') {
+ j += 7;
+ if (j > 80)
+ {
+ if (!rflag) ++outline;
+ putc('\n', output_file);
+ j = 7;
+ }
+ fprintf(output_file, "\"'\\\"'\",");
+ } else {
+ k = 5;
+ while (*++s != '\'') {
+ ++k;
+ if (*s == '\\') {
+ k += 2;
+ if (*++s == '\\')
+ ++k;
+ }
+ }
+ j += k;
+ if (j > 80) {
+ if (!rflag) ++outline;
+ putc('\n', output_file);
+ j = k;
+ }
+ fprintf(output_file, "\"'");
+ s = symnam[i];
+ while (*++s != '\'') {
+ if (*s == '\\') {
+ fprintf(output_file, "\\\\");
+ if (*++s == '\\')
+ fprintf(output_file, "\\\\");
+ else
+ putc(*s, output_file);
+ } else
+ putc(*s, output_file);
+ }
+ fprintf(output_file, "'\",");
+ }
+ } else {
+ k = strlen(s) + 3;
+ j += k;
+ if (j > 80) {
+ if (!rflag) ++outline;
+ putc('\n', output_file);
+ j = k;
+ }
+ putc('"', output_file);
+ do { putc(*s, output_file); } while (*++s);
+ fprintf(output_file, "\",");
}
- }
- j += k;
- if (j > 80)
- {
- if (!rflag) ++outline;
- putc('\n', output_file);
- j = k;
- }
- fprintf(output_file, "\"'");
- s = symnam[i];
- while (*++s != '\'')
- {
- if (*s == '\\')
- {
- fprintf(output_file, "\\\\");
- if (*++s == '\\')
- fprintf(output_file, "\\\\");
- else
- putc(*s, output_file);
+ } else {
+ j += 2;
+ if (j > 80) {
+ if (!rflag) ++outline;
+ putc('\n', output_file);
+ j = 2;
}
- else
- putc(*s, output_file);
- }
- fprintf(output_file, "'\",");
- }
- }
- else
- {
- k = strlen(s) + 3;
- j += k;
- if (j > 80)
- {
- if (!rflag) ++outline;
- putc('\n', output_file);
- j = k;
+ fprintf(output_file, "0,");
}
- putc('"', output_file);
- do { putc(*s, output_file); } while (*++s);
- fprintf(output_file, "\",");
- }
}
- else
- {
- j += 2;
- if (j > 80)
- {
- if (!rflag) ++outline;
- putc('\n', output_file);
- j = 2;
- }
- fprintf(output_file, "0,");
- }
- }
- if (!rflag) outline += 2;
- fprintf(output_file, "\n};\n");
- free(symnam);
-
- if (!rflag) ++outline;
- fprintf(output_file,
- "const char * const %srule[] =\n"
- "\t{", symbol_prefix);
- for (i = 2; i < nrules; ++i)
- {
- fprintf(output_file, "\"%s :", symbol_name[rlhs[i]]);
- for (j = rrhs[i]; ritem[j] > 0; ++j)
- {
- s = symbol_name[ritem[j]];
- if (s[0] == '"')
- {
- fprintf(output_file, " \\\"");
- while (*++s != '"')
- {
- if (*s == '\\')
- {
- if (s[1] == '\\')
- fprintf(output_file, "\\\\\\\\");
- else
- fprintf(output_file, "\\\\%c", s[1]);
- ++s;
- }
- else
- putc(*s, output_file);
+ if (!rflag)
+ outline += 2;
+ fprintf(output_file, "\n};\n");
+ free(symnam);
+
+ if (!rflag)
+ ++outline;
+ fprintf(output_file,
+ "const char * const %srule[] =\n"
+ "\t{", symbol_prefix);
+ for (i = 2; i < nrules; ++i) {
+ fprintf(output_file, "\"%s :", symbol_name[rlhs[i]]);
+ for (j = rrhs[i]; ritem[j] > 0; ++j) {
+ s = symbol_name[ritem[j]];
+ if (s[0] == '"') {
+ fprintf(output_file, " \\\"");
+ while (*++s != '"') {
+ if (*s == '\\') {
+ if (s[1] == '\\')
+ fprintf(output_file, "\\\\\\\\");
+ else
+ fprintf(output_file, "\\\\%c", s[1]);
+ ++s;
+ } else
+ putc(*s, output_file);
+ }
+ fprintf(output_file, "\\\"");
+ } else if (s[0] == '\'') {
+ if (s[1] == '"')
+ fprintf(output_file, " '\\\"'");
+ else if (s[1] == '\\') {
+ if (s[2] == '\\')
+ fprintf(output_file, " '\\\\\\\\");
+ else
+ fprintf(output_file, " '\\\\%c", s[2]);
+ s += 2;
+ while (*++s != '\'')
+ putc(*s, output_file);
+ putc('\'', output_file);
+ } else
+ fprintf(output_file, " '%c'", s[1]);
+ } else
+ fprintf(output_file, " %s", s);
}
- fprintf(output_file, "\\\"");
- }
- else if (s[0] == '\'')
- {
- if (s[1] == '"')
- fprintf(output_file, " '\\\"'");
- else if (s[1] == '\\')
- {
- if (s[2] == '\\')
- fprintf(output_file, " '\\\\\\\\");
- else
- fprintf(output_file, " '\\\\%c", s[2]);
- s += 2;
- while (*++s != '\'')
- putc(*s, output_file);
- putc('\'', output_file);
- }
- else
- fprintf(output_file, " '%c'", s[1]);
- }
- else
- fprintf(output_file, " %s", s);
+ if (!rflag)
+ ++outline;
+ fprintf(output_file, "\",\n");
}
- if (!rflag) ++outline;
- fprintf(output_file, "\",\n");
- }
- if (!rflag) outline += 2;
- fprintf(output_file, "};\n#endif\n");
+ if (!rflag)
+ outline += 2;
+ fprintf(output_file, "};\n#endif\n");
}
void
output_stype(void)
{
- if (!unionized && ntags == 0)
- {
- outline += 3;
- fprintf(code_file, "#ifndef YYSTYPE\ntypedef int YYSTYPE;\n#endif\n");
- }
+ if (!unionized && ntags == 0) {
+ outline += 3;
+ fprintf(code_file, "#ifndef YYSTYPE\ntypedef int YYSTYPE;\n#endif\n");
+ }
}
void
output_trailing_text(void)
{
- int c, last;
- FILE *in, *out;
-
- if (line == 0)
- return;
-
- in = input_file;
- out = code_file;
- c = (unsigned char)*cptr;
- if (c == '\n')
- {
- ++lineno;
- if ((c = getc(in)) == EOF)
- return;
- if (!lflag)
- {
- ++outline;
- fprintf(out, line_format, lineno, input_file_name);
- }
- if (c == '\n')
- ++outline;
- putc(c, out);
- last = c;
- }
- else
- {
- if (!lflag)
- {
- ++outline;
- fprintf(out, line_format, lineno, input_file_name);
+ int c, last;
+ FILE *in, *out;
+
+ if (line == 0)
+ return;
+
+ in = input_file;
+ out = code_file;
+ c = (unsigned char)*cptr;
+ if (c == '\n') {
+ ++lineno;
+ if ((c = getc(in)) == EOF)
+ return;
+ if (!lflag) {
+ ++outline;
+ fprintf(out, line_format, lineno, input_file_name);
+ }
+ if (c == '\n')
+ ++outline;
+ putc(c, out);
+ last = c;
+ } else {
+ if (!lflag) {
+ ++outline;
+ fprintf(out, line_format, lineno, input_file_name);
+ }
+ do {
+ putc(c, out);
+ } while ((c = (unsigned char)*++cptr) != '\n');
+ ++outline;
+ putc('\n', out);
+ last = '\n';
}
- do { putc(c, out); } while ((c = (unsigned char)*++cptr) != '\n');
- ++outline;
- putc('\n', out);
- last = '\n';
- }
- while ((c = getc(in)) != EOF)
- {
- if (c == '\n')
- ++outline;
- putc(c, out);
- last = c;
- }
+ while ((c = getc(in)) != EOF) {
+ if (c == '\n')
+ ++outline;
+ putc(c, out);
+ last = c;
+ }
- if (last != '\n')
- {
- ++outline;
- putc('\n', out);
- }
- if (!lflag)
- fprintf(out, line_format, ++outline + 1, code_file_name);
+ if (last != '\n') {
+ ++outline;
+ putc('\n', out);
+ }
+ if (!lflag)
+ fprintf(out, line_format, ++outline + 1, code_file_name);
}
void
output_semantic_actions(void)
{
- int c, last;
- FILE *out;
+ int c, last;
+ FILE *out;
- fclose(action_file);
- action_file = fopen(action_file_name, "r");
- if (action_file == NULL)
- open_error(action_file_name);
+ fclose(action_file);
+ action_file = fopen(action_file_name, "r");
+ if (action_file == NULL)
+ open_error(action_file_name);
- if ((c = getc(action_file)) == EOF)
- return;
+ if ((c = getc(action_file)) == EOF)
+ return;
- out = code_file;
- last = c;
- if (c == '\n')
- ++outline;
- putc(c, out);
- while ((c = getc(action_file)) != EOF)
- {
+ out = code_file;
+ last = c;
if (c == '\n')
- ++outline;
+ ++outline;
putc(c, out);
- last = c;
- }
+ while ((c = getc(action_file)) != EOF) {
+ if (c == '\n')
+ ++outline;
+ putc(c, out);
+ last = c;
+ }
- if (last != '\n')
- {
- ++outline;
- putc('\n', out);
- }
+ if (last != '\n') {
+ ++outline;
+ putc('\n', out);
+ }
- if (!lflag)
- fprintf(out, line_format, ++outline + 1, code_file_name);
+ if (!lflag)
+ fprintf(out, line_format, ++outline + 1, code_file_name);
}
void
free_itemsets(void)
{
- core *cp, *next;
+ core *cp, *next;
- free(state_table);
- for (cp = first_state; cp; cp = next)
- {
+ free(state_table);
+ for (cp = first_state; cp; cp = next)
+ {
next = cp->next;
free(cp);
- }
+ }
}
void
free_shifts(void)
{
- shifts *sp, *next;
-
- free(shift_table);
- for (sp = first_shift; sp; sp = next)
- {
- next = sp->next;
- free(sp);
- }
+ shifts *sp, *next;
+
+ free(shift_table);
+ for (sp = first_shift; sp; sp = next) {
+ next = sp->next;
+ free(sp);
+ }
}
@@ -1293,12 +1208,11 @@ free_shifts(void)
void
free_reductions(void)
{
- reductions *rp, *next;
-
- free(reduction_table);
- for (rp = first_reduction; rp; rp = next)
- {
- next = rp->next;
- free(rp);
- }
+ reductions *rp, *next;
+
+ free(reduction_table);
+ for (rp = first_reduction; rp; rp = next) {
+ next = rp->next;
+ free(rp);
+ }
}
diff --git a/usr.bin/yacc/skeleton.c b/usr.bin/yacc/skeleton.c
index ee4e7f74835..ffefd282f64 100644
--- a/usr.bin/yacc/skeleton.c
+++ b/usr.bin/yacc/skeleton.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: skeleton.c,v 1.32 2014/02/21 02:18:00 tedu Exp $ */
+/* $OpenBSD: skeleton.c,v 1.33 2014/03/07 19:34:49 tedu Exp $ */
/* $NetBSD: skeleton.c,v 1.10 1996/03/25 00:36:18 mrg Exp $ */
/*
@@ -49,364 +49,359 @@
char *banner[] =
{
- "#include <stdlib.h>",
- "#include <string.h>",
- "#define YYBYACC 1",
- "#define YYMAJOR 1",
- "#define YYMINOR 9",
- "#define YYLEX yylex()",
- "#define YYEMPTY -1",
- "#define yyclearin (yychar=(YYEMPTY))",
- "#define yyerrok (yyerrflag=0)",
- "#define YYRECOVERING() (yyerrflag!=0)",
- NULL
+ "#include <stdlib.h>",
+ "#include <string.h>",
+ "#define YYBYACC 1",
+ "#define YYMAJOR 1",
+ "#define YYMINOR 9",
+ "#define YYLEX yylex()",
+ "#define YYEMPTY -1",
+ "#define yyclearin (yychar=(YYEMPTY))",
+ "#define yyerrok (yyerrflag=0)",
+ "#define YYRECOVERING() (yyerrflag!=0)",
+ NULL
};
char *tables[] =
{
- "extern const short yylhs[];",
- "extern const short yylen[];",
- "extern const short yydefred[];",
- "extern const short yydgoto[];",
- "extern const short yysindex[];",
- "extern const short yyrindex[];",
- "extern const short yygindex[];",
- "extern const short yytable[];",
- "extern const short yycheck[];",
- "#if YYDEBUG",
- "extern const char *const yyname[];",
- "extern const char *const yyrule[];",
- "#endif",
- NULL
+ "extern const short yylhs[];",
+ "extern const short yylen[];",
+ "extern const short yydefred[];",
+ "extern const short yydgoto[];",
+ "extern const short yysindex[];",
+ "extern const short yyrindex[];",
+ "extern const short yygindex[];",
+ "extern const short yytable[];",
+ "extern const short yycheck[];",
+ "#if YYDEBUG",
+ "extern const char *const yyname[];",
+ "extern const char *const yyrule[];",
+ "#endif",
+ NULL
};
char *header[] =
{
- "#ifdef YYSTACKSIZE",
- "#undef YYMAXDEPTH",
- "#define YYMAXDEPTH YYSTACKSIZE",
- "#else",
- "#ifdef YYMAXDEPTH",
- "#define YYSTACKSIZE YYMAXDEPTH",
- "#else",
- "#define YYSTACKSIZE 10000",
- "#define YYMAXDEPTH 10000",
- "#endif",
- "#endif",
- "#define YYINITSTACKSIZE 200",
- "/* LINTUSED */",
- "int yydebug;",
- "int yynerrs;",
- "int yyerrflag;",
- "int yychar;",
- "short *yyssp;",
- "YYSTYPE *yyvsp;",
- "YYSTYPE yyval;",
- "YYSTYPE yylval;",
- "short *yyss;",
- "short *yysslim;",
- "YYSTYPE *yyvs;",
- "unsigned int yystacksize;",
- NULL
+ "#ifdef YYSTACKSIZE",
+ "#undef YYMAXDEPTH",
+ "#define YYMAXDEPTH YYSTACKSIZE",
+ "#else",
+ "#ifdef YYMAXDEPTH",
+ "#define YYSTACKSIZE YYMAXDEPTH",
+ "#else",
+ "#define YYSTACKSIZE 10000",
+ "#define YYMAXDEPTH 10000",
+ "#endif",
+ "#endif",
+ "#define YYINITSTACKSIZE 200",
+ "/* LINTUSED */",
+ "int yydebug;",
+ "int yynerrs;",
+ "int yyerrflag;",
+ "int yychar;",
+ "short *yyssp;",
+ "YYSTYPE *yyvsp;",
+ "YYSTYPE yyval;",
+ "YYSTYPE yylval;",
+ "short *yyss;",
+ "short *yysslim;",
+ "YYSTYPE *yyvs;",
+ "unsigned int yystacksize;",
+ NULL
};
char *body[] =
{
- "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
- "static int yygrowstack(void)",
- "{",
- " unsigned int newsize;",
- " long sslen;",
- " short *newss;",
- " YYSTYPE *newvs;",
- "",
- " if ((newsize = yystacksize) == 0)",
- " newsize = YYINITSTACKSIZE;",
- " else if (newsize >= YYMAXDEPTH)",
- " return -1;",
- " else if ((newsize *= 2) > YYMAXDEPTH)",
- " newsize = YYMAXDEPTH;",
- " sslen = yyssp - yyss;",
- "#ifdef SIZE_MAX",
- "#define YY_SIZE_MAX SIZE_MAX",
- "#else",
- "#define YY_SIZE_MAX 0xffffffffU",
- "#endif",
- " if (newsize && YY_SIZE_MAX / newsize < sizeof *newss)",
- " goto bail;",
- " newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :",
- " (short *)malloc(newsize * sizeof *newss); /* overflow check above */",
- " if (newss == NULL)",
- " goto bail;",
- " yyss = newss;",
- " yyssp = newss + sslen;",
- " if (newsize && YY_SIZE_MAX / newsize < sizeof *newvs)",
- " goto bail;",
- " newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :",
- " (YYSTYPE *)malloc(newsize * sizeof *newvs); /* overflow check above */",
- " if (newvs == NULL)",
- " goto bail;",
- " yyvs = newvs;",
- " yyvsp = newvs + sslen;",
- " yystacksize = newsize;",
- " yysslim = yyss + newsize - 1;",
- " return 0;",
- "bail:",
- " if (yyss)",
- " free(yyss);",
- " if (yyvs)",
- " free(yyvs);",
- " yyss = yyssp = NULL;",
- " yyvs = yyvsp = NULL;",
- " yystacksize = 0;",
- " return -1;",
- "}",
- "",
- "#define YYABORT goto yyabort",
- "#define YYREJECT goto yyabort",
- "#define YYACCEPT goto yyaccept",
- "#define YYERROR goto yyerrlab",
- "int",
- "yyparse(void)",
- "{",
- " int yym, yyn, yystate;",
- "#if YYDEBUG",
- " const char *yys;",
- "",
- " if ((yys = getenv(\"YYDEBUG\")))",
- " {",
- " yyn = *yys;",
- " if (yyn >= '0' && yyn <= '9')",
- " yydebug = yyn - '0';",
- " }",
- "#endif /* YYDEBUG */",
- "",
- " yynerrs = 0;",
- " yyerrflag = 0;",
- " yychar = (-1);",
- "",
- " if (yyss == NULL && yygrowstack()) goto yyoverflow;",
- " yyssp = yyss;",
- " yyvsp = yyvs;",
- " *yyssp = yystate = 0;",
- "",
- "yyloop:",
- " if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
- " if (yychar < 0)",
- " {",
- " if ((yychar = yylex()) < 0) yychar = 0;",
- "#if YYDEBUG",
- " if (yydebug)",
- " {",
- " yys = 0;",
- " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
- " if (!yys) yys = \"illegal-symbol\";",
- " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
- " YYPREFIX, yystate, yychar, yys);",
- " }",
- "#endif",
- " }",
- " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
- " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
- " {",
- "#if YYDEBUG",
- " if (yydebug)",
- " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
- " YYPREFIX, yystate, yytable[yyn]);",
- "#endif",
- " if (yyssp >= yysslim && yygrowstack())",
- " {",
- " goto yyoverflow;",
- " }",
- " *++yyssp = yystate = yytable[yyn];",
- " *++yyvsp = yylval;",
- " yychar = (-1);",
- " if (yyerrflag > 0) --yyerrflag;",
- " goto yyloop;",
- " }",
- " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
- " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
- " {",
- " yyn = yytable[yyn];",
- " goto yyreduce;",
- " }",
- " if (yyerrflag) goto yyinrecovery;",
- "#if defined(lint) || defined(__GNUC__)",
- " goto yynewerror;",
- "#endif",
- "yynewerror:",
- " yyerror(\"syntax error\");",
- "#if defined(lint) || defined(__GNUC__)",
- " goto yyerrlab;",
- "#endif",
- "yyerrlab:",
- " ++yynerrs;",
- "yyinrecovery:",
- " if (yyerrflag < 3)",
- " {",
- " yyerrflag = 3;",
- " for (;;)",
- " {",
- " if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
- " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
- " {",
- "#if YYDEBUG",
- " if (yydebug)",
- " printf(\"%sdebug: state %d, error recovery shifting\\",
- " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);",
- "#endif",
- " if (yyssp >= yysslim && yygrowstack())",
- " {",
- " goto yyoverflow;",
- " }",
- " *++yyssp = yystate = yytable[yyn];",
- " *++yyvsp = yylval;",
- " goto yyloop;",
- " }",
- " else",
- " {",
- "#if YYDEBUG",
- " if (yydebug)",
- " printf(\"%sdebug: error recovery discarding state %d\
+ "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
+ "static int yygrowstack(void)",
+ "{",
+ " unsigned int newsize;",
+ " long sslen;",
+ " short *newss;",
+ " YYSTYPE *newvs;",
+ "",
+ " if ((newsize = yystacksize) == 0)",
+ " newsize = YYINITSTACKSIZE;",
+ " else if (newsize >= YYMAXDEPTH)",
+ " return -1;",
+ " else if ((newsize *= 2) > YYMAXDEPTH)",
+ " newsize = YYMAXDEPTH;",
+ " sslen = yyssp - yyss;",
+ "#ifdef SIZE_MAX",
+ "#define YY_SIZE_MAX SIZE_MAX",
+ "#else",
+ "#define YY_SIZE_MAX 0xffffffffU",
+ "#endif",
+ " if (newsize && YY_SIZE_MAX / newsize < sizeof *newss)",
+ " goto bail;",
+ " newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :",
+ " (short *)malloc(newsize * sizeof *newss); /* overflow check above */",
+ " if (newss == NULL)",
+ " goto bail;",
+ " yyss = newss;",
+ " yyssp = newss + sslen;",
+ " if (newsize && YY_SIZE_MAX / newsize < sizeof *newvs)",
+ " goto bail;",
+ " newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :",
+ " (YYSTYPE *)malloc(newsize * sizeof *newvs); /* overflow check above */",
+ " if (newvs == NULL)",
+ " goto bail;",
+ " yyvs = newvs;",
+ " yyvsp = newvs + sslen;",
+ " yystacksize = newsize;",
+ " yysslim = yyss + newsize - 1;",
+ " return 0;",
+ "bail:",
+ " if (yyss)",
+ " free(yyss);",
+ " if (yyvs)",
+ " free(yyvs);",
+ " yyss = yyssp = NULL;",
+ " yyvs = yyvsp = NULL;",
+ " yystacksize = 0;",
+ " return -1;",
+ "}",
+ "",
+ "#define YYABORT goto yyabort",
+ "#define YYREJECT goto yyabort",
+ "#define YYACCEPT goto yyaccept",
+ "#define YYERROR goto yyerrlab",
+ "int",
+ "yyparse(void)",
+ "{",
+ " int yym, yyn, yystate;",
+ "#if YYDEBUG",
+ " const char *yys;",
+ "",
+ " if ((yys = getenv(\"YYDEBUG\")))",
+ " {",
+ " yyn = *yys;",
+ " if (yyn >= '0' && yyn <= '9')",
+ " yydebug = yyn - '0';",
+ " }",
+ "#endif /* YYDEBUG */",
+ "",
+ " yynerrs = 0;",
+ " yyerrflag = 0;",
+ " yychar = (-1);",
+ "",
+ " if (yyss == NULL && yygrowstack()) goto yyoverflow;",
+ " yyssp = yyss;",
+ " yyvsp = yyvs;",
+ " *yyssp = yystate = 0;",
+ "",
+ "yyloop:",
+ " if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
+ " if (yychar < 0)",
+ " {",
+ " if ((yychar = yylex()) < 0) yychar = 0;",
+ "#if YYDEBUG",
+ " if (yydebug)",
+ " {",
+ " yys = 0;",
+ " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
+ " if (!yys) yys = \"illegal-symbol\";",
+ " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
+ " YYPREFIX, yystate, yychar, yys);",
+ " }",
+ "#endif",
+ " }",
+ " if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&",
+ " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
+ " {",
+ "#if YYDEBUG",
+ " if (yydebug)",
+ " printf(\"%sdebug: state %d, shifting to state %d\\n\",",
+ " YYPREFIX, yystate, yytable[yyn]);",
+ "#endif",
+ " if (yyssp >= yysslim && yygrowstack())",
+ " {",
+ " goto yyoverflow;",
+ " }",
+ " *++yyssp = yystate = yytable[yyn];",
+ " *++yyvsp = yylval;",
+ " yychar = (-1);",
+ " if (yyerrflag > 0) --yyerrflag;",
+ " goto yyloop;",
+ " }",
+ " if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&",
+ " yyn <= YYTABLESIZE && yycheck[yyn] == yychar)",
+ " {",
+ " yyn = yytable[yyn];",
+ " goto yyreduce;",
+ " }",
+ " if (yyerrflag) goto yyinrecovery;",
+ "#if defined(lint) || defined(__GNUC__)",
+ " goto yynewerror;",
+ "#endif",
+ "yynewerror:",
+ " yyerror(\"syntax error\");",
+ "#if defined(lint) || defined(__GNUC__)",
+ " goto yyerrlab;",
+ "#endif",
+ "yyerrlab:",
+ " ++yynerrs;",
+ "yyinrecovery:",
+ " if (yyerrflag < 3)",
+ " {",
+ " yyerrflag = 3;",
+ " for (;;)",
+ " {",
+ " if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&",
+ " yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)",
+ " {",
+ "#if YYDEBUG",
+ " if (yydebug)",
+ " printf(\"%sdebug: state %d, error recovery shifting\\",
+ " to state %d\\n\", YYPREFIX, *yyssp, yytable[yyn]);",
+ "#endif",
+ " if (yyssp >= yysslim && yygrowstack())",
+ " {",
+ " goto yyoverflow;",
+ " }",
+ " *++yyssp = yystate = yytable[yyn];",
+ " *++yyvsp = yylval;",
+ " goto yyloop;",
+ " }",
+ " else",
+ " {",
+ "#if YYDEBUG",
+ " if (yydebug)",
+ " printf(\"%sdebug: error recovery discarding state %d\
\\n\",",
- " YYPREFIX, *yyssp);",
- "#endif",
- " if (yyssp <= yyss) goto yyabort;",
- " --yyssp;",
- " --yyvsp;",
- " }",
- " }",
- " }",
- " else",
- " {",
- " if (yychar == 0) goto yyabort;",
- "#if YYDEBUG",
- " if (yydebug)",
- " {",
- " yys = 0;",
- " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
- " if (!yys) yys = \"illegal-symbol\";",
- " printf(\"%sdebug: state %d, error recovery discards token %d\
+ " YYPREFIX, *yyssp);",
+ "#endif",
+ " if (yyssp <= yyss) goto yyabort;",
+ " --yyssp;",
+ " --yyvsp;",
+ " }",
+ " }",
+ " }",
+ " else",
+ " {",
+ " if (yychar == 0) goto yyabort;",
+ "#if YYDEBUG",
+ " if (yydebug)",
+ " {",
+ " yys = 0;",
+ " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
+ " if (!yys) yys = \"illegal-symbol\";",
+ " printf(\"%sdebug: state %d, error recovery discards token %d\
(%s)\\n\",",
- " YYPREFIX, yystate, yychar, yys);",
- " }",
- "#endif",
- " yychar = (-1);",
- " goto yyloop;",
- " }",
- "yyreduce:",
- "#if YYDEBUG",
- " if (yydebug)",
- " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
- " YYPREFIX, yystate, yyn, yyrule[yyn]);",
- "#endif",
- " yym = yylen[yyn];",
- " if (yym)",
- " yyval = yyvsp[1-yym];",
- " else",
- " memset(&yyval, 0, sizeof yyval);",
- " switch (yyn)",
- " {",
- NULL
+ " YYPREFIX, yystate, yychar, yys);",
+ " }",
+ "#endif",
+ " yychar = (-1);",
+ " goto yyloop;",
+ " }",
+ "yyreduce:",
+ "#if YYDEBUG",
+ " if (yydebug)",
+ " printf(\"%sdebug: state %d, reducing by rule %d (%s)\\n\",",
+ " YYPREFIX, yystate, yyn, yyrule[yyn]);",
+ "#endif",
+ " yym = yylen[yyn];",
+ " if (yym)",
+ " yyval = yyvsp[1-yym];",
+ " else",
+ " memset(&yyval, 0, sizeof yyval);",
+ " switch (yyn)",
+ " {",
+ NULL
};
char *trailer[] =
{
- " }",
- " yyssp -= yym;",
- " yystate = *yyssp;",
- " yyvsp -= yym;",
- " yym = yylhs[yyn];",
- " if (yystate == 0 && yym == 0)",
- " {",
- "#if YYDEBUG",
- " if (yydebug)",
- " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
- " state %d\\n\", YYPREFIX, YYFINAL);",
- "#endif",
- " yystate = YYFINAL;",
- " *++yyssp = YYFINAL;",
- " *++yyvsp = yyval;",
- " if (yychar < 0)",
- " {",
- " if ((yychar = yylex()) < 0) yychar = 0;",
- "#if YYDEBUG",
- " if (yydebug)",
- " {",
- " yys = 0;",
- " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
- " if (!yys) yys = \"illegal-symbol\";",
- " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
- " YYPREFIX, YYFINAL, yychar, yys);",
- " }",
- "#endif",
- " }",
- " if (yychar == 0) goto yyaccept;",
- " goto yyloop;",
- " }",
- " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
- " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
- " yystate = yytable[yyn];",
- " else",
- " yystate = yydgoto[yym];",
- "#if YYDEBUG",
- " if (yydebug)",
- " printf(\"%sdebug: after reduction, shifting from state %d \\",
- "to state %d\\n\", YYPREFIX, *yyssp, yystate);",
- "#endif",
- " if (yyssp >= yysslim && yygrowstack())",
- " {",
- " goto yyoverflow;",
- " }",
- " *++yyssp = yystate;",
- " *++yyvsp = yyval;",
- " goto yyloop;",
- "yyoverflow:",
- " yyerror(\"yacc stack overflow\");",
- "yyabort:",
- " if (yyss)",
- " free(yyss);",
- " if (yyvs)",
- " free(yyvs);",
- " yyss = yyssp = NULL;",
- " yyvs = yyvsp = NULL;",
- " yystacksize = 0;",
- " return (1);",
- "yyaccept:",
- " if (yyss)",
- " free(yyss);",
- " if (yyvs)",
- " free(yyvs);",
- " yyss = yyssp = NULL;",
- " yyvs = yyvsp = NULL;",
- " yystacksize = 0;",
- " return (0);",
- "}",
- NULL
+ " }",
+ " yyssp -= yym;",
+ " yystate = *yyssp;",
+ " yyvsp -= yym;",
+ " yym = yylhs[yyn];",
+ " if (yystate == 0 && yym == 0)",
+ " {",
+ "#if YYDEBUG",
+ " if (yydebug)",
+ " printf(\"%sdebug: after reduction, shifting from state 0 to\\",
+ " state %d\\n\", YYPREFIX, YYFINAL);",
+ "#endif",
+ " yystate = YYFINAL;",
+ " *++yyssp = YYFINAL;",
+ " *++yyvsp = yyval;",
+ " if (yychar < 0)",
+ " {",
+ " if ((yychar = yylex()) < 0) yychar = 0;",
+ "#if YYDEBUG",
+ " if (yydebug)",
+ " {",
+ " yys = 0;",
+ " if (yychar <= YYMAXTOKEN) yys = yyname[yychar];",
+ " if (!yys) yys = \"illegal-symbol\";",
+ " printf(\"%sdebug: state %d, reading %d (%s)\\n\",",
+ " YYPREFIX, YYFINAL, yychar, yys);",
+ " }",
+ "#endif",
+ " }",
+ " if (yychar == 0) goto yyaccept;",
+ " goto yyloop;",
+ " }",
+ " if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&",
+ " yyn <= YYTABLESIZE && yycheck[yyn] == yystate)",
+ " yystate = yytable[yyn];",
+ " else",
+ " yystate = yydgoto[yym];",
+ "#if YYDEBUG",
+ " if (yydebug)",
+ " printf(\"%sdebug: after reduction, shifting from state %d \\",
+ "to state %d\\n\", YYPREFIX, *yyssp, yystate);",
+ "#endif",
+ " if (yyssp >= yysslim && yygrowstack())",
+ " {",
+ " goto yyoverflow;",
+ " }",
+ " *++yyssp = yystate;",
+ " *++yyvsp = yyval;",
+ " goto yyloop;",
+ "yyoverflow:",
+ " yyerror(\"yacc stack overflow\");",
+ "yyabort:",
+ " if (yyss)",
+ " free(yyss);",
+ " if (yyvs)",
+ " free(yyvs);",
+ " yyss = yyssp = NULL;",
+ " yyvs = yyvsp = NULL;",
+ " yystacksize = 0;",
+ " return (1);",
+ "yyaccept:",
+ " if (yyss)",
+ " free(yyss);",
+ " if (yyvs)",
+ " free(yyvs);",
+ " yyss = yyssp = NULL;",
+ " yyvs = yyvsp = NULL;",
+ " yystacksize = 0;",
+ " return (0);",
+ "}",
+ NULL
};
void
write_section(char *section[])
{
- int c;
- int i;
- char *s;
- FILE *f;
+ int c;
+ int i;
+ char *s;
+ FILE *f;
- f = code_file;
- for (i = 0; (s = section[i]); ++i)
- {
- ++outline;
- while ((c = *s))
- {
- putc(c, f);
- ++s;
+ f = code_file;
+ for (i = 0; (s = section[i]); ++i) {
+ ++outline;
+ fputs(s, f);
+ putc('\n', f);
}
- putc('\n', f);
- }
}