diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lalr.c | 16 | ||||
-rw-r--r-- | src/lalr.h | 8 | ||||
-rw-r--r-- | src/state.c | 18 | ||||
-rw-r--r-- | src/state.h | 6 |
4 files changed, 21 insertions, 27 deletions
@@ -153,8 +153,8 @@ initialize_F (void) for (goto_number i = 0; i < ngotos; ++i) { - state_number stateno = to_state[i]; - const transitions *sp = states[stateno]->transitions; + state_number dst = to_state[i]; + const transitions *sp = states[dst]->transitions; int j; FOR_EACH_SHIFT (sp, j) @@ -164,7 +164,7 @@ initialize_F (void) { symbol_number sym = TRANSITION_SYMBOL (sp, j); if (nullable[sym - ntokens]) - edge[nedges++] = map_goto (stateno, sym); + edge[nedges++] = map_goto (dst, sym); } if (nedges == 0) @@ -215,15 +215,15 @@ build_relations (void) for (rule **rulep = derives[symbol1 - ntokens]; *rulep; rulep++) { - int length = 1; - item_number const *rp; state *s = states[from_state[i]]; states1[0] = s->number; - for (rp = (*rulep)->rhs; ! item_number_is_rule_number (*rp); rp++) + int length = 1; + item_number const *rp; + for (rp = (*rulep)->rhs; 0 <= *rp; rp++) { - s = transitions_to (s->transitions, - item_number_as_symbol_number (*rp)); + symbol_number sym = item_number_as_symbol_number (*rp); + s = transitions_to (s, sym); states1[length++] = s->number; } @@ -83,8 +83,8 @@ typedef size_t goto_number; /** Index into #from_state and #to_state. All the transitions that accept a particular variable are grouped - together and GOTO_MAP[I - NTOKENS] is the index in FROM_STATE and - TO_STATE of the first of them. */ + together in FROM_STATE and TO_STATE, with indexes from GOTO_MAP[I - + NTOKENS] to GOTO_MAP[I - NTOKENS + 1] - 1 (including both). */ extern goto_number *goto_map; /** The size of #from_state and #to_state. */ @@ -96,8 +96,8 @@ extern state_number *from_state; /** State number it leads to. */ extern state_number *to_state; -/** Map a state/symbol pair into its numeric representation. */ -goto_number map_goto (state_number s0, symbol_number sym); +/** Find the goto number of the goto from S on non-terminal SYM. */ +goto_number map_goto (state_number s, symbol_number sym); /* goto_follows[i] is the set of tokens following goto i. */ extern bitsetv goto_follows; diff --git a/src/state.c b/src/state.c index b673ec4f..781e49c3 100644 --- a/src/state.c +++ b/src/state.c @@ -51,20 +51,14 @@ transitions_new (int num, state **dst) } -/*-------------------------------------------------------. -| Return the state such that SHIFTS contain a shift/goto | -| to it on SYM. Abort if none found. | -`-------------------------------------------------------*/ - state * -transitions_to (transitions *shifts, symbol_number sym) +transitions_to (state *s, symbol_number sym) { - for (int j = 0; ; j++) - { - aver (j < shifts->num); - if (TRANSITION_SYMBOL (shifts, j) == sym) - return shifts->states[j]; - } + transitions *trans = s->transitions; + for (int i = 0; i < trans->num; ++i) + if (TRANSITION_SYMBOL (trans, i) == sym) + return trans->states[i]; + abort (); } diff --git a/src/state.h b/src/state.h index 975b69d5..16066049 100644 --- a/src/state.h +++ b/src/state.h @@ -159,9 +159,9 @@ typedef struct if (!TRANSITION_IS_DISABLED (Transitions, Iter)) -/* Return the state such SHIFTS contain a shift/goto to it on SYM. - Abort if none found. */ -struct state *transitions_to (transitions *shifts, symbol_number sym); +/* The destination of the transition (shift/goto) from state S on + label SYM (term or nterm). Abort if none found. */ +struct state *transitions_to (state *s, symbol_number sym); /*-------. |