diff options
author | Akim Demaille <akim.demaille@gmail.com> | 2020-06-27 11:12:48 +0200 |
---|---|---|
committer | Akim Demaille <akim.demaille@gmail.com> | 2020-06-27 11:39:32 +0200 |
commit | 0895858d8e0d1fa66c6dd0d2e45416488d7de513 (patch) | |
tree | 4eb69dda4eabfe5cadb3d68c850b95313ab5d2e0 /src | |
parent | 4efb2f7bd27d496e2aacb8867b53f7d22d8dfeda (diff) | |
download | bison-0895858d8e0d1fa66c6dd0d2e45416488d7de513.tar.gz |
style: use 'nonterminal' consistently
* doc/bison.texi: Formatting changes.
* src/gram.h, src/gram.c (nvars): Rename as...
(nnterms): this.
Adjust dependencies.
(section): New. Use it.
Replace "non terminal" and "non-terminal" by "nonterminal".
Diffstat (limited to 'src')
-rw-r--r-- | src/closure.c | 28 | ||||
-rw-r--r-- | src/counterexample.c | 10 | ||||
-rw-r--r-- | src/derivation.h | 6 | ||||
-rw-r--r-- | src/derives.c | 6 | ||||
-rw-r--r-- | src/gram.c | 32 | ||||
-rw-r--r-- | src/gram.h | 6 | ||||
-rw-r--r-- | src/lalr.c | 8 | ||||
-rw-r--r-- | src/lr0.c | 2 | ||||
-rw-r--r-- | src/lssi.c | 2 | ||||
-rw-r--r-- | src/nullable.c | 8 | ||||
-rw-r--r-- | src/output.c | 2 | ||||
-rw-r--r-- | src/parse-simulation.h | 4 | ||||
-rw-r--r-- | src/reader.c | 2 | ||||
-rw-r--r-- | src/reduce.c | 14 | ||||
-rw-r--r-- | src/reduce.h | 2 | ||||
-rw-r--r-- | src/state-item.c | 2 | ||||
-rw-r--r-- | src/symtab.c | 8 | ||||
-rw-r--r-- | src/tables.c | 6 |
18 files changed, 79 insertions, 69 deletions
diff --git a/src/closure.c b/src/closure.c index ee0c9d4a..1ea77ee6 100644 --- a/src/closure.c +++ b/src/closure.c @@ -104,21 +104,21 @@ print_fderives (void) fprintf (stderr, "\n\n"); } -/*------------------------------------------------------------------. -| Set FIRSTS to be an NVARS array of NVARS bitsets indicating which | -| items can represent the beginning of the input corresponding to | -| which other items. | -| | -| For example, if some rule expands symbol 5 into the sequence of | -| symbols 8 3 20, the symbol 8 can be the beginning of the data for | -| symbol 5, so the bit [8 - ntokens] in first[5 - ntokens] (= FIRST | -| (5)) is set. | -`------------------------------------------------------------------*/ +/*-------------------------------------------------------------------. +| Set FIRSTS to be an NNTERMS array of NNTERMS bitsets indicating | +| which items can represent the beginning of the input corresponding | +| to which other items. | +| | +| For example, if some rule expands symbol 5 into the sequence of | +| symbols 8 3 20, the symbol 8 can be the beginning of the data for | +| symbol 5, so the bit [8 - ntokens] in first[5 - ntokens] (= FIRST | +| (5)) is set. | +`-------------------------------------------------------------------*/ static void set_firsts (void) { - firsts = bitsetv_create (nvars, nvars, BITSET_FIXED); + firsts = bitsetv_create (nnterms, nnterms, BITSET_FIXED); for (symbol_number i = ntokens; i < nsyms; ++i) for (symbol_number j = 0; derives[i - ntokens][j]; ++j) @@ -139,8 +139,8 @@ set_firsts (void) } /*-------------------------------------------------------------------. -| Set FDERIVES to an NVARS by NRULES matrix of bits indicating which | -| rules can help derive the beginning of the data for each | +| Set FDERIVES to an NNTERMS by NRULES matrix of bits indicating | +| which rules can help derive the beginning of the data for each | | nonterminal. | | | | For example, if symbol 5 can be derived as the sequence of symbols | @@ -151,7 +151,7 @@ set_firsts (void) static void set_fderives (void) { - fderives = bitsetv_create (nvars, nrules, BITSET_FIXED); + fderives = bitsetv_create (nnterms, nrules, BITSET_FIXED); set_firsts (); diff --git a/src/counterexample.c b/src/counterexample.c index 7cc05796..e89050cc 100644 --- a/src/counterexample.c +++ b/src/counterexample.c @@ -177,9 +177,9 @@ si_bfs_free (si_bfs_node *n) /** * start is a state_item such that conflict_sym is an element of FIRSTS of the - * non-terminal after the dot in start. Because of this, we should be able to + * nonterminal after the dot in start. Because of this, we should be able to * find a production item starting with conflict_sym by only searching productions - * of the non-terminal and shifting over nullable non-terminals + * of the nonterminal and shifting over nullable nonterminals * * this returns the derivation of the productions that lead to conflict_sym */ @@ -292,7 +292,7 @@ complete_diverging_example (symbol_number conflict_sym, // We go backwards through the path to create the derivation tree bottom-up. // Effectively this loops through each production once, and generates a // derivation of the left hand side by appending all of the rhs symbols. - // this becomes the derivation of the non-terminal after the dot in the + // this becomes the derivation of the nonterminal after the dot in the // next production, and all of the other symbols of the rule are added as normal. for (gl_list_node_t state_node = list_get_end (path); state_node != NULL; @@ -334,8 +334,8 @@ complete_diverging_example (symbol_number conflict_sym, // Since reductions have the dot at the end of the item, // this loop will be first executed on the last item in the path // that's not a reduction. When that happens, - // the symbol after the dot should be a non-terminal, - // and we can look through successive nullable non-terminals + // the symbol after the dot should be a nonterminal, + // and we can look through successive nullable nonterminals // for one with the conflict symbol in its first set. if (bitset_test (FIRSTS (sym), conflict_sym)) { diff --git a/src/derivation.h b/src/derivation.h index 58852569..9f015df2 100644 --- a/src/derivation.h +++ b/src/derivation.h @@ -25,10 +25,10 @@ # include "gram.h" -/* Derivations are trees of symbols such that each non terminal's +/* Derivations are trees of symbols such that each nonterminal's children are symbols that produce that nonterminal if they are - relevant to the counterexample. The leaves of a derivation form a - counterexample when printed. */ + relevant to the counterexample. The leaves of a derivation form a + counterexample when printed. */ typedef gl_list_t derivation_list; typedef struct derivation derivation; diff --git a/src/derives.c b/src/derives.c index 178c0855..f0d334c7 100644 --- a/src/derives.c +++ b/src/derives.c @@ -62,7 +62,7 @@ derives_compute (void) { /* DSET[NTERM - NTOKENS] -- A linked list of the numbers of the rules whose LHS is NTERM. */ - rule_list **dset = xcalloc (nvars, sizeof *dset); + rule_list **dset = xcalloc (nnterms, sizeof *dset); /* DELTS[RULE] -- There are NRULES rule number to attach to nterms. Instead of performing NRULES allocations for each, have an array @@ -82,9 +82,9 @@ derives_compute (void) /* DSET contains what we need under the form of a linked list. Make it a single array. */ - derives = xnmalloc (nvars, sizeof *derives); + derives = xnmalloc (nnterms, sizeof *derives); /* Q is the storage for DERIVES[...] (DERIVES[0] = q). */ - rule **q = xnmalloc (nvars + nrules, sizeof *q); + rule **q = xnmalloc (nnterms + nrules, sizeof *q); for (symbol_number i = ntokens; i < nsyms; ++i) { @@ -40,7 +40,7 @@ rule_number nrules = 0; symbol **symbols = NULL; int nsyms = 0; int ntokens = 1; -int nvars = 0; +int nnterms = 0; symbol_number *token_translations = NULL; @@ -192,10 +192,10 @@ grammar_rules_partial_print (FILE *out, const char *title, if (first) fprintf (out, "%s\n\n", title); else if (previous_rule && previous_rule->lhs != rules[r].lhs) - fputc ('\n', out); + putc ('\n', out); first = false; rule_print (&rules[r], previous_rule, out); - fputc ('\n', out); + putc ('\n', out); previous_rule = &rules[r]; } if (!first) @@ -241,15 +241,25 @@ grammar_rules_print_xml (FILE *out, int level) xml_puts (out, level + 1, "<rules/>"); } +static void +section (FILE *out, const char *s) +{ + fprintf (out, "%s\n", s); + for (int i = strlen (s); 0 < i; --i) + putc ('-', out); + putc ('\n', out); + putc ('\n', out); +} + void grammar_dump (FILE *out, const char *title) { fprintf (out, "%s\n\n", title); fprintf (out, - "ntokens = %d, nvars = %d, nsyms = %d, nrules = %d, nritems = %d\n\n", - ntokens, nvars, nsyms, nrules, nritems); + "ntokens = %d, nnterms = %d, nsyms = %d, nrules = %d, nritems = %d\n\n", + ntokens, nnterms, nsyms, nrules, nritems); - fprintf (out, "Tokens\n------\n\n"); + section (out, "Tokens"); { fprintf (out, "Value Sprec Sassoc Tag\n"); @@ -261,7 +271,7 @@ grammar_dump (FILE *out, const char *title) fprintf (out, "\n\n"); } - fprintf (out, "Non terminals\n-------------\n\n"); + section (out, "Nonterminals"); { fprintf (out, "Value Tag\n"); @@ -271,7 +281,7 @@ grammar_dump (FILE *out, const char *title) fprintf (out, "\n\n"); } - fprintf (out, "Rules\n-----\n\n"); + section (out, "Rules"); { fprintf (out, "Num (Prec, Assoc, Useful, UselessChain) Lhs" @@ -293,17 +303,17 @@ grammar_dump (FILE *out, const char *title) /* Dumped the RHS. */ for (item_number *rhsp = rule_i->rhs; 0 <= *rhsp; ++rhsp) fprintf (out, " %3d", *rhsp); - fputc ('\n', out); + putc ('\n', out); } } fprintf (out, "\n\n"); - fprintf (out, "Rules interpreted\n-----------------\n\n"); + section (out, "Rules interpreted"); for (rule_number r = 0; r < nrules + nuseless_productions; ++r) { fprintf (out, "%-5d %s:", r, rules[r].lhs->symbol->tag); rule_rhs_print (&rules[r], out); - fputc ('\n', out); + putc ('\n', out); } fprintf (out, "\n\n"); } @@ -23,9 +23,9 @@ /* Representation of the grammar rules: - NTOKENS is the number of tokens, and NVARS is the number of + NTOKENS is the number of tokens, and NNTERMS is the number of variables (nonterminals). NSYMS is the total number, ntokens + - nvars. + nnterms. Each symbol (either token or variable) receives a symbol number. Numbers 0 to NTOKENS - 1 are for tokens, and NTOKENS to NSYMS - 1 @@ -113,7 +113,7 @@ extern int nsyms; extern int ntokens; -extern int nvars; +extern int nnterms; /* Elements of ritem. */ typedef int item_number; @@ -99,7 +99,7 @@ void set_goto_map (void) { /* Count the number of gotos (ngotos) per nterm (goto_map). */ - goto_map = xcalloc (nvars + 1, sizeof *goto_map); + goto_map = xcalloc (nnterms + 1, sizeof *goto_map); ngotos = 0; for (state_number s = 0; s < nstates; ++s) { @@ -113,7 +113,7 @@ set_goto_map (void) } } - goto_number *temp_map = xnmalloc (nvars + 1, sizeof *temp_map); + goto_number *temp_map = xnmalloc (nnterms + 1, sizeof *temp_map); { goto_number k = 0; for (symbol_number i = ntokens; i < nsyms; ++i) @@ -583,7 +583,7 @@ lalr_update_state_numbers (state_number old_to_new[], state_number nstates_old) { goto_number ngotos_reachable = 0; symbol_number nonterminal = 0; - aver (nsyms == nvars + ntokens); + aver (nsyms == nnterms + ntokens); for (goto_number i = 0; i < ngotos; ++i) { @@ -601,7 +601,7 @@ lalr_update_state_numbers (state_number old_to_new[], state_number nstates_old) ++ngotos_reachable; } } - while (nonterminal <= nvars) + while (nonterminal <= nnterms) { aver (ngotos == goto_map[nonterminal]); goto_map[nonterminal++] = ngotos_reachable; @@ -86,7 +86,7 @@ state_list_append (symbol_number sym, size_t core_size, item_index *core) return res; } -/* Symbols that can be "shifted" (including non terminals) from the +/* Symbols that can be "shifted" (including nonterminals) from the current state. */ bitset shift_symbol; @@ -186,7 +186,7 @@ shortest_path_from_start (state_item_number target, symbol_number next_sym) } } // For production steps, follow_L is based on the symbol after the - // non-terminal being produced. + // nonterminal being produced. // if no such symbol exists, follow_L is unchanged // if the symbol is a terminal, follow_L only contains that terminal // if the symbol is not nullable, follow_L is its FIRSTS set diff --git a/src/nullable.c b/src/nullable.c index 7d72c186..d982987f 100644 --- a/src/nullable.c +++ b/src/nullable.c @@ -54,17 +54,17 @@ nullable_print (FILE *out) void nullable_compute (void) { - nullable = xcalloc (nvars, sizeof *nullable); + nullable = xcalloc (nnterms, sizeof *nullable); size_t *rcount = xcalloc (nrules, sizeof *rcount); /* RITEM contains all the rules, including useless productions. Hence we must allocate room for useless nonterminals too. */ - rule_list **rsets = xcalloc (nvars, sizeof *rsets); + rule_list **rsets = xcalloc (nnterms, sizeof *rsets); /* This is said to be more elements than we actually use. Supposedly NRITEMS - NRULES is enough. But why take the risk? */ - rule_list *relts = xnmalloc (nritems + nvars + 1, sizeof *relts); + rule_list *relts = xnmalloc (nritems + nnterms + 1, sizeof *relts); - symbol_number *squeue = xnmalloc (nvars, sizeof *squeue); + symbol_number *squeue = xnmalloc (nnterms, sizeof *squeue); symbol_number *s2 = squeue; { rule_list *p = relts; diff --git a/src/output.c b/src/output.c index eb8a3bf8..ba2d2157 100644 --- a/src/output.c +++ b/src/output.c @@ -277,7 +277,7 @@ static void prepare_symbols (void) { MUSCLE_INSERT_INT ("tokens_number", ntokens); - MUSCLE_INSERT_INT ("nterms_number", nvars); + MUSCLE_INSERT_INT ("nterms_number", nnterms); MUSCLE_INSERT_INT ("symbols_number", nsyms); MUSCLE_INSERT_INT ("code_max", max_code); diff --git a/src/parse-simulation.h b/src/parse-simulation.h index 76c4bff9..6b0549ad 100644 --- a/src/parse-simulation.h +++ b/src/parse-simulation.h @@ -125,13 +125,13 @@ void parse_state_lists (parse_state *ps, gl_list_t *state_items, * is appended to state-items. */ parse_state_list simulate_transition (parse_state *ps); -/* Look at all of the productions for the non-terminal following the dot in the tail +/* Look at all of the productions for the nonterminal following the dot in the tail * state-item. Appends to state-items each production state-item which may start with * compat_sym. */ parse_state_list simulate_production (parse_state *ps, symbol_number compat_sym); /* Removes the last rule_len state-items along with their derivations. A new state-item is - * appended representing the goto after the reduction. A derivation for the non-terminal that + * appended representing the goto after the reduction. A derivation for the nonterminal that * was just reduced is appended which consists of the list of derivations that were just removed. */ parse_state_list simulate_reduction (parse_state *ps, int rule_len, bitset symbol_set); diff --git a/src/reader.c b/src/reader.c index 6461c79f..ecc4b19b 100644 --- a/src/reader.c +++ b/src/reader.c @@ -818,7 +818,7 @@ check_and_convert_grammar (void) } aver (nsyms <= SYMBOL_NUMBER_MAXIMUM); - aver (nsyms == ntokens + nvars); + aver (nsyms == ntokens + nnterms); /* Assign the symbols their symbol numbers. */ symbols_pack (); diff --git a/src/reduce.c b/src/reduce.c index 4ed8531e..78bab23e 100644 --- a/src/reduce.c +++ b/src/reduce.c @@ -93,7 +93,7 @@ useless_nonterminals (void) /* N is set as built. Np is set being built this iteration. P is set of all productions which have a RHS all in N. */ - bitset Np = bitset_create (nvars, BITSET_FIXED); + bitset Np = bitset_create (nnterms, BITSET_FIXED); /* The set being computed is a set of nonterminals which can derive the empty string or strings consisting of all terminals. At each @@ -201,7 +201,7 @@ inaccessable_symbols (void) int nuseful_nonterminals = 0; for (symbol_number i = ntokens; i < nsyms; ++i) nuseful_nonterminals += bitset_test (V, i); - nuseless_nonterminals = nvars - nuseful_nonterminals; + nuseless_nonterminals = nnterms - nuseful_nonterminals; /* A token that was used in %prec should not be warned about. */ for (rule_number r = 0; r < nrules; ++r) @@ -263,7 +263,7 @@ symbol_number *nterm_map = NULL; static void nonterminals_reduce (void) { - nterm_map = xnmalloc (nvars, sizeof *nterm_map); + nterm_map = xnmalloc (nnterms, sizeof *nterm_map); /* Map the nonterminals to their new index: useful first, useless afterwards. Kept for later report. */ { @@ -284,7 +284,7 @@ nonterminals_reduce (void) /* Shuffle elements of tables indexed by symbol number. */ { - symbol **symbols_sorted = xnmalloc (nvars, sizeof *symbols_sorted); + symbol **symbols_sorted = xnmalloc (nnterms, sizeof *symbols_sorted); for (symbol_number i = ntokens; i < nsyms; ++i) symbols[i]->content->number = nterm_map[i - ntokens]; for (symbol_number i = ntokens; i < nsyms; ++i) @@ -305,7 +305,7 @@ nonterminals_reduce (void) } nsyms -= nuseless_nonterminals; - nvars -= nuseless_nonterminals; + nnterms -= nuseless_nonterminals; } @@ -368,7 +368,7 @@ reduce_grammar (void) { /* Allocate the global sets used to compute the reduced grammar */ - N = bitset_create (nvars, BITSET_FIXED); + N = bitset_create (nnterms, BITSET_FIXED); P = bitset_create (nrules, BITSET_FIXED); V = bitset_create (nsyms, BITSET_FIXED); V1 = bitset_create (nsyms, BITSET_FIXED); @@ -401,7 +401,7 @@ reduce_grammar (void) fprintf (stderr, "reduced %s defines %d terminals, %d nonterminals" ", and %d productions.\n", - grammar_file, ntokens, nvars, nrules); + grammar_file, ntokens, nnterms, nrules); } } diff --git a/src/reduce.h b/src/reduce.h index e55bedb8..36110404 100644 --- a/src/reduce.h +++ b/src/reduce.h @@ -33,7 +33,7 @@ bool reduce_nonterminal_useless_in_grammar (const sym_content *sym); void reduce_free (void); /** Map initial nterm numbers to the new ones. Built by - * reduce_grammar. Size nvars + nuseless_nonterminals. */ + * reduce_grammar. Size nnterms + nuseless_nonterminals. */ extern symbol_number *nterm_map; extern int nuseless_nonterminals; diff --git a/src/state-item.c b/src/state-item.c index c3931d6c..d3035772 100644 --- a/src/state-item.c +++ b/src/state-item.c @@ -336,7 +336,7 @@ bitsetv firsts = NULL; static void init_firsts (void) { - firsts = bitsetv_create (nvars, nsyms, BITSET_FIXED); + firsts = bitsetv_create (nnterms, nsyms, BITSET_FIXED); for (rule_number i = 0; i < nrules; ++i) { rule *r = rules + i; diff --git a/src/symtab.c b/src/symtab.c index fb55b1dd..1a226620 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -549,7 +549,7 @@ symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring) complain_pct_type_on_token (&sym->location); if (class == nterm_sym && s->class != nterm_sym) - s->number = nvars++; + s->number = nnterms++; else if (class == token_sym && s->number == NUMBER_UNDEFINED) s->number = ntokens++; s->class = class; @@ -621,7 +621,7 @@ symbol_check_defined (symbol *sym) { complain_symbol_undeclared (sym); s->class = nterm_sym; - s->number = nvars++; + s->number = nnterms++; } if (s->class == token_sym @@ -852,7 +852,7 @@ symbols_new (void) /* Construct the accept symbol. */ accept = symbol_get ("$accept", empty_loc); accept->content->class = nterm_sym; - accept->content->number = nvars++; + accept->content->number = nnterms++; /* Construct the YYerror/"error" token */ errtoken = symbol_get ("YYerror", empty_loc); @@ -969,7 +969,7 @@ dummy_symbol_get (location loc) assure (len < sizeof buf); symbol *sym = symbol_get (buf, loc); sym->content->class = nterm_sym; - sym->content->number = nvars++; + sym->content->number = nnterms++; return sym; } diff --git a/src/tables.c b/src/tables.c index b165f0fb..883d81e5 100644 --- a/src/tables.c +++ b/src/tables.c @@ -547,7 +547,7 @@ static void goto_actions (void) { size_t *state_count = xnmalloc (nstates, sizeof *state_count); - yydefgoto = xnmalloc (nvars, sizeof *yydefgoto); + yydefgoto = xnmalloc (nnterms, sizeof *yydefgoto); /* For a given nterm I, STATE_COUNT[S] is the number of times there is a GOTO to S on I. */ @@ -780,9 +780,9 @@ tables_generate (void) correlated. In particular the signedness is not taken into account. But it's not useless. */ verify (sizeof nstates <= sizeof nvectors); - verify (sizeof nvars <= sizeof nvectors); + verify (sizeof nnterms <= sizeof nvectors); - nvectors = state_number_as_int (nstates) + nvars; + nvectors = state_number_as_int (nstates) + nnterms; froms = xcalloc (nvectors, sizeof *froms); tos = xcalloc (nvectors, sizeof *tos); |