version 1.21, 2014/03/07 19:34:49 |
version 1.22, 2014/03/07 19:44:07 |
|
|
j = 1; |
j = 1; |
} else |
} else |
++j; |
++j; |
|
|
fprintf(output_file, "%5d,", symbol_value[rlhs[i]]); |
fprintf(output_file, "%5d,", symbol_value[rlhs[i]]); |
} |
} |
if (!rflag) |
if (!rflag) |
|
|
j = 1; |
j = 1; |
} else |
} else |
j++; |
j++; |
|
|
fprintf(output_file, "%5d,", rrhs[i + 1] - rrhs[i] - 1); |
fprintf(output_file, "%5d,", rrhs[i + 1] - rrhs[i] - 1); |
} |
} |
if (!rflag) |
if (!rflag) |
|
|
putc('\n', output_file); |
putc('\n', output_file); |
j = 1; |
j = 1; |
} |
} |
|
|
fprintf(output_file, "%5d,", (defred[i] ? defred[i] - 2 : 0)); |
fprintf(output_file, "%5d,", (defred[i] ? defred[i] - 2 : 0)); |
} |
} |
|
|
|
|
if (parser[i]) { |
if (parser[i]) { |
for (j = 0; j < 2 * ntokens; ++j) |
for (j = 0; j < 2 * ntokens; ++j) |
actionrow[j] = 0; |
actionrow[j] = 0; |
|
|
shiftcount = 0; |
shiftcount = 0; |
reducecount = 0; |
reducecount = 0; |
for (p = parser[i]; p; p = p->next) { |
for (p = parser[i]; p; p = p->next) { |
|
|
state_count = NEW2(nstates, short); |
state_count = NEW2(nstates, short); |
|
|
k = default_goto(start_symbol + 1); |
k = default_goto(start_symbol + 1); |
fprintf(output_file, |
fprintf(output_file, "const short %sdgoto[] =\n" |
"const short %sdgoto[] =\n" |
"\t{%40d,", symbol_prefix, k); |
"\t{%40d,", symbol_prefix, k); |
|
save_column(start_symbol + 1, k); |
save_column(start_symbol + 1, k); |
|
|
j = 10; |
j = 10; |
|
|
m = goto_map[symbol]; |
m = goto_map[symbol]; |
n = goto_map[symbol + 1]; |
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]]++; |
state_count[to_state[i]]++; |
|
|
max = 0; |
max = 0; |
default_state = 0; |
default_state = 0; |
|
|
fatal("maximum table size exceeded"); |
fatal("maximum table size exceeded"); |
|
|
newmax = maxtable; |
newmax = maxtable; |
do { newmax += 200; } while (newmax <= loc); |
do { |
table = (short *) realloc(table, newmax*sizeof(short)); |
newmax += 200; |
if (table == 0) no_space(); |
} while (newmax <= loc); |
check = (short *) realloc(check, newmax*sizeof(short)); |
table = realloc(table, newmax*sizeof(short)); |
if (check == 0) no_space(); |
if (table == 0) |
|
no_space(); |
|
check = realloc(check, newmax*sizeof(short)); |
|
if (check == 0) |
|
no_space(); |
for (l = maxtable; l < newmax; ++l) { |
for (l = maxtable; l < newmax; ++l) { |
table[l] = 0; |
table[l] = 0; |
check[l] = -1; |
check[l] = -1; |
|
|
{ |
{ |
int i, j; |
int i, j; |
|
|
fprintf(output_file, |
fprintf(output_file, "const short %ssindex[] =\n" |
"const short %ssindex[] =\n" |
"\t{%39d,", symbol_prefix, base[0]); |
"\t{%39d,", symbol_prefix, base[0]); |
|
|
|
j = 10; |
j = 10; |
for (i = 1; i < nstates; i++) { |
for (i = 1; i < nstates; i++) { |
|
|
j = 1; |
j = 1; |
} else |
} else |
++j; |
++j; |
|
|
fprintf(output_file, "%5d,", base[i]); |
fprintf(output_file, "%5d,", base[i]); |
} |
} |
|
|
if (!rflag) |
if (!rflag) |
outline += 2; |
outline += 2; |
fprintf(output_file, |
fprintf(output_file, "};\n" |
"};\n" |
|
"const short %srindex[] =\n" |
"const short %srindex[] =\n" |
"\t{%39d,", symbol_prefix, base[nstates]); |
"\t{%39d,", symbol_prefix, base[nstates]); |
|
|
|
|
j = 1; |
j = 1; |
} else |
} else |
++j; |
++j; |
|
|
fprintf(output_file, "%5d,", base[i]); |
fprintf(output_file, "%5d,", base[i]); |
} |
} |
|
|
if (!rflag) |
if (!rflag) |
outline += 2; |
outline += 2; |
fprintf(output_file, |
fprintf(output_file, "};\n" |
"};\n" |
|
"const short %sgindex[] =\n" |
"const short %sgindex[] =\n" |
"\t{%39d,", symbol_prefix, base[2*nstates]); |
"\t{%39d,", symbol_prefix, base[2*nstates]); |
|
|
|
|
j = 1; |
j = 1; |
} else |
} else |
++j; |
++j; |
|
|
fprintf(output_file, "%5d,", base[i]); |
fprintf(output_file, "%5d,", base[i]); |
} |
} |
|
|
|
|
|
|
++outline; |
++outline; |
fprintf(code_file, "#define YYTABLESIZE %d\n", high); |
fprintf(code_file, "#define YYTABLESIZE %d\n", high); |
fprintf(output_file, |
fprintf(output_file, "const short %stable[] =\n" |
"const short %stable[] =\n" |
"\t{%40d,", symbol_prefix, table[0]); |
"\t{%40d,", symbol_prefix, table[0]); |
|
|
|
j = 10; |
j = 10; |
for (i = 1; i <= high; i++) { |
for (i = 1; i <= high; i++) { |
|
|
j = 1; |
j = 1; |
} else |
} else |
++j; |
++j; |
|
|
fprintf(output_file, "%5d,", table[i]); |
fprintf(output_file, "%5d,", table[i]); |
} |
} |
|
|
|
|
int i; |
int i; |
int j; |
int j; |
|
|
fprintf(output_file, |
fprintf(output_file, "const short %scheck[] =\n" |
"const short %scheck[] =\n" |
"\t{%40d,", symbol_prefix, check[0]); |
"\t{%40d,", symbol_prefix, check[0]); |
|
|
|
j = 10; |
j = 10; |
for (i = 1; i <= high; i++) { |
for (i = 1; i <= high; i++) { |
|
|
j = 1; |
j = 1; |
} else |
} else |
++j; |
++j; |
|
|
fprintf(output_file, "%5d,", check[i]); |
fprintf(output_file, "%5d,", check[i]); |
} |
} |
|
|
|
|
if (c == '"') { |
if (c == '"') { |
while ((c = (unsigned char)*++s) != '"') { |
while ((c = (unsigned char)*++s) != '"') { |
putc(c, code_file); |
putc(c, code_file); |
if (dflag) putc(c, defines_file); |
if (dflag) |
|
putc(c, defines_file); |
} |
} |
} else { |
} else { |
do { |
do { |
putc(c, code_file); |
putc(c, code_file); |
if (dflag) putc(c, defines_file); |
if (dflag) |
|
putc(c, defines_file); |
} while ((c = (unsigned char)*++s)); |
} while ((c = (unsigned char)*++s)); |
} |
} |
++outline; |
++outline; |
|
|
} |
} |
j += k; |
j += k; |
if (j > 80) { |
if (j > 80) { |
if (!rflag) ++outline; |
if (!rflag) |
|
++outline; |
putc('\n', output_file); |
putc('\n', output_file); |
j = k; |
j = k; |
} |
} |
|
|
} else if (s[0] == '\'') { |
} else if (s[0] == '\'') { |
if (s[1] == '"') { |
if (s[1] == '"') { |
j += 7; |
j += 7; |
if (j > 80) |
if (j > 80) { |
{ |
if (!rflag) |
if (!rflag) ++outline; |
++outline; |
putc('\n', output_file); |
putc('\n', output_file); |
j = 7; |
j = 7; |
} |
} |
fprintf(output_file, "\"'\\\"'\","); |
fprintf(output_file, "\"'\\\"'\","); |
} else { |
} else { |
|
|
if (*s == '\\') { |
if (*s == '\\') { |
k += 2; |
k += 2; |
if (*++s == '\\') |
if (*++s == '\\') |
++k; |
++k; |
} |
} |
} |
} |
j += k; |
j += k; |
if (j > 80) { |
if (j > 80) { |
if (!rflag) ++outline; |
if (!rflag) |
|
++outline; |
putc('\n', output_file); |
putc('\n', output_file); |
j = k; |
j = k; |
} |
} |
|
|
k = strlen(s) + 3; |
k = strlen(s) + 3; |
j += k; |
j += k; |
if (j > 80) { |
if (j > 80) { |
if (!rflag) ++outline; |
if (!rflag) |
|
++outline; |
putc('\n', output_file); |
putc('\n', output_file); |
j = k; |
j = k; |
} |
} |
putc('"', output_file); |
putc('"', output_file); |
do { putc(*s, output_file); } while (*++s); |
do { |
|
putc(*s, output_file); |
|
} while (*++s); |
fprintf(output_file, "\","); |
fprintf(output_file, "\","); |
} |
} |
} else { |
} else { |
j += 2; |
j += 2; |
if (j > 80) { |
if (j > 80) { |
if (!rflag) ++outline; |
if (!rflag) |
|
++outline; |
putc('\n', output_file); |
putc('\n', output_file); |
j = 2; |
j = 2; |
} |
} |
|
|
fprintf(output_file, " \\\""); |
fprintf(output_file, " \\\""); |
while (*++s != '"') { |
while (*++s != '"') { |
if (*s == '\\') { |
if (*s == '\\') { |
if (s[1] == '\\') |
if (s[1] == '\\') |
fprintf(output_file, "\\\\\\\\"); |
fprintf(output_file, "\\\\\\\\"); |
else |
else |
fprintf(output_file, "\\\\%c", s[1]); |
fprintf(output_file, "\\\\%c", s[1]); |
++s; |
++s; |
} else |
} else |
putc(*s, output_file); |
putc(*s, output_file); |
} |
} |
fprintf(output_file, "\\\""); |
fprintf(output_file, "\\\""); |
} else if (s[0] == '\'') { |
} else if (s[0] == '\'') { |
|
|
core *cp, *next; |
core *cp, *next; |
|
|
free(state_table); |
free(state_table); |
for (cp = first_state; cp; cp = next) |
for (cp = first_state; cp; cp = next) { |
{ |
next = cp->next; |
next = cp->next; |
free(cp); |
free(cp); |
|
} |
} |
} |
} |
|
|