17 static short *state_count;
27 static void output_prefix(
void);
28 static void output_rule_data(
void);
29 static void output_yydefred(
void);
30 static void output_actions(
void);
31 static void token_actions(
void);
32 static void goto_actions(
void);
33 static void save_column(
int symbol,
int default_state);
34 static void sort_actions(
void);
35 static void pack_table(
void);
36 static void output_base(
void);
37 static void output_table(
void);
38 static void output_check(
void);
39 static void output_defines(
void);
40 static void output_stored_text(
void);
41 static void output_debug(
void);
42 static void output_stype(
void);
43 static void output_trailing_text(
void);
44 static void output_semantic_actions(
void);
45 static void free_itemsets(
void);
46 static void free_shifts(
void);
47 static void free_reductions(
void);
67 output_trailing_text();
69 output_semantic_actions();
136 output_rule_data(
void)
145 for (i = 3; i <
nrules; i++)
164 for (i = 3; i <
nrules; i++)
183 output_yydefred(
void)
215 froms =
NEW2(nvectors,
short *);
216 tos =
NEW2(nvectors,
short *);
217 tally =
NEW2(nvectors,
short);
218 width =
NEW2(nvectors,
short);
243 int shiftcount, reducecount;
245 short *actionrow, *r, *s;
253 for (j = 0; j < 2*
ntokens; ++j)
275 tally[
i] = shiftcount;
276 tally[nstates+
i] = reducecount;
278 width[nstates+
i] = 0;
281 froms[
i] = r =
NEW2(shiftcount,
short);
282 tos[
i] = s =
NEW2(shiftcount,
short);
297 width[
i] = max - min + 1;
301 froms[nstates+
i] = r =
NEW2(reducecount,
short);
302 tos[nstates+
i] = s =
NEW2(reducecount,
short);
307 if (actionrow[ntokens+j])
314 *s++ = actionrow[ntokens+j] - 2;
317 width[nstates+
i] = max - min + 1;
369 if (m == n)
return (0);
374 for (i = m; i < n; i++)
381 if (state_count[i] > max)
383 max = state_count[
i];
388 return (default_state);
395 save_column(
int symbol,
int default_state)
410 for (i = m; i < n; i++)
415 if (count == 0)
return;
419 froms[symno] = sp1 = sp =
NEW2(count,
short);
420 tos[symno] = sp2 =
NEW2(count,
short);
422 for (i = m; i < n; i++)
431 tally[symno] = count;
432 width[symno] = sp1[-1] - sp[0] + 1;
444 order =
NEW2(nvectors,
short);
447 for (i = 0; i < nvectors; i++)
455 while (j >= 0 && (width[order[j]] < w))
458 while (j >= 0 && (width[order[j]] == w) && (tally[order[j]] < t))
461 for (k = nentries - 1; k > j; k--)
462 order[k + 1] = order[k];
479 pos =
NEW2(nentries,
short);
482 table =
NEW2(maxtable,
short);
483 check =
NEW2(maxtable,
short);
488 for (i = 0; i < maxtable; i++)
491 for (i = 0; i < nentries; i++)
501 base[order[
i]] = place;
504 for (i = 0; i < nvectors; i++)
552 for (prev = vector - 1; prev >= 0; prev--)
555 if (width[j] != w || tally[j] != t)
559 for (k = 0; match && k < t; k++)
561 if (tos[j][k] != tos[i][k] || froms[j][k] != froms[i][k])
592 j = lowzero - from[0];
593 for (k = 1; k < t; ++k)
594 if (lowzero - from[k] > j)
595 j = lowzero - from[k];
601 for (k = 0; ok && k < t; k++)
607 fatal(
"maximum table size exceeded");
610 do { newmax += 200; }
while (newmax <= loc);
611 table = (
short *)
REALLOC(table, newmax*
sizeof(
short));
613 check = (
short *)
REALLOC(check, newmax*
sizeof(
short));
615 for (l = maxtable; l < newmax; ++l)
623 if (check[loc] != -1)
626 for (k = 0; ok && k < vector; k++)
633 for (k = 0; k < t; k++)
637 check[loc] = from[k];
638 if (loc > high) high = loc;
641 while (check[lowzero] != -1)
678 for (i = nstates + 1; i < 2*
nstates; i++)
697 for (i = 2*nstates + 1; i < nvectors - 1; i++)
725 fprintf(
code_file,
"#define YYTABLESIZE %d\n", high);
730 for (i = 1; i <= high; i++)
761 for (i = 1; i <= high; i++)
782 is_C_identifier(
char *name)
792 if (!isalpha(c) && c !=
'_' && c !=
'$')
794 while ((c = *++s) !=
'"')
796 if (!isalnum(c) && c !=
'_' && c !=
'$')
802 if (!isalpha(c) && c !=
'_' && c !=
'$')
806 if (!isalnum(c) && c !=
'_' && c !=
'$')
822 if (is_C_identifier(s))
829 while ((c = *++s) !=
'"')
858 fprintf(
defines_file,
" YYSTYPE;\nstatic YYSTYPE %slval;\n",
865 output_stored_text(
void)
872 if ((c = getc(in)) == EOF)
878 while ((c = getc(in)) != EOF)
898 fprintf(
code_file,
"#ifndef YYDEBUG\n#define YYDEBUG %d\n#endif\n",
901 fprintf(
output_file,
"#ifndef YYDEBUG\n#define YYDEBUG %d\n#endif\n",
909 fprintf(
code_file,
"#define YYMAXTOKEN %d\n", max);
911 symnam = (
char **)
MALLOC((max+1)*
sizeof(
char *));
916 for (i = 0; i <
max; ++
i)
918 for (i = ntokens - 1; i >= 2; --
i)
920 symnam[0] =
"end-of-file";
925 for (i = 0; i <=
max; ++
i)
966 else if (s[0] ==
'\'')
1001 while (*++s !=
'\'')
1074 else if (s[0] ==
'\'')
1078 else if (s[1] ==
'\\')
1085 while (*++s !=
'\'')
1110 fprintf(
code_file,
"#ifndef YYSTYPE\ntypedef int YYSTYPE;\n#endif\n");
1116 output_trailing_text(
void)
1130 if ((c = getc(in)) == EOF)
1149 do { putc(c, out); }
while ((c = *++
cptr) !=
'\n');
1155 while ((c = getc(in)) != EOF)
1174 output_semantic_actions(
void)
1237 free_reductions(
void)
void fatal(char *msg) NORETURN
#define assert(exp)
Declare that a condition should be true.
int default_goto(int symbol)
void write_section(char *section[])
reductions * first_reduction
int matching_vector(int vector)
void no_space(void) NORETURN
reductions ** reduction_table
int pack_vector(int vector)