diff options
Diffstat (limited to 'yacc/output.c')
-rw-r--r-- | yacc/output.c | 650 |
1 files changed, 325 insertions, 325 deletions
diff --git a/yacc/output.c b/yacc/output.c index 4fff0c9af..d7e89f5dc 100644 --- a/yacc/output.c +++ b/yacc/output.c @@ -116,14 +116,14 @@ void output_rule_data(void) j = 8; for (i = 3; i < nrules; i++) { - if (j >= 8) - { - if (!rflag) ++outline; - fprintf(output_file, "\\\n"); - j = 1; - } + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } else - ++j; + ++j; output_short(symbol_value[rlhs[i]]); } @@ -136,14 +136,14 @@ void output_rule_data(void) j = 8; for (i = 3; i < nrules; i++) { - if (j >= 8) - { - if (!rflag) ++outline; - fprintf(output_file, "\\\n"); - j = 1; - } - else - j++; + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + else + j++; output_short(rrhs[i + 1] - rrhs[i] - 1); } @@ -162,16 +162,16 @@ void output_yydefred(void) j = 8; for (i = 1; i < nstates; i++) { - if (j < 8) - ++j; - else - { - if (!rflag) ++outline; - fprintf(output_file, "\\\n"); - j = 1; - } - - output_short(defred[i] ? defred[i] - 2 : 0); + if (j < 8) + ++j; + else + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + + output_short(defred[i] ? defred[i] - 2 : 0); } if (!rflag) outline += 2; @@ -218,75 +218,75 @@ void token_actions(void) 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; - } - } + 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; + } + } } FREE(actionrow); } @@ -306,18 +306,18 @@ void goto_actions(void) j = 8; for (i = start_symbol + 2; i < nsyms; i++) { - if (j >= 8) - { - if (!rflag) ++outline; - fprintf(output_file, "\\\n"); - j = 1; - } - else - ++j; - - k = default_goto(i); - output_short(k); - save_column(i, k); + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + else + ++j; + + k = default_goto(i); + output_short(k); + save_column(i, k); } if (!rflag) outline += 2; @@ -340,20 +340,20 @@ default_goto(int symbol) if (m == n) return (0); for (i = 0; i < nstates; i++) - state_count[i] = 0; + state_count[i] = 0; for (i = m; i < n; i++) - state_count[to_state[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; - } + if (state_count[i] > max) + { + max = state_count[i]; + default_state = i; + } } return (default_state); @@ -378,8 +378,8 @@ void save_column(int symbol, int default_state) count = 0; for (i = m; i < n; i++) { - if (to_state[i] != default_state) - ++count; + if (to_state[i] != default_state) + ++count; } if (count == 0) return; @@ -390,11 +390,11 @@ void save_column(int symbol, int default_state) for (i = m; i < n; i++) { - if (to_state[i] != default_state) - { - *sp1++ = from_state[i]; - *sp2++ = to_state[i]; - } + if (to_state[i] != default_state) + { + *sp1++ = from_state[i]; + *sp2++ = to_state[i]; + } } tally[symno] = count; @@ -415,23 +415,23 @@ void sort_actions(void) for (i = 0; i < nvectors; i++) { if (tally[i] > 0) - { - t = tally[i]; - w = width[i]; - j = nentries - 1; + { + t = tally[i]; + w = width[i]; + j = nentries - 1; - while (j >= 0 && (width[order[j]] < w)) - j--; + while (j >= 0 && (width[order[j]] < w)) + j--; - while (j >= 0 && (width[order[j]] == w) && (tally[order[j]] < t)) - j--; + while (j >= 0 && (width[order[j]] == w) && (tally[order[j]] < t)) + j--; - for (k = nentries - 1; k > j; k--) - order[k + 1] = order[k]; + for (k = nentries - 1; k > j; k--) + order[k + 1] = order[k]; - order[j + 1] = i; - nentries++; - } + order[j + 1] = i; + nentries++; + } } } @@ -453,27 +453,27 @@ void pack_table(void) high = 0; for (i = 0; i < maxtable; i++) - check[i] = -1; + check[i] = -1; for (i = 0; i < nentries; i++) { - state = matching_vector(i); + state = matching_vector(i); - if (state < 0) - place = pack_vector(i); - else - place = base[state]; + if (state < 0) + place = pack_vector(i); + else + place = base[state]; - pos[i] = place; - base[order[i]] = place; + 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]); + if (froms[i]) + FREE(froms[i]); + if (tos[i]) + FREE(tos[i]); } FREE(froms); @@ -482,21 +482,21 @@ void pack_table(void) } -/* The function matching_vector determines if the vector specified by */ -/* the input parameter matches a previously considered vector. The */ -/* test at the start of the function checks if the vector represents */ -/* a row of shifts over terminal symbols or a row of reductions, or a */ -/* column of shifts over a nonterminal symbol. Berkeley Yacc does not */ -/* check if a column of shifts over a nonterminal symbols matches a */ -/* previously considered vector. Because of the nature of LR parsing */ -/* tables, no two columns can match. Therefore, the only possible */ -/* match would be between a row and a column. Such matches are */ -/* unlikely. Therefore, to save time, no attempt is made to see if a */ -/* column matches a previously considered vector. */ -/* */ -/* Matching_vector is poorly designed. The test could easily be made */ -/* faster. Also, it depends on the vectors being in a specific */ -/* order. */ +/* The function matching_vector determines if the vector specified by */ +/* the input parameter matches a previously considered vector. The */ +/* test at the start of the function checks if the vector represents */ +/* a row of shifts over terminal symbols or a row of reductions, or a */ +/* column of shifts over a nonterminal symbol. Berkeley Yacc does not */ +/* check if a column of shifts over a nonterminal symbols matches a */ +/* previously considered vector. Because of the nature of LR parsing */ +/* tables, no two columns can match. Therefore, the only possible */ +/* match would be between a row and a column. Such matches are */ +/* unlikely. Therefore, to save time, no attempt is made to see if a */ +/* column matches a previously considered vector. */ +/* */ +/* Matching_vector is poorly designed. The test could easily be made */ +/* faster. Also, it depends on the vectors being in a specific */ +/* order. */ int matching_vector(int vector) @@ -511,26 +511,26 @@ matching_vector(int vector) i = order[vector]; if (i >= 2*nstates) - return (-1); + 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; - } - - if (match) - return (j); + 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; + } + + if (match) + return (j); } return (-1); @@ -558,58 +558,58 @@ pack_vector(int vector) j = lowzero - from[0]; for (k = 1; k < t; ++k) - if (lowzero - from[k] > j) - j = lowzero - from[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; - } - 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 (lowzero < maxtable && check[lowzero] != -1) - ++lowzero; - - return (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; + } + 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 (lowzero < maxtable && check[lowzero] != -1) + ++lowzero; + + return (j); + } } } @@ -625,16 +625,16 @@ void output_base(void) j = 8; for (i = 1; i < nstates; i++) { - if (j >= 8) - { - if (!rflag) ++outline; - fprintf(output_file, "\\\n"); - j = 1; - } - else - ++j; - - output_short(base[i]); + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + else + ++j; + + output_short(base[i]); } if (!rflag) outline += 2; @@ -646,16 +646,16 @@ void output_base(void) j = 8; for (i = nstates + 1; i < 2*nstates; i++) { - if (j >= 8) - { - if (!rflag) ++outline; - fprintf(output_file, "\\\n"); - j = 1; - } - else - ++j; - - output_short(base[i]); + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + else + ++j; + + output_short(base[i]); } if (!rflag) outline += 2; @@ -667,16 +667,16 @@ void output_base(void) j = 8; for (i = 2*nstates + 1; i < nvectors - 1; i++) { - if (j >= 8) - { - if (!rflag) ++outline; - fprintf(output_file, "\\\n"); - j = 1; - } - else - ++j; - - output_short(base[i]); + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + else + ++j; + + output_short(base[i]); } if (!rflag) outline += 2; @@ -699,16 +699,16 @@ void output_table(void) j = 8; for (i = 1; i <= high; i++) { - if (j >= 8) - { - if (!rflag) ++outline; - fprintf(output_file, "\\\n"); - j = 1; - } - else - ++j; - - output_short(table[i]); + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + else + ++j; + + output_short(table[i]); } if (!rflag) outline += 2; @@ -729,16 +729,16 @@ void output_check(void) j = 8; for (i = 1; i <= high; i++) { - if (j >= 8) - { - if (!rflag) ++outline; - fprintf(output_file, "\\\n"); - j = 1; - } - else - ++j; - - output_short(check[i]); + if (j >= 8) + { + if (!rflag) ++outline; + fprintf(output_file, "\\\n"); + j = 1; + } + else + ++j; + + output_short(check[i]); } if (!rflag) outline += 2; @@ -775,22 +775,22 @@ void output_stored_text(void) fclose(text_file); text_file = fopen(text_file_name, "r"); if (text_file == NULL) - open_error(text_file_name); + open_error(text_file_name); in = text_file; if ((c = getc(in)) == EOF) - return; + return; out = code_file; if (c == '\n') - ++outline; + ++outline; putc(c, out); while ((c = getc(in)) != EOF) { - if (c == '\n') - ++outline; - putc(c, out); + if (c == '\n') + ++outline; + putc(c, out); } if (!lflag) - fprintf(out, line_format, ++outline + 1, code_file_name); + fprintf(out, line_format, ++outline + 1, code_file_name); } @@ -804,54 +804,54 @@ void output_trailing_text(void) register FILE *in, *out; if (line == 0) - return; + return; in = input_file; out = code_file; c = *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; + ++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 = *++cptr) != '\n'); - ++outline; - putc('\n', out); - last = '\n'; + if (!lflag) + { + ++outline; + fprintf(out, line_format, lineno, input_file_name); + } + do { putc(c, out); } while ((c = *++cptr) != '\n'); + ++outline; + putc('\n', out); + last = '\n'; } while ((c = getc(in)) != EOF) { - if (c == '\n') - ++outline; - putc(c, out); - last = c; + if (c == '\n') + ++outline; + putc(c, out); + last = c; } if (last != '\n') { - ++outline; - putc('\n', out); + ++outline; + putc('\n', out); } if (!lflag) - fprintf(out, line_format, ++outline + 1, code_file_name); + fprintf(out, line_format, ++outline + 1, code_file_name); } @@ -863,28 +863,28 @@ void copy_file(FILE **file, char *file_name) fclose(*file); *file = fopen(file_name, "r"); if (*file == NULL) - open_error(file_name); + open_error(file_name); if ((c = getc(*file)) == EOF) - return; + return; out = code_file; last = c; if (c == '\n') - ++outline; + ++outline; putc(c, out); while ((c = getc(*file)) != EOF) { - if (c == '\n') - ++outline; - putc(c, out); - last = c; + if (c == '\n') + ++outline; + putc(c, out); + last = c; } if (last != '\n') { - ++outline; - putc('\n', out); + ++outline; + putc('\n', out); } } @@ -906,8 +906,8 @@ void free_itemsets(void) FREE(state_table); for (cp = first_state; cp; cp = next) { - next = cp->next; - FREE(cp); + next = cp->next; + FREE(cp); } } @@ -919,8 +919,8 @@ void free_shifts(void) FREE(shift_table); for (sp = first_shift; sp; sp = next) { - next = sp->next; - FREE(sp); + next = sp->next; + FREE(sp); } } @@ -933,7 +933,7 @@ void free_reductions(void) FREE(reduction_table); for (rp = first_reduction; rp; rp = next) { - next = rp->next; - FREE(rp); + next = rp->next; + FREE(rp); } } |