X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/9839bbe557af2c1c3a8160a157d713fb2fc9145a..ba29c4ec2590be025f37df6c722ad4a9a16f78c2:/src/state.h diff --git a/src/state.h b/src/state.h index 3bf9022f..1877ec48 100644 --- a/src/state.h +++ b/src/state.h @@ -1,5 +1,5 @@ /* Type definitions for nondeterministic finite state machine for bison, - Copyright 1984, 1989, 2000 Free Software Foundation, Inc. + Copyright 1984, 1989, 2000, 2001 Free Software Foundation, Inc. This file is part of Bison, the GNU Compiler Compiler. @@ -30,21 +30,21 @@ state. These symbols at these items are the allowable inputs that can follow now. - A core represents one state. States are numbered in the number + A core represents one state. States are numbered in the NUMBER field. When generate_states is finished, the starting state is - state 0 and nstates is the number of states. (A transition to a - state whose state number is nstates indicates termination.) All - the cores are chained together and first_state points to the first - one (state 0). + state 0 and NSTATES is the number of states. (FIXME: This sentence + is no longer true: A transition to a state whose state number is + NSTATES indicates termination.) All the cores are chained together + and FIRST_STATE points to the first one (state 0). For each state there is a particular symbol which must have been the last thing accepted to reach that state. It is the - accessing_symbol of the core. + ACCESSING_SYMBOL of the core. - Each core contains a vector of nitems items which are the indices - in the ritems vector of the items that are selected in this state. + Each core contains a vector of NITEMS items which are the indices + in the RITEMS vector of the items that are selected in this state. - The link field is used for chaining buckets that hash states by + The link field is used for chaining symbols that hash states by their itemsets. This is for recognizing equivalent states and combining them when the states are generated. @@ -88,24 +88,7 @@ #ifndef STATE_H_ # define STATE_H_ - -/*-------. -| Core. | -`-------*/ - -typedef struct core -{ - struct core *next; - struct core *link; - short number; - short accessing_symbol; - short nitems; - short items[1]; -} core; - -#define CORE_ALLOC(Nitems) \ - (core *) xcalloc ((unsigned) (sizeof (core) \ - + (Nitems - 1) * sizeof (short)), 1) +# include "bitsetv.h" /*---------. | Shifts. | @@ -113,23 +96,19 @@ typedef struct core typedef struct shifts { - struct shifts *next; - short number; short nshifts; short shifts[1]; } shifts; +shifts *shifts_new PARAMS ((int n)); -#define SHIFTS_ALLOC(Nshifts) \ - (shifts *) xcalloc ((unsigned) (sizeof (shifts) \ - + (Nshifts - 1) * sizeof (short)), 1) /* What is the symbol which is shifted by SHIFTS->shifts[Shift]? Can be a token (amongst which the error token), or non terminals in case of gotos. */ #define SHIFT_SYMBOL(Shifts, Shift) \ - (state_table[Shifts->shifts[Shift]].accessing_symbol) + (states[Shifts->shifts[Shift]]->accessing_symbol) /* Is the SHIFTS->shifts[Shift] a real shift? (as opposed to gotos.) */ @@ -144,7 +123,7 @@ typedef struct shifts /* Is the SHIFTS->shifts[Shift] then handling of the error token?. */ #define SHIFT_IS_ERROR(Shifts, Shift) \ - (SHIFT_SYMBOL (Shifts, Shift) == error_token_number) + (SHIFT_SYMBOL (Shifts, Shift) == errtoken->number) /* When resolving a SR conflicts, if the reduction wins, the shift is disabled. */ @@ -166,9 +145,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)); /*-------------. @@ -177,14 +155,54 @@ typedef struct errs typedef struct reductions { - struct reductions *next; - short number; short nreds; short rules[1]; } reductions; -#define REDUCTIONS_ALLOC(Nreductions) \ - (reductions *) xcalloc ((unsigned) (sizeof (reductions) \ - + (Nreductions - 1) * sizeof (short)), 1) +reductions *reductions_new PARAMS ((int n)); + + +/*----------. +| State_t. | +`----------*/ + +typedef struct state_s +{ + struct state_s *next; + struct state_s *link; + + short number; + symbol_number_t accessing_symbol; + shifts *shifts; + reductions *reductions; + errs *errs; + + /* Nonzero if no lookahead is needed to decide what to do in state S. */ + char consistent; + + /* Used in LALR, not LR(0). */ + int nlookaheads; + bitsetv lookaheads; + rule_t **lookaheads_rule; + + /* If some conflicts were solved thanks to precedence/associativity, + a human readable description of the resolution. */ + const char *solved_conflicts; + + /* Its items. Must be last, since ITEMS can be arbitrarily large. + */ + unsigned short nitems; + item_number_t items[1]; +} state_t; + +#define STATE_ALLOC(Nitems) \ + (state_t *) xcalloc ((unsigned) (sizeof (state_t) \ + + (Nitems - 1) * sizeof (item_number_t)), 1) + +/* 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, + FILE *out)); #endif /* !STATE_H_ */