From: Akim Demaille Date: Sun, 26 May 2002 18:39:05 +0000 (+0000) Subject: * src/LR0.c, src/derives.c, src/gram.c, src/gram.h, src/lalr.c, X-Git-Tag: BISON-1_49b~215 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/a49aecd528ab271f49fa76a482abbd84ce216b46 * src/LR0.c, src/derives.c, src/gram.c, src/gram.h, src/lalr.c, * src/nullable.c, src/output.c, src/print.c, src/print_graph.c, * src/reader.c, src/reduce.c, src/state.h, src/symtab.h (token_number_t, item_number_as_token_number) (token_number_as_item_number, muscle_insert_token_number_table): Rename as... (symbol_number_t, item_number_as_symbol_number) (symbol_number_as_item_number, muscle_insert_symbol_number_table): these, since it is more appropriate. --- diff --git a/ChangeLog b/ChangeLog index f074e59c..4a450cbc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2002-05-26 Akim Demaille + + * src/LR0.c, src/derives.c, src/gram.c, src/gram.h, src/lalr.c, + * src/nullable.c, src/output.c, src/print.c, src/print_graph.c, + * src/reader.c, src/reduce.c, src/state.h, src/symtab.h + (token_number_t, item_number_as_token_number) + (token_number_as_item_number, muscle_insert_token_number_table): + Rename as... + (symbol_number_t, item_number_as_symbol_number) + (symbol_number_as_item_number, muscle_insert_symbol_number_table): + these, since it is more appropriate. + 2002-05-26 Akim Demaille * tests/calc.at (AT_CHECK_CALC): Adjust: there are now additional diff --git a/src/LR0.c b/src/LR0.c index fce8b3db..269a8b87 100644 --- a/src/LR0.c +++ b/src/LR0.c @@ -52,7 +52,7 @@ static state_t *this_state = NULL; static state_t *last_state = NULL; static int nshifts; -static token_number_t *shift_symbol = NULL; +static symbol_number_t *shift_symbol = NULL; static short *redset = NULL; static short *shiftset = NULL; @@ -117,7 +117,7 @@ allocate_storage (void) shiftset = XCALLOC (short, nsyms); redset = XCALLOC (short, nrules + 1); state_hash = XCALLOC (state_t *, STATE_HASH_SIZE); - shift_symbol = XCALLOC (token_number_t, nsyms); + shift_symbol = XCALLOC (symbol_number_t, nsyms); } @@ -164,8 +164,8 @@ new_itemsets (void) for (i = 0; i < nritemset; ++i) if (ritem[itemset[i]] >= 0) { - token_number_t symbol - = item_number_as_token_number (ritem[itemset[i]]); + symbol_number_t symbol + = item_number_as_symbol_number (ritem[itemset[i]]); if (!kernel_size[symbol]) { shift_symbol[nshifts] = symbol; @@ -185,7 +185,7 @@ new_itemsets (void) `-----------------------------------------------------------------*/ static state_t * -new_state (token_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; @@ -228,7 +228,7 @@ new_state (token_number_t symbol, size_t core_size, item_number_t *core) `--------------------------------------------------------------*/ static int -get_state (token_number_t symbol, size_t core_size, item_number_t *core) +get_state (symbol_number_t symbol, size_t core_size, item_number_t *core) { int key; size_t i; @@ -297,7 +297,7 @@ append_states (void) { int i; int j; - token_number_t symbol; + symbol_number_t symbol; if (trace_flag) fprintf (stderr, "Entering append_states, state = %d\n", diff --git a/src/derives.c b/src/derives.c index d3443602..d78d5563 100644 --- a/src/derives.c +++ b/src/derives.c @@ -69,7 +69,7 @@ set_derives (void) p = delts; for (i = nrules; i > 0; i--) { - token_number_t lhs = rules[i].lhs->number; + symbol_number_t lhs = rules[i].lhs->number; p->next = dset[lhs]; p->value = i; dset[lhs] = p; diff --git a/src/gram.c b/src/gram.c index de5a217c..6b491e89 100644 --- a/src/gram.c +++ b/src/gram.c @@ -39,9 +39,9 @@ int nsyms = 0; int ntokens = 1; int nvars = 0; -token_number_t *token_translations = NULL; +symbol_number_t *token_translations = NULL; -token_number_t start_symbol = 0; +symbol_number_t start_symbol = 0; int max_user_token_number = 256; diff --git a/src/gram.h b/src/gram.h index 0a92993c..a5079e37 100644 --- a/src/gram.h +++ b/src/gram.h @@ -113,15 +113,15 @@ extern item_number_t *ritem; extern unsigned int nritems; /* There is weird relationship between item_number_t and - token_number_t: we store token_number_t in item_number_t, but in + symbol_number_t: we store symbol_number_t in item_number_t, but in the latter we also store, as negative numbers, the rule numbers. - Therefore, an token_number_t must be a valid item_number_t, and we + Therefore, an symbol_number_t must be a valid item_number_t, and we sometimes have to perform the converse transformation. */ -#define token_number_as_item_number(Tok) ((item_number_t) (Tok)) -#define item_number_as_token_number(Ite) ((token_number_t) (Ite)) +#define symbol_number_as_item_number(Tok) ((item_number_t) (Tok)) +#define item_number_as_symbol_number(Ite) ((symbol_number_t) (Ite)) -extern token_number_t start_symbol; +extern symbol_number_t start_symbol; typedef struct rule_s @@ -158,7 +158,7 @@ extern symbol_t **symbols; /* TOKEN_TRANSLATION -- a table indexed by a token number as returned by the user's yylex routine, it yields the internal token number used by the parser and throughout bison. */ -extern token_number_t *token_translations; +extern symbol_number_t *token_translations; extern int max_user_token_number; diff --git a/src/lalr.c b/src/lalr.c index 643f8fd9..f3f37a73 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -217,7 +217,7 @@ set_goto_map (void) `----------------------------------------------------------*/ static int -map_goto (int state, token_number_t symbol) +map_goto (int state, symbol_number_t symbol) { int high; int low; @@ -267,7 +267,7 @@ initialize_F (void) for (; j < sp->nshifts; j++) { - token_number_t symbol = SHIFT_SYMBOL (sp, j); + symbol_number_t symbol = SHIFT_SYMBOL (sp, j); if (nullable[symbol]) edge[nedges++] = map_goto (stateno, symbol); } @@ -408,7 +408,7 @@ build_relations (void) for (i = 0; i < ngotos; i++) { int nedges = 0; - token_number_t symbol1 = states[to_state[i]]->accessing_symbol; + symbol_number_t symbol1 = states[to_state[i]]->accessing_symbol; short *rulep; for (rulep = derives[symbol1]; *rulep > 0; rulep++) @@ -427,7 +427,7 @@ build_relations (void) { state = states[sp->shifts[j]]; if (state->accessing_symbol - == item_number_as_token_number (*rp)) + == item_number_as_symbol_number (*rp)) break; } @@ -446,9 +446,9 @@ build_relations (void) /* JF added rp>=ritem && I hope to god its right! */ if (rp >= ritem && ISVAR (*rp)) { - /* Downcasting from item_number_t to token_number_t. */ + /* Downcasting from item_number_t to symbol_number_t. */ edge[nedges++] = map_goto (states1[--length], - item_number_as_token_number (*rp)); + item_number_as_symbol_number (*rp)); if (nullable[*rp]) done = 0; } diff --git a/src/nullable.c b/src/nullable.c index ae02db75..42e398b3 100644 --- a/src/nullable.c +++ b/src/nullable.c @@ -47,11 +47,11 @@ void set_nullable (void) { int ruleno; - token_number_t *s1; - token_number_t *s2; + symbol_number_t *s1; + symbol_number_t *s2; shorts *p; - token_number_t *squeue = XCALLOC (token_number_t, nvars); + symbol_number_t *squeue = XCALLOC (symbol_number_t, nvars); short *rcount = XCALLOC (short, nrules + 1); /* RITEM contains all the rules, including useless productions. Hence we must allocate room for useless nonterminals too. */ diff --git a/src/output.c b/src/output.c index cff89a78..2b2f1f08 100644 --- a/src/output.c +++ b/src/output.c @@ -215,7 +215,7 @@ Name (const char *name, \ GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_unsigned_int_table, unsigned int) GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_short_table, short) -GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_token_number_table, token_number_t) +GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_symbol_number_table, symbol_number_t) GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_item_number_table, item_number_t) @@ -227,7 +227,7 @@ GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_item_number_table, item_number_t) static void prepare_tokens (void) { - muscle_insert_token_number_table ("translate", + muscle_insert_symbol_number_table ("translate", token_translations, 0, 1, max_user_token_number + 1); @@ -290,7 +290,7 @@ prepare_rules (void) item_number_t *rhs = XMALLOC (item_number_t, nritems); unsigned int *prhs = XMALLOC (unsigned int, nrules + 1); unsigned int *rline = XMALLOC (unsigned int, nrules + 1); - token_number_t *r1 = XMALLOC (token_number_t, nrules + 1); + symbol_number_t *r1 = XMALLOC (symbol_number_t, nrules + 1); unsigned int *r2 = XMALLOC (unsigned int, nrules + 1); for (r = 1; r < nrules + 1; ++r) @@ -315,7 +315,7 @@ prepare_rules (void) muscle_insert_item_number_table ("rhs", rhs, ritem[0], 1, nritems); muscle_insert_unsigned_int_table ("prhs", prhs, 0, 1, nrules + 1); muscle_insert_unsigned_int_table ("rline", rline, 0, 1, nrules + 1); - muscle_insert_token_number_table ("r1", r1, 0, 1, nrules + 1); + muscle_insert_symbol_number_table ("r1", r1, 0, 1, nrules + 1); muscle_insert_unsigned_int_table ("r2", r2, 0, 1, nrules + 1); free (rhs); @@ -333,11 +333,11 @@ static void prepare_states (void) { size_t i; - token_number_t *values = - (token_number_t *) alloca (sizeof (token_number_t) * nstates); + symbol_number_t *values = + (symbol_number_t *) alloca (sizeof (symbol_number_t) * nstates); for (i = 0; i < nstates; ++i) values[i] = states[i]->accessing_symbol; - muscle_insert_token_number_table ("stos", values, + muscle_insert_symbol_number_table ("stos", values, 0, 1, nstates); } @@ -390,7 +390,7 @@ action_row (state_t *state) to reduce. */ for (i = 0; i < shiftp->nshifts; i++) { - token_number_t symbol; + symbol_number_t symbol; int shift_state = shiftp->shifts[i]; if (!shift_state) continue; diff --git a/src/print.c b/src/print.c index ddaa3328..b99c233d 100644 --- a/src/print.c +++ b/src/print.c @@ -149,7 +149,7 @@ print_shifts (FILE *out, state_t *state) if (!SHIFT_IS_DISABLED (shiftp, i)) { int state1 = shiftp->shifts[i]; - token_number_t symbol = states[state1]->accessing_symbol; + symbol_number_t symbol = states[state1]->accessing_symbol; fprintf (out, _(" %-4s\tshift, and go to state %d\n"), escape (symbols[symbol]->tag), state1); @@ -191,7 +191,7 @@ print_gotos (FILE *out, state_t *state) if (!SHIFT_IS_DISABLED (shiftp, i)) { int state1 = shiftp->shifts[i]; - token_number_t symbol = states[state1]->accessing_symbol; + symbol_number_t symbol = states[state1]->accessing_symbol; fprintf (out, _(" %-4s\tgo to state %d\n"), escape (symbols[symbol]->tag), state1); } @@ -215,7 +215,7 @@ print_reductions (FILE *out, state_t *state) if (state->consistent) { int rule = redp->rules[0]; - token_number_t symbol = rules[rule].lhs->number; + symbol_number_t symbol = rules[rule].lhs->number; fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"), rule - 1, escape (symbols[symbol]->tag)); return; @@ -385,7 +385,7 @@ do { \ static void print_grammar (FILE *out) { - token_number_t i; + symbol_number_t i; int j; item_number_t *rule; char buffer[90]; @@ -422,7 +422,7 @@ print_grammar (FILE *out) for (j = 1; j < nrules + 1; j++) for (rule = rules[j].rhs; *rule >= 0; rule++) - if (item_number_as_token_number (*rule) == token_translations[i]) + if (item_number_as_symbol_number (*rule) == token_translations[i]) { END_TEST (65); sprintf (buffer + strlen (buffer), " %d", j - 1); @@ -443,7 +443,7 @@ print_grammar (FILE *out) if (rules[j].lhs->number == i) left_count++; for (rule = rules[j].rhs; *rule >= 0; rule++) - if (item_number_as_token_number (*rule) == i) + if (item_number_as_symbol_number (*rule) == i) { right_count++; break; @@ -478,7 +478,7 @@ print_grammar (FILE *out) for (j = 1; j < nrules + 1; j++) { for (rule = rules[j].rhs; *rule >= 0; rule++) - if (item_number_as_token_number (*rule) == i) + if (item_number_as_symbol_number (*rule) == i) { END_TEST (65); sprintf (buffer + strlen (buffer), " %d", j - 1); diff --git a/src/print_graph.c b/src/print_graph.c index 416c4fd2..6cd92ec9 100644 --- a/src/print_graph.c +++ b/src/print_graph.c @@ -140,7 +140,7 @@ print_actions (state_t *state, const char *node_name) if (!SHIFT_IS_DISABLED (shiftp, i)) { int state1 = shiftp->shifts[i]; - token_number_t symbol = states[state1]->accessing_symbol; + symbol_number_t symbol = states[state1]->accessing_symbol; new_edge (&edge); diff --git a/src/reader.c b/src/reader.c index 93df69a6..185ca0fa 100644 --- a/src/reader.c +++ b/src/reader.c @@ -1693,7 +1693,7 @@ token_translations_init (void) max_user_token_number = this->user_token_number; } - token_translations = XCALLOC (token_number_t, max_user_token_number + 1); + token_translations = XCALLOC (symbol_number_t, max_user_token_number + 1); /* Initialize all entries for literal tokens to 2, the internal token number for $undefined., which represents all invalid @@ -1762,9 +1762,9 @@ packgram (void) p = p->next; while (p && p->sym) { - /* item_number_t = token_number_t. + /* item_number_t = symbol_number_t. But the former needs to contain more: negative rule numbers. */ - ritem[itemno++] = token_number_as_item_number (p->sym->number); + ritem[itemno++] = symbol_number_as_item_number (p->sym->number); /* A rule gets by default the precedence and associativity of the last token in it. */ if (p->sym->class == token_sym) diff --git a/src/reduce.c b/src/reduce.c index fd6f9e15..4ac89197 100644 --- a/src/reduce.c +++ b/src/reduce.c @@ -278,12 +278,12 @@ reduce_grammar_tables (void) static void nonterminals_reduce (void) { - token_number_t i, n; + symbol_number_t i, n; /* Map the nonterminals to their new index: useful first, useless afterwards. Kept for later report. */ - token_number_t *nontermmap = XCALLOC (token_number_t, nvars) - ntokens; + symbol_number_t *nontermmap = XCALLOC (symbol_number_t, nvars) - ntokens; n = ntokens; for (i = ntokens; i < nsyms; i++) if (bitset_test (V, i)) @@ -313,7 +313,7 @@ nonterminals_reduce (void) item_number_t *rhsp; for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp) if (ISVAR (*rhsp)) - *rhsp = token_number_as_item_number (nontermmap[*rhsp]); + *rhsp = symbol_number_as_item_number (nontermmap[*rhsp]); } start_symbol = nontermmap[start_symbol]; } diff --git a/src/state.h b/src/state.h index 92378c70..c2282474 100644 --- a/src/state.h +++ b/src/state.h @@ -171,7 +171,7 @@ typedef struct state_s struct state_s *link; short number; - token_number_t accessing_symbol; + symbol_number_t accessing_symbol; shifts *shifts; reductions *reductions; errs *errs; diff --git a/src/symtab.h b/src/symtab.h index fd7f495c..f95e7701 100644 --- a/src/symtab.h +++ b/src/symtab.h @@ -43,7 +43,7 @@ typedef enum /* Internal token numbers. */ -typedef short token_number_t; +typedef short symbol_number_t; typedef struct symbol_s symbol_t; @@ -54,7 +54,7 @@ struct symbol_s /* Its type. */ char *type_name; - token_number_t number; + symbol_number_t number; short prec; associativity assoc; int user_token_number; @@ -76,7 +76,7 @@ struct symbol_s #define USER_NUMBER_ALIAS -9991 /* Undefined internal token number. */ -#define NUMBER_UNDEFINED ((token_number_t) -1) +#define NUMBER_UNDEFINED ((symbol_number_t) -1) /* A function to apply to each symbol. */