mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-20 17:53:02 +00:00
* src/state.h, src/state.c (state_new): New, extracted from...
* src/LR0.c (new_state): here. * src/state.h (STATE_ALLOC): Move to... * src/state.c: here. * src/LR0.h, src/LR0.c (nstates, final_state): Move to... * src/state.h, src/state.c: here.
This commit is contained in:
10
ChangeLog
10
ChangeLog
@@ -1,3 +1,13 @@
|
|||||||
|
2002-06-30 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
* src/state.h, src/state.c (state_new): New, extracted from...
|
||||||
|
* src/LR0.c (new_state): here.
|
||||||
|
* src/state.h (STATE_ALLOC): Move to...
|
||||||
|
* src/state.c: here.
|
||||||
|
* src/LR0.h, src/LR0.c (nstates, final_state): Move to...
|
||||||
|
* src/state.h, src/state.c: here.
|
||||||
|
|
||||||
|
|
||||||
2002-06-30 Akim Demaille <akim@epita.fr>
|
2002-06-30 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* src/reader.c (gensym): Rename as...
|
* src/reader.c (gensym): Rename as...
|
||||||
|
|||||||
29
src/LR0.c
29
src/LR0.c
@@ -37,10 +37,6 @@
|
|||||||
#include "lalr.h"
|
#include "lalr.h"
|
||||||
#include "reduce.h"
|
#include "reduce.h"
|
||||||
|
|
||||||
state_number_t nstates = 0;
|
|
||||||
/* FINAL_STATE is properly set by new_state when it recognizes its
|
|
||||||
accessing symbol: EOF. */
|
|
||||||
state_t *final_state = NULL;
|
|
||||||
static state_t *first_state = NULL;
|
static state_t *first_state = NULL;
|
||||||
|
|
||||||
static state_t *this_state = NULL;
|
static state_t *this_state = NULL;
|
||||||
@@ -182,37 +178,26 @@ new_itemsets (void)
|
|||||||
static state_t *
|
static state_t *
|
||||||
new_state (symbol_number_t symbol, size_t core_size, item_number_t *core)
|
new_state (symbol_number_t symbol, size_t core_size, item_number_t *core)
|
||||||
{
|
{
|
||||||
state_t *p;
|
state_t *res;
|
||||||
|
|
||||||
if (trace_flag)
|
if (trace_flag)
|
||||||
fprintf (stderr, "Entering new_state, state = %d, symbol = %d (%s)\n",
|
fprintf (stderr, "Entering new_state, state = %d, symbol = %d (%s)\n",
|
||||||
nstates, symbol, symbol_tag_get (symbols[symbol]));
|
nstates, symbol, symbol_tag_get (symbols[symbol]));
|
||||||
|
|
||||||
if (nstates >= STATE_NUMBER_MAX)
|
res = state_new (symbol, core_size, core);
|
||||||
fatal (_("too many states (max %d)"), STATE_NUMBER_MAX);
|
|
||||||
|
|
||||||
p = STATE_ALLOC (core_size);
|
|
||||||
p->accessing_symbol = symbol;
|
|
||||||
p->number = nstates;
|
|
||||||
p->solved_conflicts = NULL;
|
|
||||||
|
|
||||||
p->nitems = core_size;
|
|
||||||
memcpy (p->items, core, core_size * sizeof (core[0]));
|
|
||||||
|
|
||||||
/* If this is the eoftoken, and this is not the initial state, then
|
/* If this is the eoftoken, and this is not the initial state, then
|
||||||
this is the final state. */
|
this is the final state. */
|
||||||
if (symbol == 0 && first_state)
|
if (symbol == 0 && first_state)
|
||||||
final_state = p;
|
final_state = res;
|
||||||
|
|
||||||
if (!first_state)
|
if (!first_state)
|
||||||
first_state = p;
|
first_state = res;
|
||||||
if (last_state)
|
if (last_state)
|
||||||
last_state->next = p;
|
last_state->next = res;
|
||||||
last_state = p;
|
last_state = res;
|
||||||
|
|
||||||
nstates++;
|
return res;
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,4 @@
|
|||||||
|
|
||||||
void generate_states PARAMS ((void));
|
void generate_states PARAMS ((void));
|
||||||
|
|
||||||
extern state_number_t nstates;
|
|
||||||
extern state_t *final_state;
|
|
||||||
|
|
||||||
#endif /* !LR0_H_ */
|
#endif /* !LR0_H_ */
|
||||||
|
|||||||
63
src/state.c
63
src/state.c
@@ -20,9 +20,16 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
|
#include "complain.h"
|
||||||
#include "gram.h"
|
#include "gram.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------------.
|
||||||
|
| Shifts and Gotos. |
|
||||||
|
`-------------------*/
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------.
|
/*---------------------------------.
|
||||||
| Create a new array of N shitfs. |
|
| Create a new array of N shitfs. |
|
||||||
`---------------------------------*/
|
`---------------------------------*/
|
||||||
@@ -40,6 +47,13 @@ shifts_new (int n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*--------------------.
|
||||||
|
| Error transitions. |
|
||||||
|
`--------------------*/
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------.
|
/*-------------------------------.
|
||||||
| Create a new array of N errs. |
|
| Create a new array of N errs. |
|
||||||
`-------------------------------*/
|
`-------------------------------*/
|
||||||
@@ -66,6 +80,14 @@ errs_dup (errs *src)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*-------------.
|
||||||
|
| Reductions. |
|
||||||
|
`-------------*/
|
||||||
|
|
||||||
|
|
||||||
/*-------------------------------------.
|
/*-------------------------------------.
|
||||||
| Create a new array of N reductions. |
|
| Create a new array of N reductions. |
|
||||||
`-------------------------------------*/
|
`-------------------------------------*/
|
||||||
@@ -83,6 +105,47 @@ reductions_new (int n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*---------.
|
||||||
|
| States. |
|
||||||
|
`---------*/
|
||||||
|
|
||||||
|
|
||||||
|
state_number_t nstates = 0;
|
||||||
|
/* FINAL_STATE is properly set by new_state when it recognizes its
|
||||||
|
accessing symbol: EOF. */
|
||||||
|
state_t *final_state = NULL;
|
||||||
|
|
||||||
|
/*------------------------------------------------------------.
|
||||||
|
| Create a new state with ACCESSING_SYMBOL, for those items. |
|
||||||
|
`------------------------------------------------------------*/
|
||||||
|
|
||||||
|
state_t *
|
||||||
|
state_new (symbol_number_t accessing_symbol,
|
||||||
|
size_t core_size, item_number_t *core)
|
||||||
|
{
|
||||||
|
state_t *res;
|
||||||
|
|
||||||
|
if (nstates >= STATE_NUMBER_MAX)
|
||||||
|
fatal (_("too many states (max %d)"), STATE_NUMBER_MAX);
|
||||||
|
|
||||||
|
#define STATE_ALLOC(Nitems) \
|
||||||
|
(state_t *) xcalloc ((unsigned) (sizeof (state_t) \
|
||||||
|
+ (Nitems - 1) * sizeof (item_number_t)), 1)
|
||||||
|
|
||||||
|
res = STATE_ALLOC (core_size);
|
||||||
|
res->accessing_symbol = accessing_symbol;
|
||||||
|
res->number = nstates;
|
||||||
|
++nstates;
|
||||||
|
res->solved_conflicts = NULL;
|
||||||
|
|
||||||
|
res->nitems = core_size;
|
||||||
|
memcpy (res->items, core, core_size * sizeof (core[0]));
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------.
|
/*--------------------------------------------------------------.
|
||||||
| Print on OUT all the lookaheads such that this STATE wants to |
|
| Print on OUT all the lookaheads such that this STATE wants to |
|
||||||
| reduce this RULE. |
|
| reduce this RULE. |
|
||||||
|
|||||||
10
src/state.h
10
src/state.h
@@ -206,9 +206,13 @@ typedef struct state_s
|
|||||||
item_number_t items[1];
|
item_number_t items[1];
|
||||||
} state_t;
|
} state_t;
|
||||||
|
|
||||||
#define STATE_ALLOC(Nitems) \
|
extern state_number_t nstates;
|
||||||
(state_t *) xcalloc ((unsigned) (sizeof (state_t) \
|
extern state_t *final_state;
|
||||||
+ (Nitems - 1) * sizeof (item_number_t)), 1)
|
|
||||||
|
/* Create a new state with ACCESSING_SYMBOL for those items. */
|
||||||
|
|
||||||
|
state_t *state_new PARAMS ((symbol_number_t accessing_symbol,
|
||||||
|
size_t core_size, item_number_t *core));
|
||||||
|
|
||||||
/* Print on OUT all the lookaheads such that this STATE wants to
|
/* Print on OUT all the lookaheads such that this STATE wants to
|
||||||
reduce this RULE. */
|
reduce this RULE. */
|
||||||
|
|||||||
Reference in New Issue
Block a user