494 |
| that has any such conflicts. | |
| that has any such conflicts. | |
495 |
`------------------------------------------------------------------*/ |
`------------------------------------------------------------------*/ |
496 |
|
|
497 |
static rule_number_t |
static rule_t * |
498 |
action_row (state_t *state) |
action_row (state_t *state) |
499 |
{ |
{ |
500 |
int i; |
int i; |
501 |
rule_number_t default_rule = -1; |
rule_t *default_rule = NULL; |
502 |
reductions_t *redp = state->reductions; |
reductions_t *redp = state->reductions; |
503 |
transitions_t *transitions = state->transitions; |
transitions_t *transitions = state->transitions; |
504 |
errs_t *errp = state->errs; |
errs_t *errp = state->errs; |
505 |
/* set nonzero to inhibit having any default reduction */ |
/* Set to nonzero to inhibit having any default reduction. */ |
506 |
int nodefault = 0; |
int nodefault = 0; |
507 |
int conflicted = 0; |
int conflicted = 0; |
508 |
|
|
531 |
/* Now see which tokens are allowed for shifts in this state. For |
/* Now see which tokens are allowed for shifts in this state. For |
532 |
them, record the shift as the thing to do. So shift is preferred |
them, record the shift as the thing to do. So shift is preferred |
533 |
to reduce. */ |
to reduce. */ |
534 |
for (i = 0; i < transitions->num && TRANSITION_IS_SHIFT (transitions, i); i++) |
FOR_EACH_SHIFT (transitions, i) |
535 |
if (!TRANSITION_IS_DISABLED (transitions, i)) |
{ |
536 |
{ |
symbol_number_t symbol = TRANSITION_SYMBOL (transitions, i); |
537 |
symbol_number_t symbol = TRANSITION_SYMBOL (transitions, i); |
state_t *shift_state = transitions->states[i]; |
|
state_number_t shift_state = transitions->states[i]; |
|
538 |
|
|
539 |
if (actrow[symbol] != 0) |
if (actrow[symbol] != 0) |
540 |
conflicted = conflrow[symbol] = 1; |
conflicted = conflrow[symbol] = 1; |
541 |
actrow[symbol] = state_number_as_int (shift_state); |
actrow[symbol] = state_number_as_int (shift_state->number); |
542 |
|
|
543 |
/* Do not use any default reduction if there is a shift for |
/* Do not use any default reduction if there is a shift for |
544 |
error */ |
error */ |
545 |
if (symbol == errtoken->number) |
if (symbol == errtoken->number) |
546 |
nodefault = 1; |
nodefault = 1; |
547 |
} |
} |
548 |
|
|
549 |
/* See which tokens are an explicit error in this state (due to |
/* See which tokens are an explicit error in this state (due to |
550 |
%nonassoc). For them, record ACTION_MIN as the action. */ |
%nonassoc). For them, record ACTION_MIN as the action. */ |
551 |
for (i = 0; i < errp->num; i++) |
for (i = 0; i < errp->num; i++) |
552 |
{ |
{ |
553 |
symbol_number_t symbol = errp->symbols[i]; |
symbol_t *symbol = errp->symbols[i]; |
554 |
actrow[symbol] = ACTION_MIN; |
actrow[symbol->number] = ACTION_MIN; |
555 |
} |
} |
556 |
|
|
557 |
/* Now find the most common reduction and make it the default action |
/* Now find the most common reduction and make it the default action |
567 |
for (i = 0; i < state->nlookaheads; i++) |
for (i = 0; i < state->nlookaheads; i++) |
568 |
{ |
{ |
569 |
int count = 0; |
int count = 0; |
570 |
rule_number_t rule = state->lookaheads_rule[i]->number; |
rule_t *rule = state->lookaheads_rule[i]; |
571 |
symbol_number_t j; |
symbol_number_t j; |
572 |
|
|
573 |
for (j = 0; j < ntokens; j++) |
for (j = 0; j < ntokens; j++) |
574 |
if (actrow[j] == rule_number_as_item_number (rule)) |
if (actrow[j] == rule_number_as_item_number (rule->number)) |
575 |
count++; |
count++; |
576 |
|
|
577 |
if (count > max) |
if (count > max) |
591 |
{ |
{ |
592 |
int j; |
int j; |
593 |
for (j = 0; j < ntokens; j++) |
for (j = 0; j < ntokens; j++) |
594 |
if (actrow[j] == rule_number_as_item_number (default_rule) |
if (actrow[j] == rule_number_as_item_number (default_rule->number) |
595 |
&& ! (glr_parser && conflrow[j])) |
&& ! (glr_parser && conflrow[j])) |
596 |
actrow[j] = 0; |
actrow[j] = 0; |
597 |
} |
} |
601 |
/* If have no default rule, the default is an error. |
/* If have no default rule, the default is an error. |
602 |
So replace any action which says "error" with "use default". */ |
So replace any action which says "error" with "use default". */ |
603 |
|
|
604 |
if (default_rule == -1) |
if (!default_rule) |
605 |
for (i = 0; i < ntokens; i++) |
for (i = 0; i < ntokens; i++) |
606 |
if (actrow[i] == ACTION_MIN) |
if (actrow[i] == ACTION_MIN) |
607 |
actrow[i] = 0; |
actrow[i] = 0; |
689 |
|
|
690 |
for (i = 0; i < nstates; ++i) |
for (i = 0; i < nstates; ++i) |
691 |
{ |
{ |
692 |
yydefact[i] = action_row (states[i]) + 1; |
rule_t *default_rule = action_row (states[i]); |
693 |
|
yydefact[i] = default_rule ? default_rule->number + 1 : 0; |
694 |
save_row (i); |
save_row (i); |
695 |
} |
} |
696 |
|
|