#ifndef STATE_H_
# define STATE_H_
-# include "bitsetv.h"
+# include "bitset.h"
/*-------------------.
/* Be ready to map a state_number_t to an int. */
# define state_number_as_int(Tok) ((int) (Tok))
+
+typedef struct state_s state_t;
+
/*--------------.
| Transitions. |
`--------------*/
typedef struct transtion_s
{
short num;
- state_number_t states[1];
+ state_t *states[1];
} transitions_t;
token), or non terminals in case of gotos. */
#define TRANSITION_SYMBOL(Transitions, Num) \
- (states[Transitions->states[Num]]->accessing_symbol)
+ (Transitions->states[Num]->accessing_symbol)
/* Is the TRANSITIONS->states[Num] a shift? (as opposed to gotos). */
disabled. */
#define TRANSITION_DISABLE(Transitions, Num) \
- (Transitions->states[Num] = 0)
+ (Transitions->states[Num] = NULL)
#define TRANSITION_IS_DISABLED(Transitions, Num) \
- (Transitions->states[Num] == 0)
+ (Transitions->states[Num] == NULL)
+
+
+/* Iterate over each transition over a token (shifts). */
+#define FOR_EACH_SHIFT(Transitions, Iter) \
+ for (Iter = 0; \
+ Iter < Transitions->num \
+ && (TRANSITION_IS_DISABLED (Transitions, Iter) \
+ || TRANSITION_IS_SHIFT (Transitions, Iter)); \
+ ++Iter) \
+ if (!TRANSITION_IS_DISABLED (Transitions, Iter))
+
/* Return the state such these TRANSITIONS contain a shift/goto to it on
SYMBOL. Aborts if none found. */
struct state_s;
-struct state_s *transitions_to PARAMS ((transitions_t *state,
- symbol_number_t s));
+struct state_s *transitions_to (transitions_t *state, symbol_number_t s);
/*-------.
typedef struct errs_s
{
short num;
- symbol_number_t symbols[1];
+ symbol_t *symbols[1];
} errs_t;
-errs_t *errs_new PARAMS ((int num, symbol_number_t *tokens));
+errs_t *errs_new (int num, symbol_t **tokens);
/*-------------.
typedef struct reductions_s
{
short num;
- rule_number_t rules[1];
+ bitset *lookaheads;
+ rule_t *rules[1];
} reductions_t;
-/*----------.
-| State_t. |
-`----------*/
+/*---------.
+| States. |
+`---------*/
-typedef struct state_s
+struct state_s
{
state_number_t number;
symbol_number_t accessing_symbol;
/* Nonzero if no lookahead is needed to decide what to do in state S. */
char consistent;
- /* Used in LALR, not LR(0).
-
- When a state is not consistent (there is an S/R or R/R conflict),
- lookaheads are needed to enable the reductions. NLOOKAHEADS is
- the number of lookahead guarded reductions of the
- LOOKAHEADS_RULE. For each rule LOOKAHEADS_RULE[R], LOOKAHEADS[R]
- is the bitset of the lookaheads enabling this reduction. */
- 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;
*/
unsigned short nitems;
item_number_t items[1];
-} state_t;
+};
extern state_number_t nstates;
extern state_t *final_state;
/* 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));
+state_t *state_new (symbol_number_t accessing_symbol,
+ size_t core_size, item_number_t *core);
/* Set the transitions of STATE. */
-void state_transitions_set PARAMS ((state_t *state,
- int num, state_number_t *transitions));
+void state_transitions_set (state_t *state, int num, state_t **transitions);
/* Set the reductions of STATE. */
-void state_reductions_set PARAMS ((state_t *state,
- int num, rule_number_t *reductions));
+void state_reductions_set (state_t *state, int num, rule_t **reductions);
+
+int state_reduction_find (state_t *state, rule_t *rule);
/* Set the errs of STATE. */
-void state_errs_set PARAMS ((state_t *state,
- int num, symbol_number_t *errs));
+void state_errs_set (state_t *state, int num, symbol_t **errs);
/* 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));
+void state_rule_lookaheads_print (state_t *state, rule_t *rule, FILE *out);
/* Create/destroy the states hash table. */
-void state_hash_new PARAMS ((void));
-void state_hash_free PARAMS ((void));
+void state_hash_new (void);
+void state_hash_free (void);
/* Find the state associated to the CORE, and return it. If it does
not exist yet, return NULL. */
-state_t *state_hash_lookup PARAMS ((size_t core_size, item_number_t *core));
+state_t *state_hash_lookup (size_t core_size, item_number_t *core);
/* Insert STATE in the state hash table. */
-void state_hash_insert PARAMS ((state_t *state));
+void state_hash_insert (state_t *state);
/* All the states, indexed by the state number. */
extern state_t **states;
/* Free all the states. */
-void states_free PARAMS ((void));
+void states_free (void);
#endif /* !STATE_H_ */