Skip to content

Commit 0895858

Browse files
committed
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".
1 parent 4efb2f7 commit 0895858

22 files changed

+111
-99
lines changed

README-hacking.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ Only user visible strings are to be translated: error messages, bits of the
3737
assert/abort), and all the --trace output which is meant for the maintainers
3838
only.
3939

40+
## Vocabulary
41+
Use "nonterminal", not "variable" or "non-terminal" or "non terminal".
42+
Abbreviated as "nterm".
43+
4044
## Syntax highlighting
4145
It's quite nice to be in C++ mode when editing lalr1.cc for instance.
4246
However tools such as Emacs will be fooled by the fact that braces and

TODO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ generates tons of white space in the page, and may contribute to bad page
9191
breaks.
9292

9393
** consistency
94-
token vs terminal, variable vs non terminal.
94+
token vs terminal.
9595

9696
** api.token.raw
9797
The YYUNDEFTOK could be assigned a semantic value so that yyerror could be

doc/bison.texi

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,13 +2834,13 @@ predefined variables such as @code{pi} or @code{e} as well.
28342834
Add some new functions from @file{math.h} to the initialization list.
28352835

28362836
@item
2837-
Add another array that contains constants and their values. Then
2838-
modify @code{init_table} to add these constants to the symbol table.
2839-
It will be easiest to give the constants type @code{VAR}.
2837+
Add another array that contains constants and their values. Then modify
2838+
@code{init_table} to add these constants to the symbol table. It will be
2839+
easiest to give the constants type @code{VAR}.
28402840

28412841
@item
2842-
Make the program report an error if the user refers to an
2843-
uninitialized variable in any way except to store a value in it.
2842+
Make the program report an error if the user refers to an uninitialized
2843+
variable in any way except to store a value in it.
28442844
@end enumerate
28452845

