mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-16 15:53:03 +00:00
* src/lalr.h, src/lalr.c (LAruleno): Replace with...
(LArule): this, which is an array to rule_t*. * src/print.c, src/conflicts.c: Adjust.
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
2002-04-07 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
* src/lalr.h, src/lalr.c (LAruleno): Replace with...
|
||||||
|
(LArule): this, which is an array to rule_t*.
|
||||||
|
* src/print.c, src/conflicts.c: Adjust.
|
||||||
|
|
||||||
|
|
||||||
2002-04-07 Akim Demaille <akim@epita.fr>
|
2002-04-07 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* src/gram.h (rule_t): Rename `number' as `user_number'.
|
* src/gram.h (rule_t): Rename `number' as `user_number'.
|
||||||
|
|||||||
@@ -46,7 +46,9 @@ log_resolution (state_t *state, int LAno, int token, const char *resolution)
|
|||||||
obstack_fgrow4 (&output_obstack,
|
obstack_fgrow4 (&output_obstack,
|
||||||
_("\
|
_("\
|
||||||
Conflict in state %d between rule %d and token %s resolved as %s.\n"),
|
Conflict in state %d between rule %d and token %s resolved as %s.\n"),
|
||||||
state->number, LAruleno[LAno], symbols[token]->tag,
|
state->number,
|
||||||
|
LArule[LAno]->number,
|
||||||
|
symbols[token]->tag,
|
||||||
resolution);
|
resolution);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +97,7 @@ resolve_sr_conflict (state_t *state, int lookahead)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
/* find the rule to reduce by to get precedence of reduction */
|
/* find the rule to reduce by to get precedence of reduction */
|
||||||
int redprec = rules[LAruleno[lookahead]].prec;
|
int redprec = LArule[lookahead]->prec;
|
||||||
errs *errp = errs_new (ntokens + 1);
|
errs *errp = errs_new (ntokens + 1);
|
||||||
errp->nerrs = 0;
|
errp->nerrs = 0;
|
||||||
|
|
||||||
@@ -172,7 +174,7 @@ set_conflicts (state_t *state)
|
|||||||
check for shift-reduce conflict, and try to resolve using
|
check for shift-reduce conflict, and try to resolve using
|
||||||
precedence */
|
precedence */
|
||||||
for (i = 0; i < state->nlookaheads; ++i)
|
for (i = 0; i < state->nlookaheads; ++i)
|
||||||
if (rules[LAruleno[state->lookaheadsp + i]].prec
|
if (LArule[state->lookaheadsp + i]->prec
|
||||||
&& !bitset_disjoint_p (LA[state->lookaheadsp + i], lookaheadset))
|
&& !bitset_disjoint_p (LA[state->lookaheadsp + i], lookaheadset))
|
||||||
{
|
{
|
||||||
resolve_sr_conflict (state, state->lookaheadsp + i);
|
resolve_sr_conflict (state, state->lookaheadsp + i);
|
||||||
|
|||||||
19
src/lalr.c
19
src/lalr.c
@@ -1,5 +1,6 @@
|
|||||||
/* Compute look-ahead criteria for bison,
|
/* Compute look-ahead criteria for bison,
|
||||||
Copyright 1984, 1986, 1989, 2000, 2001 Free Software Foundation, Inc.
|
Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of Bison, the GNU Compiler Compiler.
|
This file is part of Bison, the GNU Compiler Compiler.
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@
|
|||||||
/* All the decorated states, indexed by the state number. */
|
/* All the decorated states, indexed by the state number. */
|
||||||
state_t **states = NULL;
|
state_t **states = NULL;
|
||||||
|
|
||||||
short *LAruleno = NULL;
|
rule_t **LArule = NULL;
|
||||||
bitsetv LA = NULL;
|
bitsetv LA = NULL;
|
||||||
size_t nLA;
|
size_t nLA;
|
||||||
|
|
||||||
@@ -134,21 +135,21 @@ initialize_LA (void)
|
|||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
int j;
|
int j;
|
||||||
short *np;
|
rule_t **np;
|
||||||
|
|
||||||
/* Avoid having to special case 0. */
|
/* Avoid having to special case 0. */
|
||||||
if (!nLA)
|
if (!nLA)
|
||||||
nLA = 1;
|
nLA = 1;
|
||||||
|
|
||||||
LA = bitsetv_create (nLA, ntokens, BITSET_FIXED);
|
LA = bitsetv_create (nLA, ntokens, BITSET_FIXED);
|
||||||
LAruleno = XCALLOC (short, nLA);
|
LArule = XCALLOC (rule_t *, nLA);
|
||||||
lookback = XCALLOC (shorts *, nLA);
|
lookback = XCALLOC (shorts *, nLA);
|
||||||
|
|
||||||
np = LAruleno;
|
np = LArule;
|
||||||
for (i = 0; i < nstates; i++)
|
for (i = 0; i < nstates; i++)
|
||||||
if (!states[i]->consistent)
|
if (!states[i]->consistent)
|
||||||
for (j = 0; j < states[i]->reductions->nreds; j++)
|
for (j = 0; j < states[i]->reductions->nreds; j++)
|
||||||
*np++ = states[i]->reductions->rules[j];
|
*np++ = &rules[states[i]->reductions->rules[j]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -296,10 +297,10 @@ add_lookback_edge (state_t *state, int ruleno, int gotono)
|
|||||||
shorts *sp;
|
shorts *sp;
|
||||||
|
|
||||||
for (i = 0; i < state->nlookaheads; ++i)
|
for (i = 0; i < state->nlookaheads; ++i)
|
||||||
if (LAruleno[state->lookaheadsp + i] == ruleno)
|
if (LArule[state->lookaheadsp + i]->number == ruleno)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
assert (LAruleno[state->lookaheadsp + i] == ruleno);
|
assert (LArule[state->lookaheadsp + i]->number == ruleno);
|
||||||
|
|
||||||
sp = XCALLOC (shorts, 1);
|
sp = XCALLOC (shorts, 1);
|
||||||
sp->next = lookback[state->lookaheadsp + i];
|
sp->next = lookback[state->lookaheadsp + i];
|
||||||
@@ -561,7 +562,7 @@ lookaheads_print (FILE *out)
|
|||||||
if (bitset_test (LA[states[i]->lookaheadsp + j], j))
|
if (bitset_test (LA[states[i]->lookaheadsp + j], j))
|
||||||
fprintf (out, " on %d (%s) -> rule %d\n",
|
fprintf (out, " on %d (%s) -> rule %d\n",
|
||||||
k, symbols[k]->tag,
|
k, symbols[k]->tag,
|
||||||
-LAruleno[states[i]->lookaheadsp + j] - 1);
|
LArule[states[i]->lookaheadsp + j]->number - 1);
|
||||||
}
|
}
|
||||||
fprintf (out, "Lookaheads: END\n");
|
fprintf (out, "Lookaheads: END\n");
|
||||||
}
|
}
|
||||||
|
|||||||
15
src/lalr.h
15
src/lalr.h
@@ -1,5 +1,5 @@
|
|||||||
/* Compute look-ahead criteria for bison,
|
/* Compute look-ahead criteria for bison,
|
||||||
Copyright 1984, 1986, 1989, 2000, 2002 Free Software Foundation, Inc.
|
Copyright (C) 1984, 1986, 1989, 2000, 2002 Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of Bison, the GNU Compiler Compiler.
|
This file is part of Bison, the GNU Compiler Compiler.
|
||||||
|
|
||||||
@@ -26,6 +26,8 @@
|
|||||||
/* Import the definition of CORE, SHIFTS and REDUCTIONS. */
|
/* Import the definition of CORE, SHIFTS and REDUCTIONS. */
|
||||||
# include "state.h"
|
# include "state.h"
|
||||||
|
|
||||||
|
/* Import the definition of RULE_T. */
|
||||||
|
# include "gram.h"
|
||||||
|
|
||||||
/* Compute how to make the finite state machine deterministic; find
|
/* Compute how to make the finite state machine deterministic; find
|
||||||
which rules need lookahead in each state, and which lookahead
|
which rules need lookahead in each state, and which lookahead
|
||||||
@@ -50,16 +52,15 @@ extern short *goto_map;
|
|||||||
extern short *from_state;
|
extern short *from_state;
|
||||||
extern short *to_state;
|
extern short *to_state;
|
||||||
|
|
||||||
/* LARULENO is a vector which records the rules that need lookahead in
|
/* LARULE is a vector which records the rules that need lookahead in
|
||||||
various states. The elements of LARULENO that apply to state S are
|
various states. The elements of LARULE that apply to state S are
|
||||||
those from LOOKAHEADS[S] through LOOKAHEADS[S+1]-1. Each element
|
those from LOOKAHEADS[S] through LOOKAHEADS[S+1]-1.
|
||||||
of LARULENO is a rule number.
|
|
||||||
|
|
||||||
If LR is the length of LAruleno, then a number from 0 to LR-1 can
|
If LR is the length of LArule, then a number from 0 to LR-1 can
|
||||||
specify both a rule and a state where the rule might be applied.
|
specify both a rule and a state where the rule might be applied.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern short *LAruleno;
|
extern rule_t **LArule;
|
||||||
|
|
||||||
/* LA is a lr by ntokens matrix of bits. LA[l, i] is 1 if the rule
|
/* LA is a lr by ntokens matrix of bits. LA[l, i] is 1 if the rule
|
||||||
LAruleno[l] is applicable in the appropriate state when the next
|
LAruleno[l] is applicable in the appropriate state when the next
|
||||||
|
|||||||
@@ -348,7 +348,7 @@ action_row (state_t *state)
|
|||||||
/* and record this rule as the rule to use if that
|
/* and record this rule as the rule to use if that
|
||||||
token follows. */
|
token follows. */
|
||||||
if (bitset_test (LA[state->lookaheadsp + i], j))
|
if (bitset_test (LA[state->lookaheadsp + i], j))
|
||||||
actrow[j] = -LAruleno[state->lookaheadsp + i];
|
actrow[j] = -LArule[state->lookaheadsp + i]->number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now see which tokens are allowed for shifts in this state. For
|
/* Now see which tokens are allowed for shifts in this state. For
|
||||||
@@ -395,7 +395,7 @@ action_row (state_t *state)
|
|||||||
for (i = 0; i < state->nlookaheads; i++)
|
for (i = 0; i < state->nlookaheads; i++)
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int rule = -LAruleno[state->lookaheadsp + i];
|
int rule = -LArule[state->lookaheadsp + i]->number;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
for (j = 0; j < ntokens; j++)
|
for (j = 0; j < ntokens; j++)
|
||||||
@@ -918,7 +918,7 @@ output_actions (void)
|
|||||||
|
|
||||||
token_actions ();
|
token_actions ();
|
||||||
bitsetv_free (LA);
|
bitsetv_free (LA);
|
||||||
XFREE (LAruleno);
|
free (LArule);
|
||||||
|
|
||||||
goto_actions ();
|
goto_actions ();
|
||||||
XFREE (goto_map + ntokens);
|
XFREE (goto_map + ntokens);
|
||||||
|
|||||||
33
src/print.c
33
src/print.c
@@ -1,5 +1,6 @@
|
|||||||
/* Print information on generated parser, for bison,
|
/* Print information on generated parser, for bison,
|
||||||
Copyright 1984, 1986, 1989, 2000, 2001, 2002 Free Software Foundation, Inc.
|
Copyright (C) 1984, 1986, 1989, 2000, 2001, 2002
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
|
||||||
This file is part of Bison, the GNU Compiler Compiler.
|
This file is part of Bison, the GNU Compiler Compiler.
|
||||||
|
|
||||||
@@ -213,24 +214,26 @@ print_reductions (FILE *out, state_t *state)
|
|||||||
|
|
||||||
if (state->nlookaheads == 1 && !nodefault)
|
if (state->nlookaheads == 1 && !nodefault)
|
||||||
{
|
{
|
||||||
int default_rule = LAruleno[state->lookaheadsp];
|
rule_t *default_rule = LArule[state->lookaheadsp];
|
||||||
|
|
||||||
bitset_and (lookaheadset, LA[state->lookaheadsp], shiftset);
|
bitset_and (lookaheadset, LA[state->lookaheadsp], shiftset);
|
||||||
|
|
||||||
for (i = 0; i < ntokens; i++)
|
for (i = 0; i < ntokens; i++)
|
||||||
if (bitset_test (lookaheadset, i))
|
if (bitset_test (lookaheadset, i))
|
||||||
fprintf (out, _(" %-4s\t[reduce using rule %d (%s)]\n"),
|
fprintf (out, _(" %-4s\t[reduce using rule %d (%s)]\n"),
|
||||||
escape (symbols[i]->tag), default_rule - 1,
|
escape (symbols[i]->tag),
|
||||||
escape2 (rules[default_rule].lhs->tag));
|
default_rule->number - 1,
|
||||||
|
escape2 (default_rule->lhs->tag));
|
||||||
|
|
||||||
fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"),
|
fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"),
|
||||||
default_rule - 1, escape (rules[default_rule].lhs->tag));
|
default_rule->number - 1,
|
||||||
|
escape (default_rule->lhs->tag));
|
||||||
}
|
}
|
||||||
else if (state->nlookaheads >= 1)
|
else if (state->nlookaheads >= 1)
|
||||||
{
|
{
|
||||||
int cmax = 0;
|
int cmax = 0;
|
||||||
int default_LA = -1;
|
int default_LA = -1;
|
||||||
int default_rule = 0;
|
rule_t *default_rule = NULL;
|
||||||
|
|
||||||
if (!nodefault)
|
if (!nodefault)
|
||||||
for (i = 0; i < state->nlookaheads; ++i)
|
for (i = 0; i < state->nlookaheads; ++i)
|
||||||
@@ -248,7 +251,7 @@ print_reductions (FILE *out, state_t *state)
|
|||||||
{
|
{
|
||||||
cmax = count;
|
cmax = count;
|
||||||
default_LA = state->lookaheadsp + i;
|
default_LA = state->lookaheadsp + i;
|
||||||
default_rule = LAruleno[state->lookaheadsp + i];
|
default_rule = LArule[state->lookaheadsp + i];
|
||||||
}
|
}
|
||||||
|
|
||||||
bitset_or (shiftset, shiftset, lookaheadset);
|
bitset_or (shiftset, shiftset, lookaheadset);
|
||||||
@@ -275,8 +278,8 @@ print_reductions (FILE *out, state_t *state)
|
|||||||
fprintf (out,
|
fprintf (out,
|
||||||
_(" %-4s\treduce using rule %d (%s)\n"),
|
_(" %-4s\treduce using rule %d (%s)\n"),
|
||||||
escape (symbols[i]->tag),
|
escape (symbols[i]->tag),
|
||||||
LAruleno[state->lookaheadsp + j] - 1,
|
LArule[state->lookaheadsp + j]->number - 1,
|
||||||
escape2 (rules[LAruleno[state->lookaheadsp + j]].lhs->tag));
|
escape2 (LArule[state->lookaheadsp + j]->lhs->tag));
|
||||||
else
|
else
|
||||||
defaulted = 1;
|
defaulted = 1;
|
||||||
|
|
||||||
@@ -288,22 +291,22 @@ print_reductions (FILE *out, state_t *state)
|
|||||||
fprintf (out,
|
fprintf (out,
|
||||||
_(" %-4s\treduce using rule %d (%s)\n"),
|
_(" %-4s\treduce using rule %d (%s)\n"),
|
||||||
escape (symbols[i]->tag),
|
escape (symbols[i]->tag),
|
||||||
LAruleno[default_LA] - 1,
|
LArule[default_LA]->number - 1,
|
||||||
escape2 (rules[LAruleno[default_LA]].lhs->tag));
|
escape2 (LArule[default_LA]->lhs->tag));
|
||||||
defaulted = 0;
|
defaulted = 0;
|
||||||
fprintf (out,
|
fprintf (out,
|
||||||
_(" %-4s\t[reduce using rule %d (%s)]\n"),
|
_(" %-4s\t[reduce using rule %d (%s)]\n"),
|
||||||
escape (symbols[i]->tag),
|
escape (symbols[i]->tag),
|
||||||
LAruleno[state->lookaheadsp + j] - 1,
|
LArule[state->lookaheadsp + j]->number - 1,
|
||||||
escape2 (rules[LAruleno[state->lookaheadsp + j]].lhs->tag));
|
escape2 (LArule[state->lookaheadsp + j]->lhs->tag));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (default_LA >= 0)
|
if (default_LA >= 0)
|
||||||
fprintf (out, _(" $default\treduce using rule %d (%s)\n"),
|
fprintf (out, _(" $default\treduce using rule %d (%s)\n"),
|
||||||
default_rule - 1,
|
default_rule->number - 1,
|
||||||
escape (rules[default_rule].lhs->tag));
|
escape (default_rule->lhs->tag));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user