-/*------------------------------------------------------------------.
-| Decide what to do for each type of token if seen as the lookahead |
-| token in specified state. The value returned is used as the |
-| default action (yydefact) for the state. In addition, actrow is |
-| filled with what to do for each kind of token, index by symbol |
-| number, with zero meaning do the default action. The value |
-| MINSHORT, a very negative number, means this situation is an |
-| error. The parser recognizes this value specially. |
-| |
-| This is where conflicts are resolved. The loop over lookahead |
-| rules considered lower-numbered rules last, and the last rule |
-| considered that likes a token gets to handle it. |
-`------------------------------------------------------------------*/
-
-static int
-action_row (int state)
-{
- int i;
- int j;
- int m = 0;
- int n = 0;
- int default_rule;
- int nreds;
- int rule;
- int shift_state;
- int symbol;
- reductions *redp;
- shifts *shiftp;
- errs *errp;
- int nodefault = 0; /* set nonzero to inhibit having any default reduction */
-
- for (i = 0; i < ntokens; i++)
- actrow[i] = 0;
-
- default_rule = 0;
- nreds = 0;
- redp = state_table[state]->reductions;
-
- if (redp)
- {
- nreds = redp->nreds;
-
- if (nreds >= 1)
- {
- /* loop over all the rules available here which require
- lookahead */
- m = state_table[state]->lookaheads;
- n = state_table[state + 1]->lookaheads;
-
- for (i = n - 1; i >= m; i--)
- /* and find each token which the rule finds acceptable
- to come next */
- for (j = 0; j < ntokens; j++)
- /* and record this rule as the rule to use if that
- token follows. */
- if (BITISSET (LA (i), j))
- actrow[j] = -LAruleno[i];
- }
- }
-
- /* Now see which tokens are allowed for shifts in this state. For
- them, record the shift as the thing to do. So shift is preferred
- to reduce. */
- shiftp = state_table[state]->shifts;
- for (i = 0; i < shiftp->nshifts; i++)
- {
- shift_state = shiftp->shifts[i];
- if (!shift_state)
- continue;
-
- symbol = state_table[shift_state]->accessing_symbol;
-
- if (ISVAR (symbol))
- break;
-
- actrow[symbol] = shift_state;
-
- /* Do not use any default reduction if there is a shift for
- error */
- if (symbol == error_token_number)
- nodefault = 1;
- }
-
- /* See which tokens are an explicit error in this state (due to
- %nonassoc). For them, record MINSHORT as the action. */
- errp = state_table[state]->errs;
-
- if (errp)
- for (i = 0; i < errp->nerrs; i++)
- {
- symbol = errp->errs[i];
- actrow[symbol] = MINSHORT;
- }
-
- /* Now find the most common reduction and make it the default action
- for this state. */
-
- if (nreds >= 1 && !nodefault)
- {
- if (state_table[state]->consistent)
- default_rule = redp->rules[0];
- else
- {
- int max = 0;
- for (i = m; i < n; i++)
- {
- int count = 0;
- rule = -LAruleno[i];
-
- for (j = 0; j < ntokens; j++)
- {
- if (actrow[j] == rule)
- count++;
- }
-
- if (count > max)
- {
- max = count;
- default_rule = rule;
- }
- }
-
- /* actions which match the default are replaced with zero,
- which means "use the default" */
-
- if (max > 0)
- {
- for (j = 0; j < ntokens; j++)
- {
- if (actrow[j] == default_rule)
- actrow[j] = 0;
- }
-
- default_rule = -default_rule;
- }
- }
- }
-
- /* If have no default rule, the default is an error.
- So replace any action which says "error" with "use default". */
-
- if (default_rule == 0)
- for (j = 0; j < ntokens; j++)
- {
- if (actrow[j] == MINSHORT)
- actrow[j] = 0;
- }
-
- return default_rule;
-}