static int conflict_list_cnt;
static int conflict_list_free;
-/* TABLE_SIZE is the allocated size of both TABLE and CHECK.
- We start with the original hard-coded value: SHRT_MAX
- (yes, not USHRT_MAX). */
-static size_t table_size = SHRT_MAX;
+/* TABLE_SIZE is the allocated size of both TABLE and CHECK. We start
+ with more or less the original hard-coded value (which was
+ SHRT_MAX). */
+static size_t table_size = 32768;
static base_t *table = NULL;
static base_t *check = NULL;
/* The value used in TABLE to denote explicit parse errors
while (table_size <= desired)
table_size *= 2;
- if (trace_flag)
+ if (trace_flag & trace_resource)
fprintf (stderr, "growing table and check from: %d to %d\n",
old_size, table_size);
prepare_tokens (void)
{
muscle_insert_symbol_number_table ("translate",
- token_translations,
- 0, 1, max_user_token_number + 1);
+ token_translations,
+ token_translations[0],
+ 1, max_user_token_number + 1);
{
int i;
| that has any such conflicts. |
`------------------------------------------------------------------*/
-static rule_number_t
+static rule_t *
action_row (state_t *state)
{
int i;
- rule_number_t default_rule = -1;
+ rule_t *default_rule = NULL;
reductions_t *redp = state->reductions;
transitions_t *transitions = state->transitions;
errs_t *errp = state->errs;
- /* set nonzero to inhibit having any default reduction */
+ /* Set to nonzero to inhibit having any default reduction. */
int nodefault = 0;
int conflicted = 0;
/* 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. */
- for (i = 0; i < transitions->num && TRANSITION_IS_SHIFT (transitions, i); i++)
- if (!TRANSITION_IS_DISABLED (transitions, i))
- {
- symbol_number_t symbol = TRANSITION_SYMBOL (transitions, i);
- state_number_t shift_state = transitions->states[i];
+ FOR_EACH_SHIFT (transitions, i)
+ {
+ symbol_number_t symbol = TRANSITION_SYMBOL (transitions, i);
+ state_t *shift_state = transitions->states[i];
- if (actrow[symbol] != 0)
- conflicted = conflrow[symbol] = 1;
- actrow[symbol] = state_number_as_int (shift_state);
+ if (actrow[symbol] != 0)
+ conflicted = conflrow[symbol] = 1;
+ actrow[symbol] = state_number_as_int (shift_state->number);
- /* Do not use any default reduction if there is a shift for
- error */
- if (symbol == errtoken->number)
- nodefault = 1;
- }
+ /* Do not use any default reduction if there is a shift for
+ error */
+ if (symbol == errtoken->number)
+ nodefault = 1;
+ }
/* See which tokens are an explicit error in this state (due to
%nonassoc). For them, record ACTION_MIN as the action. */
for (i = 0; i < errp->num; i++)
{
- symbol_number_t symbol = errp->symbols[i];
- actrow[symbol] = ACTION_MIN;
+ symbol_t *symbol = errp->symbols[i];
+ actrow[symbol->number] = ACTION_MIN;
}
/* Now find the most common reduction and make it the default action
for (i = 0; i < state->nlookaheads; i++)
{
int count = 0;
- rule_number_t rule = state->lookaheads_rule[i]->number;
+ rule_t *rule = state->lookaheads_rule[i];
symbol_number_t j;
for (j = 0; j < ntokens; j++)
- if (actrow[j] == rule_number_as_item_number (rule))
+ if (actrow[j] == rule_number_as_item_number (rule->number))
count++;
if (count > max)
{
int j;
for (j = 0; j < ntokens; j++)
- if (actrow[j] == rule_number_as_item_number (default_rule)
+ if (actrow[j] == rule_number_as_item_number (default_rule->number)
&& ! (glr_parser && conflrow[j]))
actrow[j] = 0;
}
}
}
+ /* Find the rules which are reduced. */
+ if (!glr_parser)
+ {
+ for (i = 0; i < ntokens; i++)
+ if (actrow[i] < 0 && actrow[i] != ACTION_MIN)
+ rules[item_number_as_rule_number (actrow[i])].useful = TRUE;
+ if (default_rule)
+ default_rule->useful = TRUE;
+ }
+
/* If have no default rule, the default is an error.
So replace any action which says "error" with "use default". */
- if (default_rule == -1)
+ if (!default_rule)
for (i = 0; i < ntokens; i++)
if (actrow[i] == ACTION_MIN)
actrow[i] = 0;
token_actions (void)
{
state_number_t i;
+ rule_number_t r;
int nconflict = conflicts_total_count ();
rule_number_t *yydefact = XCALLOC (rule_number_t, nstates);
actrow = XCALLOC (action_t, ntokens);
conflrow = XCALLOC (unsigned int, ntokens);
+ /* Now that the parser was computed, we can find which rules are
+ really reduced, and which are not because of SR or RR conflicts.
+ */
+ if (!glr_parser)
+ for (r = 0; r < nrules; ++r)
+ rules[r].useful = FALSE;
+
if (glr_parser)
{
conflict_list = XCALLOC (unsigned int, 1 + 2 * nconflict);
for (i = 0; i < nstates; ++i)
{
- yydefact[i] = action_row (states[i]) + 1;
+ rule_t *default_rule = action_row (states[i]);
+ yydefact[i] = default_rule ? default_rule->number + 1 : 0;
save_row (i);
}
muscle_insert_rule_number_table ("defact", yydefact,
yydefact[0], 1, nstates);
+
+ if (!glr_parser)
+ for (r = 0; r < nrules ; ++r)
+ if (!rules[r].useful)
+ {
+ LOCATION_PRINT (stderr, rules[r].location);
+ fprintf (stderr, ": %s: %s: ",
+ _("warning"), _("rule never reduced because of conflicts"));
+ rule_print (&rules[r], stderr);
+ }
+
XFREE (actrow);
XFREE (conflrow);
XFREE (yydefact);
m4_invoke (tempfile);
/* If `debugging', keep this file alive. */
- if (!trace_flag)
+ if (!(trace_flag & trace_tools))
unlink (tempfile);
free (tempfile);