35 |
|
|
36 |
int nstates; |
int nstates; |
37 |
int final_state; |
int final_state; |
38 |
state_t *first_state = NULL; |
static state_t *first_state = NULL; |
39 |
shifts *first_shift = NULL; |
static shifts *first_shift = NULL; |
40 |
|
|
41 |
static state_t *this_state = NULL; |
static state_t *this_state = NULL; |
42 |
static state_t *last_state = NULL; |
static state_t *last_state = NULL; |
601 |
} |
} |
602 |
|
|
603 |
|
|
604 |
|
/*--------------------. |
605 |
|
| Build STATE_TABLE. | |
606 |
|
`--------------------*/ |
607 |
|
|
608 |
|
static void |
609 |
|
set_state_table (void) |
610 |
|
{ |
611 |
|
/* NSTATES + 1 because lookahead for the pseudo state number NSTATES |
612 |
|
might be used (see conflicts.c). It is too opaque for me to |
613 |
|
provide a probably less hacky implementation. --akim */ |
614 |
|
state_table = XCALLOC (state_t *, nstates + 1); |
615 |
|
|
616 |
|
{ |
617 |
|
state_t *sp; |
618 |
|
for (sp = first_state; sp; sp = sp->next) |
619 |
|
state_table[sp->number] = sp; |
620 |
|
} |
621 |
|
|
622 |
|
/* Pessimization, but simplification of the code: make sure all the |
623 |
|
states have a shifts, even if reduced to 0 shifts. */ |
624 |
|
{ |
625 |
|
int i; |
626 |
|
for (i = 0; i < nstates; i++) |
627 |
|
if (!state_table[i]->shifts) |
628 |
|
state_table[i]->shifts = shifts_new (0); |
629 |
|
} |
630 |
|
|
631 |
|
/* Initializing the lookaheads members. Please note that it must be |
632 |
|
performed after having set some of the other members which are |
633 |
|
used below. Change with extreme caution. */ |
634 |
|
{ |
635 |
|
int i; |
636 |
|
int count = 0; |
637 |
|
for (i = 0; i < nstates; i++) |
638 |
|
{ |
639 |
|
int k; |
640 |
|
reductions *rp = state_table[i]->reductions; |
641 |
|
shifts *sp = state_table[i]->shifts; |
642 |
|
|
643 |
|
state_table[i]->lookaheads = count; |
644 |
|
|
645 |
|
if (rp |
646 |
|
&& (rp->nreds > 1 || (sp->nshifts && SHIFT_IS_SHIFT (sp, 0)))) |
647 |
|
count += rp->nreds; |
648 |
|
else |
649 |
|
state_table[i]->consistent = 1; |
650 |
|
|
651 |
|
for (k = 0; k < sp->nshifts; k++) |
652 |
|
if (SHIFT_IS_ERROR (sp, k)) |
653 |
|
{ |
654 |
|
state_table[i]->consistent = 0; |
655 |
|
break; |
656 |
|
} |
657 |
|
} |
658 |
|
|
659 |
|
/* Seems to be needed by conflicts.c. */ |
660 |
|
state_table[nstates] = STATE_ALLOC (0); |
661 |
|
state_table[nstates]->lookaheads = count; |
662 |
|
} |
663 |
|
} |
664 |
|
|
665 |
/*-------------------------------------------------------------------. |
/*-------------------------------------------------------------------. |
666 |
| Compute the nondeterministic finite state machine (see state.h for | |
| Compute the nondeterministic finite state machine (see state.h for | |
667 |
| details) from the grammar. | |
| details) from the grammar. | |
705 |
|
|
706 |
/* set up initial and final states as parser wants them */ |
/* set up initial and final states as parser wants them */ |
707 |
augment_automaton (); |
augment_automaton (); |
708 |
|
|
709 |
|
/* Set up STATE_TABLE. */ |
710 |
|
set_state_table (); |
711 |
} |
} |