* src/state.h, src/state.c (state_reductions_set): New.
(reductions, errs): Rename as...
(reductions_t, errs_t): these.
Adjust all dependencies.
+2002-06-30 Akim Demaille <akim@epita.fr>
+
+ * src/LR0.c (save_reductions): Remove, replaced by...
+ * src/state.h, src/state.c (state_reductions_set): New.
+ (reductions, errs): Rename as...
+ (reductions_t, errs_t): these.
+ Adjust all dependencies.
+
+
2002-06-30 Akim Demaille <akim@epita.fr>
* src/LR0.c (state_list_t, state_list_append): New.
2002-06-30 Akim Demaille <akim@epita.fr>
* src/LR0.c (state_list_t, state_list_append): New.
/* See comments before new_itemsets. All the vectors of items
live inside KERNEL_ITEMS. The number of active items after
some symbol cannot be more than the number of times that symbol
/* See comments before new_itemsets. All the vectors of items
live inside KERNEL_ITEMS. The number of active items after
some symbol cannot be more than the number of times that symbol
- appears as an item, which is symbol_count[symbol].
+ appears as an item, which is SYMBOL_COUNT[SYMBOL].
We allocate that much space for each symbol. */
kernel_base = XCALLOC (item_number_t *, nsyms);
We allocate that much space for each symbol. */
kernel_base = XCALLOC (item_number_t *, nsyms);
}
/* Make a reductions structure and copy the data into it. */
}
/* Make a reductions structure and copy the data into it. */
- state->reductions = reductions_new (count);
- memcpy (state->reductions->rules, redset, count * sizeof (redset[0]));
+ state_reductions_set (state, count, redset);
if (!state->errs)
state->errs = errs_new (0);
if (!state->reductions)
if (!state->errs)
state->errs = errs_new (0);
if (!state->reductions)
- state->reductions = reductions_new (0);
+ state_reductions_set (state, 0, 0);
states[state->number] = state;
states[state->number] = state;
rule_t *redrule = state->lookaheads_rule[lookahead];
int redprec = redrule->prec->prec;
bitset lookaheads = state->lookaheads[lookahead];
rule_t *redrule = state->lookaheads_rule[lookahead];
int redprec = redrule->prec->prec;
bitset lookaheads = state->lookaheads[lookahead];
- errs *errp = errs_new (ntokens + 1);
+ errs_t *errp = errs_new (ntokens + 1);
errp->nerrs = 0;
for (i = 0; i < ntokens; i++)
errp->nerrs = 0;
for (i = 0; i < ntokens; i++)
{
int k;
int nlookaheads = 0;
{
int k;
int nlookaheads = 0;
- reductions *rp = states[i]->reductions;
+ reductions_t *rp = states[i]->reductions;
shifts_t *sp = states[i]->shifts;
/* We need a lookahead either to distinguish different
shifts_t *sp = states[i]->shifts;
/* We need a lookahead either to distinguish different
{
int i;
int default_rule = 0;
{
int i;
int default_rule = 0;
- reductions *redp = state->reductions;
+ reductions_t *redp = state->reductions;
shifts_t *shiftp = state->shifts;
shifts_t *shiftp = state->shifts;
- errs *errp = state->errs;
+ errs_t *errp = state->errs;
/* set nonzero to inhibit having any default reduction */
int nodefault = 0;
int conflicted = 0;
/* set nonzero to inhibit having any default reduction */
int nodefault = 0;
int conflicted = 0;
static void
print_errs (FILE *out, state_t *state)
{
static void
print_errs (FILE *out, state_t *state)
{
- errs *errp = state->errs;
+ errs_t *errp = state->errs;
int i;
for (i = 0; i < errp->nerrs; ++i)
int i;
for (i = 0; i < errp->nerrs; ++i)
{
int i;
shifts_t *shiftp = state->shifts;
{
int i;
shifts_t *shiftp = state->shifts;
- reductions *redp = state->reductions;
- errs *errp = state->errs;
+ reductions_t *redp = state->reductions;
+ errs_t *errp = state->errs;
int nodefault = 0;
if (redp->nreds == 0)
int nodefault = 0;
if (redp->nreds == 0)
static void
print_actions (FILE *out, state_t *state)
{
static void
print_actions (FILE *out, state_t *state)
{
- reductions *redp = state->reductions;
+ reductions_t *redp = state->reductions;
shifts_t *shiftp = state->shifts;
if (shiftp->nshifts == 0 && redp->nreds == 0)
shifts_t *shiftp = state->shifts;
if (shiftp->nshifts == 0 && redp->nreds == 0)
- shifts_t *shiftp = state->shifts;
- reductions *redp = state->reductions;
+ shifts_t *shiftp = state->shifts;
+ reductions_t *redp = state->reductions;
static char buff[10];
edge_t edge;
static char buff[10];
edge_t edge;
`-------------------------------*/
#define ERRS_ALLOC(Nerrs) \
`-------------------------------*/
#define ERRS_ALLOC(Nerrs) \
- (errs *) xcalloc ((unsigned) (sizeof (errs) \
+ (errs_t *) xcalloc ((unsigned) (sizeof (errs_t) \
+ (Nerrs - 1) * sizeof (short)), 1)
+ (Nerrs - 1) * sizeof (short)), 1)
- errs *res = ERRS_ALLOC (n);
+ errs_t *res = ERRS_ALLOC (n);
res->nerrs = n;
return res;
}
res->nerrs = n;
return res;
}
-errs *
-errs_dup (errs *src)
+errs_t *
+errs_dup (errs_t *src)
- errs *res = errs_new (src->nerrs);
+ errs_t *res = errs_new (src->nerrs);
memcpy (res->errs, src->errs, src->nerrs * sizeof (src->errs[0]));
return res;
}
memcpy (res->errs, src->errs, src->nerrs * sizeof (src->errs[0]));
return res;
}
`-------------------------------------*/
#define REDUCTIONS_ALLOC(Nreductions) \
`-------------------------------------*/
#define REDUCTIONS_ALLOC(Nreductions) \
- (reductions *) xcalloc ((unsigned) (sizeof (reductions) \
+ (reductions_t *) xcalloc ((unsigned) (sizeof (reductions_t) \
+ (Nreductions - 1) * sizeof (short)), 1)
+ (Nreductions - 1) * sizeof (short)), 1)
-reductions *
-reductions_new (int n)
+static reductions_t *
+reductions_new (int nreductions, short *reductions)
- reductions *res = REDUCTIONS_ALLOC (n);
- res->nreds = n;
+ reductions_t *res = REDUCTIONS_ALLOC (nreductions);
+ res->nreds = nreductions;
+ memcpy (res->rules, reductions, nreductions * sizeof (reductions[0]));
+/*------------------------------.
+| Set the reductions of STATE. |
+`------------------------------*/
+
+void
+state_reductions_set (state_t *state, int nreductions, short *reductions)
+{
+ state->reductions = reductions_new (nreductions, reductions);
+}
+
+
/*--------------------------------------------------------------.
| Print on OUT all the lookaheads such that this STATE wants to |
/*--------------------------------------------------------------.
| Print on OUT all the lookaheads such that this STATE wants to |
{
short nerrs;
short errs[1];
{
short nerrs;
short errs[1];
-errs *errs_new PARAMS ((int n));
-errs *errs_dup PARAMS ((errs *src));
+errs_t *errs_new PARAMS ((int n));
+errs_t *errs_dup PARAMS ((errs_t *src));
/*-------------.
| Reductions. |
`-------------*/
/*-------------.
| Reductions. |
`-------------*/
-typedef struct reductions
+typedef struct reductions_s
{
short nreds;
short rules[1];
{
short nreds;
short rules[1];
-reductions *reductions_new PARAMS ((int n));
state_number_t number;
symbol_number_t accessing_symbol;
shifts_t *shifts;
state_number_t number;
symbol_number_t accessing_symbol;
shifts_t *shifts;
- reductions *reductions;
- errs *errs;
+ reductions_t *reductions;
+ errs_t *errs;
/* Nonzero if no lookahead is needed to decide what to do in state S. */
char consistent;
/* Nonzero if no lookahead is needed to decide what to do in state S. */
char consistent;
void state_shifts_set PARAMS ((state_t *state,
int nshifts, state_number_t *shifts));
void state_shifts_set PARAMS ((state_t *state,
int nshifts, state_number_t *shifts));
+/* Set the reductions of STATE. */
+void state_reductions_set PARAMS ((state_t *state,
+ int nreductions, short *reductions));
+
/* Print on OUT all the lookaheads such that this STATE wants to
reduce this RULE. */
void state_rule_lookaheads_print PARAMS ((state_t *state, rule_t *rule,
/* Print on OUT all the lookaheads such that this STATE wants to
reduce this RULE. */
void state_rule_lookaheads_print PARAMS ((state_t *state, rule_t *rule,