-static void
-save_column (int symbol, int default_state)
-{
- int i;
- short *sp;
- short *sp1;
- short *sp2;
- int count;
- int symno = symbol - ntokens + nstates;
-
- short begin = goto_map[symbol];
- short end = goto_map[symbol + 1];
-
- count = 0;
- for (i = begin; i < end; i++)
- if (to_state[i] != default_state)
- count++;
-
- if (count == 0)
- return;
-
- froms[symno] = sp1 = sp = XCALLOC (short, count);
- tos[symno] = sp2 = XCALLOC (short, count);
-
- for (i = begin; i < end; 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;
-}
-
-static int
-default_goto (int symbol)
-{
- size_t i;
- size_t m = goto_map[symbol];
- size_t n = goto_map[symbol + 1];
- int default_state = -1;
- int max = 0;
-
- if (m == n)
- return -1;
-
- for (i = 0; i < nstates; i++)
- state_count[i] = 0;
-
- for (i = m; i < n; i++)
- state_count[to_state[i]]++;
-
- for (i = 0; i < nstates; i++)
- if (state_count[i] > max)
- {
- max = state_count[i];
- default_state = i;
- }
-
- return default_state;
-}
-
-
-/*-------------------------------------------------------------------.
-| Figure out what to do after reducing with each rule, depending on |
-| the saved state from before the beginning of parsing the data that |
-| matched this rule. |
-| |
-| The YYDEFGOTO table is output now. The detailed info is saved for |
-| putting into YYTABLE later. |
-`-------------------------------------------------------------------*/
-
-static void
-goto_actions (void)
-{
- int i;
- short *yydefgoto = XMALLOC (short, nsyms - ntokens);
-
- state_count = XCALLOC (short, nstates);
- for (i = ntokens; i < nsyms; ++i)
- {
- int default_state = default_goto (i);
- save_column (i, default_state);
- yydefgoto[i - ntokens] = default_state;
- }
-
- output_short_table (&format_obstack, yydefgoto,
- yydefgoto[0], 1, nsyms - ntokens);
- muscle_insert ("defgoto", obstack_finish (&format_obstack));
-
- XFREE (state_count);
- XFREE (yydefgoto);
-}
-
-
-/* The next few functions decide how to pack the actions and gotos
- information into yytable. */
-
-static void
-sort_actions (void)
-{
- int i;
-
- order = XCALLOC (short, nvectors);
- nentries = 0;
-
- for (i = 0; i < nvectors; i++)
- if (tally[i] > 0)
- {
- int k;
- int t = tally[i];
- int w = width[i];
- int j = nentries - 1;
-
- while (j >= 0 && (width[order[j]] < w))
- 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];
-
- order[j + 1] = i;
- nentries++;
- }
-}
-
-
-static int
-matching_state (int vector)
-{
- int i = order[vector];
- int t;
- int w;
- int prev;
-
- if (i >= (int) nstates)
- return -1;
-
- t = tally[i];
- w = width[i];
-
- for (prev = vector - 1; prev >= 0; prev--)
- {
- int j = order[prev];
- int k;
- int match = 1;
-
- if (width[j] != w || tally[j] != t)
- return -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;
-}
-
-
-static int
-pack_vector (int vector)
-{
- int i = order[vector];
- int j;
- int t = tally[i];
- int loc = 0;
- short *from = froms[i];
- short *to = tos[i];
-
- assert (t);
-
- for (j = lowzero - from[0]; j < (int) table_size; j++)
- {
- int k;
- int ok = 1;
-
- for (k = 0; ok && k < t; k++)
- {
- loc = j + from[k];
- if (loc > (int) table_size)
- table_grow (loc);
-
- if (table[loc] != 0)
- 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];
- }
-
- while (table[lowzero] != 0)
- lowzero++;
-
- if (loc > high)
- high = loc;
-
- return j;
- }
- }
-#define pack_vector_succeeded 0
- assert (pack_vector_succeeded);
- return 0;
-}
-