-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;
- }
-
- muscle_insert_short_table ("defgoto", yydefgoto,
- yydefgoto[0], 1, nsyms - ntokens);
- 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)