28462846
@node Grammar File
@@ -5513,12 +5513,12 @@ do @{
55135513
yypstate_delete (ps);
55145514
@end example
55155515

5516-
If the user decided to use an impure push parser, a few things about
5517-
the generated parser will change. The @code{yychar} variable becomes
5518-
a global variable instead of a variable in the @code{yypush_parse} function.
5519-
For this reason, the signature of the @code{yypush_parse} function is
5520-
changed to remove the token as a parameter. A nonreentrant push parser
5521-
example would thus look like this:
5516+
If the user decided to use an impure push parser, a few things about the
5517+
generated parser will change. The @code{yychar} variable becomes a global
5518+
variable instead of a local one in the @code{yypush_parse} function. For
5519+
this reason, the signature of the @code{yypush_parse} function is changed to
5520+
remove the token as a parameter. A nonreentrant push parser example would
5521+
thus look like this:
55225522

55235523
@example
55245524
extern int yychar;
@@ -8104,10 +8104,9 @@ doing so would produce on the stack the sequence of symbols @code{expr
81048104
@vindex yychar
81058105
@vindex yylval
81068106
@vindex yylloc
8107-
The lookahead token is stored in the variable @code{yychar}.
8108-
Its semantic value and location, if any, are stored in the variables
8109-
@code{yylval} and @code{yylloc}.
8110-
@xref{Action Features}.
8107+
The lookahead token is stored in the variable @code{yychar}. Its semantic
8108+
value and location, if any, are stored in the variables @code{yylval} and
8109+
@code{yylloc}. @xref{Action Features}.
81118110

81128111
@node Shift/Reduce
81138112
@section Shift/Reduce Conflicts
@@ -14263,14 +14262,13 @@ start:
1426314262
These tokens prevents the introduction of new conflicts. As far as the
1426414263
parser goes, that is all that is needed.
1426514264

14266-
Now the difficult part is ensuring that the scanner will send these
14267-
tokens first. If your scanner is hand-written, that should be
14268-
straightforward. If your scanner is generated by Lex, them there is
14269-
simple means to do it: recall that anything between @samp{%@{ ... %@}}
14270-
after the first @code{%%} is copied verbatim in the top of the generated
14271-
@code{yylex} function. Make sure a variable @code{start_token} is
14272-
available in the scanner (e.g., a global variable or using
14273-
@code{%lex-param} etc.), and use the following:
14265+
Now the difficult part is ensuring that the scanner will send these tokens
14266+
first. If your scanner is hand-written, that should be straightforward. If
14267+
your scanner is generated by Lex, them there is simple means to do it:
14268+
recall that anything between @samp{%@{ ... %@}} after the first @code{%%} is
14269+
copied verbatim in the top of the generated @code{yylex} function. Make
14270+
sure a variable @code{start_token} is available in the scanner (e.g., a
14271+
global variable or using @code{%lex-param} etc.), and use the following:
1427414272

1427514273
@example
1427614274
/* @r{Prologue.} */

src/closure.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,21 @@ print_fderives (void)
104104
fprintf (stderr, "\n\n");
105105
}
106106

107-
/*------------------------------------------------------------------.
108-
| Set FIRSTS to be an NVARS array of NVARS bitsets indicating which |
109-
| items can represent the beginning of the input corresponding to |
110-
| which other items. |
111-
| |
112-
| For example, if some rule expands symbol 5 into the sequence of |
113-
| symbols 8 3 20, the symbol 8 can be the beginning of the data for |
114-
| symbol 5, so the bit [8 - ntokens] in first[5 - ntokens] (= FIRST |
115-
| (5)) is set. |
116-
`------------------------------------------------------------------*/
107+
/*-------------------------------------------------------------------.
108+
| Set FIRSTS to be an NNTERMS array of NNTERMS bitsets indicating |
109+
| which items can represent the beginning of the input corresponding |
110+
| to which other items. |
111+
| |
112+
| For example, if some rule expands symbol 5 into the sequence of |
113+
| symbols 8 3 20, the symbol 8 can be the beginning of the data for |
114+
| symbol 5, so the bit [8 - ntokens] in first[5 - ntokens] (= FIRST |
115+
| (5)) is set. |
116+
`-------------------------------------------------------------------*/
117117

118118
static void
119119
set_firsts (void)
120120
{
121-
firsts = bitsetv_create (nvars, nvars, BITSET_FIXED);
121+
firsts = bitsetv_create (nnterms, nnterms, BITSET_FIXED);
122122

123123
for (symbol_number i = ntokens; i < nsyms; ++i)
124124
for (symbol_number j = 0; derives[i - ntokens][j]; ++j)
@@ -139,8 +139,8 @@ set_firsts (void)
139139
}
140140

141141
/*-------------------------------------------------------------------.
142-
| Set FDERIVES to an NVARS by NRULES matrix of bits indicating which |
143-
| rules can help derive the beginning of the data for each |
142+
| Set FDERIVES to an NNTERMS by NRULES matrix of bits indicating |
143+
| which rules can help derive the beginning of the data for each |
144144
| nonterminal. |
145145
| |
146146
| For example, if symbol 5 can be derived as the sequence of symbols |
@@ -151,7 +151,7 @@ set_firsts (void)
151151
static void
152152
set_fderives (void)
153153
{
154-
fderives = bitsetv_create (nvars, nrules, BITSET_FIXED);
154+
fderives = bitsetv_create (nnterms, nrules, BITSET_FIXED);
155155

156156
set_firsts ();
157157

src/counterexample.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ si_bfs_free (si_bfs_node *n)
177177

178178
/**
179179
* start is a state_item such that conflict_sym is an element of FIRSTS of the
180-
* non-terminal after the dot in start. Because of this, we should be able to
180+
* nonterminal after the dot in start. Because of this, we should be able to
181181
* find a production item starting with conflict_sym by only searching productions
182-
* of the non-terminal and shifting over nullable non-terminals
182+
* of the nonterminal and shifting over nullable nonterminals
183183
*
184184
* this returns the derivation of the productions that lead to conflict_sym
185185
*/
@@ -292,7 +292,7 @@ complete_diverging_example (symbol_number conflict_sym,
292292
// We go backwards through the path to create the derivation tree bottom-up.
293293
// Effectively this loops through each production once, and generates a
294294
// derivation of the left hand side by appending all of the rhs symbols.
295-
// this becomes the derivation of the non-terminal after the dot in the
295+
// this becomes the derivation of the nonterminal after the dot in the
296296
// next production, and all of the other symbols of the rule are added as normal.
297297
for (gl_list_node_t state_node = list_get_end (path);
298298
state_node != NULL;
@@ -334,8 +334,8 @@ complete_diverging_example (symbol_number conflict_sym,
334334
// Since reductions have the dot at the end of the item,
335335
// this loop will be first executed on the last item in the path
336336
// that's not a reduction. When that happens,
337-
// the symbol after the dot should be a non-terminal,
338-
// and we can look through successive nullable non-terminals
337+
// the symbol after the dot should be a nonterminal,
338+
// and we can look through successive nullable nonterminals
339339
// for one with the conflict symbol in its first set.
340340
if (bitset_test (FIRSTS (sym), conflict_sym))
341341
{

src/derivation.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525

2626
# include "gram.h"
2727

28-
/* Derivations are trees of symbols such that each non terminal's
28+
/* Derivations are trees of symbols such that each nonterminal's
2929
children are symbols that produce that nonterminal if they are
30-
relevant to the counterexample. The leaves of a derivation form a
31-
counterexample when printed. */
30+
relevant to the counterexample. The leaves of a derivation form a
31+
counterexample when printed. */
3232

3333
typedef gl_list_t derivation_list;
3434
typedef struct derivation derivation;

src/derives.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ derives_compute (void)
6262
{
6363
/* DSET[NTERM - NTOKENS] -- A linked list of the numbers of the rules
6464
whose LHS is NTERM. */
65-
rule_list **dset = xcalloc (nvars, sizeof *dset);
65+
rule_list **dset = xcalloc (nnterms, sizeof *dset);
6666

6767
/* DELTS[RULE] -- There are NRULES rule number to attach to nterms.
6868
Instead of performing NRULES allocations for each, have an array
@@ -82,9 +82,9 @@ derives_compute (void)
8282
/* DSET contains what we need under the form of a linked list. Make
8383
it a single array. */
8484

85-
derives = xnmalloc (nvars, sizeof *derives);
85+
derives = xnmalloc (nnterms, sizeof *derives);
8686
/* Q is the storage for DERIVES[...] (DERIVES[0] = q). */
87-
rule **q = xnmalloc (nvars + nrules, sizeof *q);
87+
rule **q = xnmalloc (nnterms + nrules, sizeof *q);
8888

8989
for (symbol_number i = ntokens; i < nsyms; ++i)
9090
{

src/gram.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ rule_number nrules = 0;
4040
symbol **symbols = NULL;
4141
int nsyms = 0;
4242
int ntokens = 1;
43-
int nvars = 0;
43+
int nnterms = 0;
4444

4545
symbol_number *token_translations = NULL;
4646

@@ -192,10 +192,10 @@ grammar_rules_partial_print (FILE *out, const char *title,
192192
if (first)
193193
fprintf (out, "%s\n\n", title);
194194
else if (previous_rule && previous_rule->lhs != rules[r].lhs)
195-
fputc ('\n', out);
195+
putc ('\n', out);
196196
first = false;
197197
rule_print (&rules[r], previous_rule, out);
198-
fputc ('\n', out);
198+
putc ('\n', out);
199199
previous_rule = &rules[r];
200200
}
201201
if (!first)
@@ -241,15 +241,25 @@ grammar_rules_print_xml (FILE *out, int level)
241241
xml_puts (out, level + 1, "<rules/>");
242242
}
243243

244+
static void
245+
section (FILE *out, const char *s)
246+
{
247+
fprintf (out, "%s\n", s);
248+
for (int i = strlen (s); 0 < i; --i)
249+
putc ('-', out);
250+
putc ('\n', out);
251+
putc ('\n', out);
252+
}
253+
244254
void
245255
grammar_dump (FILE *out, const char *title)
246256
{
247257
fprintf (out, "%s\n\n", title);
248258
fprintf (out,
249-
"ntokens = %d, nvars = %d, nsyms = %d, nrules = %d, nritems = %d\n\n",
250-
ntokens, nvars, nsyms, nrules, nritems);
259+
"ntokens = %d, nnterms = %d, nsyms = %d, nrules = %d, nritems = %d\n\n",
260+
ntokens, nnterms, nsyms, nrules, nritems);
251261

252-
fprintf (out, "Tokens\n------\n\n");
262+
section (out, "Tokens");
253263
{
254264
fprintf (out, "Value Sprec Sassoc Tag\n");
255265

@@ -261,7 +271,7 @@ grammar_dump (FILE *out, const char *title)
261271
fprintf (out, "\n\n");
262272
}
263273

264-
fprintf (out, "Non terminals\n-------------\n\n");
274+
section (out, "Nonterminals");
265275
{
266276
fprintf (out, "Value Tag\n");
267277

@@ -271,7 +281,7 @@ grammar_dump (FILE *out, const char *title)
271281
fprintf (out, "\n\n");
272282
}
273283

274-
fprintf (out, "Rules\n-----\n\n");
284+
section (out, "Rules");
275285
{
276286
fprintf (out,
277287
"Num (Prec, Assoc, Useful, UselessChain) Lhs"
@@ -293,17 +303,17 @@ grammar_dump (FILE *out, const char *title)
293303
/* Dumped the RHS. */
294304
for (item_number *rhsp = rule_i->rhs; 0 <= *rhsp; ++rhsp)
295305
fprintf (out, " %3d", *rhsp);
296-
fputc ('\n', out);
306+
putc ('\n', out);
297307
}
298308
}
299309
fprintf (out, "\n\n");
300310

301-
fprintf (out, "Rules interpreted\n-----------------\n\n");
311+
section (out, "Rules interpreted");
302312
for (rule_number r = 0; r < nrules + nuseless_productions; ++r)
303313
{
304314
fprintf (out, "%-5d %s:", r, rules[r].lhs->symbol->tag);
305315
rule_rhs_print (&rules[r], out);
306-
fputc ('\n', out);
316+
putc ('\n', out);
307317
}
308318
fprintf (out, "\n\n");
309319
}

src/gram.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323

2424
/* Representation of the grammar rules:
2525
26-
NTOKENS is the number of tokens, and NVARS is the number of
26+
NTOKENS is the number of tokens, and NNTERMS is the number of
2727
variables (nonterminals). NSYMS is the total number, ntokens +
28-
nvars.
28+
nnterms.
2929
3030
Each symbol (either token or variable) receives a symbol number.
3131
Numbers 0 to NTOKENS - 1 are for tokens, and NTOKENS to NSYMS - 1
@@ -113,7 +113,7 @@
113113

114114
extern int nsyms;
115115
extern int ntokens;
116-
extern int nvars;
116+
extern int nnterms;
117117

118118
/* Elements of ritem. */
119119
typedef int item_number;

src/lalr.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void
9999
set_goto_map (void)
100100
{
101101
/* Count the number of gotos (ngotos) per nterm (goto_map). */
102-
goto_map = xcalloc (nvars + 1, sizeof *goto_map);
102+
goto_map = xcalloc (nnterms + 1, sizeof *goto_map);
103103
ngotos = 0;
104104
for (state_number s = 0; s < nstates; ++s)
105105
{
@@ -113,7 +113,7 @@ set_goto_map (void)
113113
}
114114
}
115115

116-
goto_number *temp_map = xnmalloc (nvars + 1, sizeof *temp_map);
116+
goto_number *temp_map = xnmalloc (nnterms + 1, sizeof *temp_map);
117117
{
118118
goto_number k = 0;
119119
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)
583583
{
584584
goto_number ngotos_reachable = 0;
585585
symbol_number nonterminal = 0;
586-
aver (nsyms == nvars + ntokens);
586+
aver (nsyms == nnterms + ntokens);
587587

588588
for (goto_number i = 0; i < ngotos; ++i)
589589
{
@@ -601,7 +601,7 @@ lalr_update_state_numbers (state_number old_to_new[], state_number nstates_old)
601601
++ngotos_reachable;
602602
}
603603
}
604-
while (nonterminal <= nvars)
604+
while (nonterminal <= nnterms)
605605
{
606606
aver (ngotos == goto_map[nonterminal]);
607607
goto_map[nonterminal++] = ngotos_reachable;

0 commit comments

Comments
 (0)