mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-18 00:33:03 +00:00
Finish implementing %define lr.type.
Its value can be "LALR", "IELR", or "canonical LR". * lib/timevar.def (TV_IELR_PHASE1): New var. (TV_IELR_PHASE2): New var. (TV_IELR_PHASE3): New var. (TV_IELR_PHASE4): New var. * src/Makefile.am (bison_SOURCES): Add AnnotationList.c, AnnotationList.h, InadequacyList.c, InadequacyList.h, Sbitset.c, Sbitset.h, ielr.h, and ielr.c. * src/getargs.h, src/getargs.c (enum trace, trace_args, trace_types): Add trace_ielr. * src/lalr.h, src/lalr.c (ngotos): Export it. (F): Rename to... (goto_follows): ... this, update all uses, and export it. (set_goto_map): Export it. (map_goto): Export it. (compute_lookahead_tokens): Don't free goto_follows yet. Now handled in ielr. (initialize_LA): Export it. Move lookback allocation to... (lalr): ... here because, for canonical LR, initialize_LA must be invoked but lookback and much of the rest of LALR isn't needed. * main.c (main): Instead of lalr, invoke ielr, which invokes lalr. * src/reader.c (reader): Default lr.type to "LALR". Default lr.default_rules to "accepting" if lr.type is "canonical LR". Leave the default as "all" otherwise. Check for a valid lr.type value. * src/state.h, src/state.c (struct state_list): Add state_list member. (state_new): Initialize state_list member to NULL. (state_new_isocore): New function, exported. * tests/existing.at (AT_TEST_EXISTING_GRAMMAR): New macro that exercises all values of lr.type. (GNU AWK Grammar): Rename test group to... (GNU AWK 3.1.0 Grammar): ... this, and extend to use AT_TEST_EXISTING_GRAMMAR. (GNU Cim Grammar): Extend to use AT_TEST_EXISTING_GRAMMAR. (GNU pic Grammar): Rename test group to... (GNU pic (Groff 1.18.1) Grammar): ... this, and extend to use AT_TEST_EXISTING_GRAMMAR. * tests/reduce.at (AT_TEST_LR_TYPE): New macro that exercises all values of lr.type. (Single State Split): New test groups using AT_TEST_LR_TYPE. (Lane Split): Likewise. (Complex Lane Split): Likewise. (Split During Added Lookahead Propagation): Likewise.
This commit is contained in:
33
src/lalr.c
33
src/lalr.c
@@ -43,9 +43,10 @@
|
||||
#include "symtab.h"
|
||||
|
||||
goto_number *goto_map;
|
||||
static goto_number ngotos;
|
||||
goto_number ngotos;
|
||||
state_number *from_state;
|
||||
state_number *to_state;
|
||||
bitsetv goto_follows = NULL;
|
||||
|
||||
/* Linked list of goto numbers. */
|
||||
typedef struct goto_list
|
||||
@@ -64,17 +65,13 @@ static bitsetv LA = NULL;
|
||||
size_t nLA;
|
||||
|
||||
|
||||
/* And for the famous F variable, which name is so descriptive that a
|
||||
comment is hardly needed. <grin>. */
|
||||
static bitsetv F = NULL;
|
||||
|
||||
static goto_number **includes;
|
||||
static goto_list **lookback;
|
||||
|
||||
|
||||
|
||||
|
||||
static void
|
||||
void
|
||||
set_goto_map (void)
|
||||
{
|
||||
state_number s;
|
||||
@@ -134,12 +131,7 @@ set_goto_map (void)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------.
|
||||
| Map a state/symbol pair into its numeric representation. |
|
||||
`----------------------------------------------------------*/
|
||||
|
||||
static goto_number
|
||||
goto_number
|
||||
map_goto (state_number s0, symbol_number sym)
|
||||
{
|
||||
goto_number high;
|
||||
@@ -174,7 +166,7 @@ initialize_F (void)
|
||||
|
||||
goto_number i;
|
||||
|
||||
F = bitsetv_create (ngotos, ntokens, BITSET_FIXED);
|
||||
goto_follows = bitsetv_create (ngotos, ntokens, BITSET_FIXED);
|
||||
|
||||
for (i = 0; i < ngotos; i++)
|
||||
{
|
||||
@@ -183,7 +175,7 @@ initialize_F (void)
|
||||
|
||||
int j;
|
||||
FOR_EACH_SHIFT (sp, j)
|
||||
bitset_set (F[i], TRANSITION_SYMBOL (sp, j));
|
||||
bitset_set (goto_follows[i], TRANSITION_SYMBOL (sp, j));
|
||||
|
||||
for (; j < sp->num; j++)
|
||||
{
|
||||
@@ -203,7 +195,7 @@ initialize_F (void)
|
||||
}
|
||||
}
|
||||
|
||||
relation_digraph (reads, ngotos, &F);
|
||||
relation_digraph (reads, ngotos, &goto_follows);
|
||||
|
||||
for (i = 0; i < ngotos; i++)
|
||||
free (reads[i]);
|
||||
@@ -264,7 +256,7 @@ build_relations (void)
|
||||
{
|
||||
done = true;
|
||||
/* Each rhs ends in a rule number, and there is a
|
||||
sentinel before the first rhs, so it is safe to
|
||||
sentinel (ritem[-1]=0) before the first rhs, so it is safe to
|
||||
decrement RP here. */
|
||||
rp--;
|
||||
if (ISVAR (*rp))
|
||||
@@ -303,7 +295,7 @@ compute_FOLLOWS (void)
|
||||
{
|
||||
goto_number i;
|
||||
|
||||
relation_digraph (includes, ngotos, &F);
|
||||
relation_digraph (includes, ngotos, &goto_follows);
|
||||
|
||||
for (i = 0; i < ngotos; i++)
|
||||
free (includes[i]);
|
||||
@@ -320,14 +312,13 @@ compute_lookahead_tokens (void)
|
||||
|
||||
for (i = 0; i < nLA; i++)
|
||||
for (sp = lookback[i]; sp; sp = sp->next)
|
||||
bitset_or (LA[i], LA[i], F[sp->value]);
|
||||
bitset_or (LA[i], LA[i], goto_follows[sp->value]);
|
||||
|
||||
/* Free LOOKBACK. */
|
||||
for (i = 0; i < nLA; i++)
|
||||
LIST_FREE (goto_list, lookback[i]);
|
||||
|
||||
free (lookback);
|
||||
bitsetv_free (F);
|
||||
}
|
||||
|
||||
|
||||
@@ -373,7 +364,7 @@ state_lookahead_tokens_count (state *s, bool default_rule_only_for_accept)
|
||||
| Compute LA, NLA, and the lookahead_tokens members. |
|
||||
`----------------------------------------------------*/
|
||||
|
||||
static void
|
||||
void
|
||||
initialize_LA (void)
|
||||
{
|
||||
state_number i;
|
||||
@@ -395,7 +386,6 @@ initialize_LA (void)
|
||||
nLA = 1;
|
||||
|
||||
pLA = LA = bitsetv_create (nLA, ntokens, BITSET_FIXED);
|
||||
lookback = xcalloc (nLA, sizeof *lookback);
|
||||
|
||||
/* Initialize the members LOOKAHEAD_TOKENS for each state whose reductions
|
||||
require lookahead tokens. */
|
||||
@@ -454,6 +444,7 @@ lalr (void)
|
||||
initialize_LA ();
|
||||
set_goto_map ();
|
||||
initialize_F ();
|
||||
lookback = xcalloc (nLA, sizeof *lookback);
|
||||
build_relations ();
|
||||
compute_FOLLOWS ();
|
||||
compute_lookahead_tokens ();
|
||||
|
||||
Reference in New Issue
Block a user