mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
* src/state.h, src/state.c (errs_new, errs_dup): New.
* src/LR0.c (set_state_table): Let all the states have an errs, even if reduced to 0. * src/print.c (print_errs, print_reductions): Adjust. * src/output.c (output_actions, action_row): Adjust. * src/conflicts.c (resolve_sr_conflict): Adjust.
This commit is contained in:
10
ChangeLog
10
ChangeLog
@@ -1,3 +1,13 @@
|
||||
2001-12-27 Akim Demaille <akim@epita.fr>
|
||||
|
||||
* src/state.h, src/state.c (errs_new, errs_dup): New.
|
||||
* src/LR0.c (set_state_table): Let all the states have an errs,
|
||||
even if reduced to 0.
|
||||
* src/print.c (print_errs, print_reductions): Adjust.
|
||||
* src/output.c (output_actions, action_row): Adjust.
|
||||
* src/conflicts.c (resolve_sr_conflict): Adjust.
|
||||
|
||||
|
||||
2001-12-27 Akim Demaille <akim@epita.fr>
|
||||
|
||||
* src/lalr.c (set_goto_map, initialize_F): Use SHIFT_SYMBOL.
|
||||
|
||||
24
src/LR0.c
24
src/LR0.c
@@ -541,22 +541,20 @@ save_reductions (void)
|
||||
static void
|
||||
set_state_table (void)
|
||||
{
|
||||
state_t *sp;
|
||||
state_table = XCALLOC (state_t *, nstates);
|
||||
|
||||
{
|
||||
state_t *sp;
|
||||
for (sp = first_state; sp; sp = sp->next)
|
||||
state_table[sp->number] = sp;
|
||||
}
|
||||
for (sp = first_state; sp; sp = sp->next)
|
||||
{
|
||||
/* Pessimization, but simplification of the code: make sure all
|
||||
the states have a shifts and errs, even if reduced to 0. */
|
||||
if (!sp->shifts)
|
||||
sp->shifts = shifts_new (0);
|
||||
if (!sp->errs)
|
||||
sp->errs = errs_new (0);
|
||||
|
||||
/* Pessimization, but simplification of the code: make sure all the
|
||||
states have a shifts, even if reduced to 0 shifts. */
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < nstates; i++)
|
||||
if (!state_table[i]->shifts)
|
||||
state_table[i]->shifts = shifts_new (0);
|
||||
}
|
||||
state_table[sp->number] = sp;
|
||||
}
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------.
|
||||
|
||||
@@ -93,8 +93,8 @@ resolve_sr_conflict (state_t *state, int lookahead)
|
||||
int i;
|
||||
/* find the rule to reduce by to get precedence of reduction */
|
||||
int redprec = rule_table[LAruleno[lookahead]].prec;
|
||||
errs *errp = ERRS_ALLOC (ntokens + 1);
|
||||
short *errtokens = errp->errs;
|
||||
errs *errp = errs_new (ntokens + 1);
|
||||
errp->nerrs = 0;
|
||||
|
||||
for (i = 0; i < ntokens; i++)
|
||||
if (BITISSET (LA (lookahead), i)
|
||||
@@ -137,17 +137,14 @@ resolve_sr_conflict (state_t *state, int lookahead)
|
||||
flush_shift (state, i);
|
||||
flush_reduce (lookahead, i);
|
||||
/* Record an explicit error for this token. */
|
||||
*errtokens++ = i;
|
||||
errp->errs[errp->nerrs++] = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
errp->nerrs = errtokens - errp->errs;
|
||||
/* Some tokens have been explicitly made errors. Allocate a
|
||||
permanent errs structure for this state, to record them. */
|
||||
i = (char *) errtokens - (char *) errp;
|
||||
state->errs = ERRS_ALLOC (i + 1);
|
||||
memcpy (state->errs, errp, i);
|
||||
state->errs = errs_dup (errp);
|
||||
free (errp);
|
||||
}
|
||||
|
||||
|
||||
15
src/output.c
15
src/output.c
@@ -375,12 +375,11 @@ action_row (state_t *state)
|
||||
|
||||
/* See which tokens are an explicit error in this state (due to
|
||||
%nonassoc). For them, record MINSHORT as the action. */
|
||||
if (errp)
|
||||
for (i = 0; i < errp->nerrs; i++)
|
||||
{
|
||||
int symbol = errp->errs[i];
|
||||
actrow[symbol] = MINSHORT;
|
||||
}
|
||||
for (i = 0; i < errp->nerrs; i++)
|
||||
{
|
||||
int symbol = errp->errs[i];
|
||||
actrow[symbol] = MINSHORT;
|
||||
}
|
||||
|
||||
/* Now find the most common reduction and make it the default action
|
||||
for this state. */
|
||||
@@ -903,9 +902,9 @@ output_actions (void)
|
||||
|
||||
for (i = 0; i < nstates; ++i)
|
||||
{
|
||||
XFREE (state_table[i]->shifts);
|
||||
free (state_table[i]->shifts);
|
||||
XFREE (state_table[i]->reductions);
|
||||
XFREE (state_table[i]->errs);
|
||||
free (state_table[i]->errs);
|
||||
free (state_table[i]);
|
||||
}
|
||||
XFREE (state_table);
|
||||
|
||||
12
src/print.c
12
src/print.c
@@ -124,16 +124,13 @@ print_errs (FILE *out, state_t *state)
|
||||
errs *errp = state->errs;
|
||||
int i;
|
||||
|
||||
if (!errp)
|
||||
return;
|
||||
|
||||
for (i = 0; i < errp->nerrs; ++i)
|
||||
if (errp->errs[i])
|
||||
fprintf (out, _(" %-4s\terror (nonassociative)\n"),
|
||||
tags[errp->errs[i]]);
|
||||
|
||||
if (i > 0)
|
||||
fputc ('\n', out);
|
||||
fputc ('\n', out);
|
||||
}
|
||||
|
||||
|
||||
@@ -192,10 +189,9 @@ print_reductions (FILE *out, state_t *state)
|
||||
SETBIT (shiftset, SHIFT_SYMBOL (shiftp, i));
|
||||
}
|
||||
|
||||
if (errp)
|
||||
for (i = 0; i < errp->nerrs; i++)
|
||||
if (errp->errs[i])
|
||||
SETBIT (shiftset, errp->errs[i]);
|
||||
for (i = 0; i < errp->nerrs; i++)
|
||||
if (errp->errs[i])
|
||||
SETBIT (shiftset, errp->errs[i]);
|
||||
|
||||
if (state->nlookaheads == 1 && !nodefault)
|
||||
{
|
||||
|
||||
31
src/state.c
31
src/state.c
@@ -26,6 +26,10 @@
|
||||
| Create a new array of N shitfs. |
|
||||
`---------------------------------*/
|
||||
|
||||
#define SHIFTS_ALLOC(Nshifts) \
|
||||
(shifts *) xcalloc ((unsigned) (sizeof (shifts) \
|
||||
+ (Nshifts - 1) * sizeof (short)), 1)
|
||||
|
||||
shifts *
|
||||
shifts_new (int n)
|
||||
{
|
||||
@@ -33,3 +37,30 @@ shifts_new (int n)
|
||||
res->nshifts = n;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/*-------------------------------.
|
||||
| Create a new array of N errs. |
|
||||
`-------------------------------*/
|
||||
|
||||
#define ERRS_ALLOC(Nerrs) \
|
||||
(errs *) xcalloc ((unsigned) (sizeof (errs) \
|
||||
+ (Nerrs - 1) * sizeof (short)), 1)
|
||||
|
||||
|
||||
errs *
|
||||
errs_new (int n)
|
||||
{
|
||||
errs *res = ERRS_ALLOC (n);
|
||||
res->nerrs = n;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
errs *
|
||||
errs_dup (errs *src)
|
||||
{
|
||||
errs *res = errs_new (src->nerrs);
|
||||
memcpy (res->errs, src->errs, src->nerrs);
|
||||
return res;
|
||||
}
|
||||
|
||||
12
src/state.h
12
src/state.h
@@ -99,12 +99,7 @@ typedef struct shifts
|
||||
short shifts[1];
|
||||
} shifts;
|
||||
|
||||
|
||||
#define SHIFTS_ALLOC(Nshifts) \
|
||||
(shifts *) xcalloc ((unsigned) (sizeof (shifts) \
|
||||
+ (Nshifts - 1) * sizeof (short)), 1)
|
||||
|
||||
shifts * shifts_new PARAMS ((int n));
|
||||
shifts *shifts_new PARAMS ((int n));
|
||||
|
||||
|
||||
/* What is the symbol which is shifted by SHIFTS->shifts[Shift]? Can
|
||||
@@ -149,9 +144,8 @@ typedef struct errs
|
||||
short errs[1];
|
||||
} errs;
|
||||
|
||||
#define ERRS_ALLOC(Nerrs) \
|
||||
(errs *) xcalloc ((unsigned) (sizeof (errs) \
|
||||
+ (Nerrs - 1) * sizeof (short)), 1)
|
||||
errs *errs_new PARAMS ((int n));
|
||||
errs *errs_dup PARAMS ((errs *src));
|
||||
|
||||
|
||||
/*-------------.
|
||||
|
||||
Reference in New Issue
Block a user