mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-16 15:53:03 +00:00
lalr: clarify the API
* src/state.h, src/state.c (state_reduction_find): Clarify. Die on errors. * src/lalr.c (goto_list_new): New. Use it.
This commit is contained in:
16
src/lalr.c
16
src/lalr.c
@@ -54,8 +54,16 @@ typedef struct goto_list
|
|||||||
goto_number value;
|
goto_number value;
|
||||||
} goto_list;
|
} goto_list;
|
||||||
|
|
||||||
|
static goto_list *
|
||||||
|
goto_list_new (goto_number value, struct goto_list *next)
|
||||||
|
{
|
||||||
|
goto_list *res = xmalloc (sizeof *res);
|
||||||
|
res->next = next;
|
||||||
|
res->value = value;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
/* LA is an NLA by NTOKENS matrix of bits. LA[l, i] is 1 if the rule
|
/* LA is an nLA by NTOKENS matrix of bits. LA[l, i] is 1 if the rule
|
||||||
LArule[l] is applicable in the appropriate state when the next
|
LArule[l] is applicable in the appropriate state when the next
|
||||||
token is symbol i. If LA[l, i] and LA[l, j] are both 1 for i != j,
|
token is symbol i. If LA[l, i] and LA[l, j] are both 1 for i != j,
|
||||||
it is a conflict. */
|
it is a conflict. */
|
||||||
@@ -232,10 +240,8 @@ static void
|
|||||||
add_lookback_edge (state *s, rule const *r, goto_number gotono)
|
add_lookback_edge (state *s, rule const *r, goto_number gotono)
|
||||||
{
|
{
|
||||||
int ri = state_reduction_find (s, r);
|
int ri = state_reduction_find (s, r);
|
||||||
goto_list *sp = xmalloc (sizeof *sp);
|
int idx = (s->reductions->lookahead_tokens - LA) + ri;
|
||||||
sp->next = lookback[(s->reductions->lookahead_tokens - LA) + ri];
|
lookback[idx] = goto_list_new (gotono, lookback[idx]);
|
||||||
sp->value = gotono;
|
|
||||||
lookback[(s->reductions->lookahead_tokens - LA) + ri] = sp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ state_reduction_find (state *s, rule const *r)
|
|||||||
for (int i = 0; i < reds->num; ++i)
|
for (int i = 0; i < reds->num; ++i)
|
||||||
if (reds->rules[i] == r)
|
if (reds->rules[i] == r)
|
||||||
return i;
|
return i;
|
||||||
return -1;
|
abort ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -239,6 +239,8 @@ void state_transitions_set (state *s, int num, state **dst);
|
|||||||
/* Set the reductions of STATE. */
|
/* Set the reductions of STATE. */
|
||||||
void state_reductions_set (state *s, int num, rule **reds);
|
void state_reductions_set (state *s, int num, rule **reds);
|
||||||
|
|
||||||
|
/* The index of the reduction of state S that corresponds to rule R.
|
||||||
|
Aborts if there is no reduction of R in S. */
|
||||||
int state_reduction_find (state *s, rule const *r);
|
int state_reduction_find (state *s, rule const *r);
|
||||||
|
|
||||||
/* Set the errs of STATE. */
|
/* Set the errs of STATE. */
|
||||||
|
|||||||
Reference in New Issue
Block a user