doc: a single space before closing comments

I don't think this style:

    /* If buffer is full, make it bigger.        */
    if (i == length)
      {
        length *= 2;
        symbuf = (char *) realloc (symbuf, length + 1);
      }
    /* Add this character to the buffer.         */
    symbuf[i++] = c;
    /* Get another character.                    */
    c = getchar ();

or more readable than

    /* If buffer is full, make it bigger. */
    if (i == length)
      {
        length *= 2;
        symbuf = (char *) realloc (symbuf, length + 1);
      }
    /* Add this character to the buffer. */
    symbuf[i++] = c;
    /* Get another character. */
    c = getchar ();

Actually, I think the latter is more readable, and helps with width
issues in the PDF.  As a matter of fact, I would happily move to //
only for single line comments.

* doc/bison.texi: A single space before closing comments.
This commit is contained in:
Akim Demaille
2019-02-10 16:38:22 +01:00
parent 8b2d233283
commit f23b879ff5

View File

@@ -1548,7 +1548,7 @@ after @samp{//}.
@comment file: rpcalc.y @comment file: rpcalc.y
@example @example
/* Reverse Polish Notation calculator. */ /* Reverse Polish Notation calculator. */
@group @group
%@{ %@{
@@ -1562,7 +1562,7 @@ after @samp{//}.
%define api.value.type @{double@} %define api.value.type @{double@}
%token NUM %token NUM
%% /* Grammar rules and actions follow. */ %% /* Grammar rules and actions follow. */
@end example @end example
The declarations section (@pxref{Prologue, , The prologue}) contains two The declarations section (@pxref{Prologue, , The prologue}) contains two
@@ -1625,7 +1625,7 @@ exp:
| exp exp '*' @{ $$ = $1 * $2; @} | exp exp '*' @{ $$ = $1 * $2; @}
| exp exp '/' @{ $$ = $1 / $2; @} | exp exp '/' @{ $$ = $1 / $2; @}
| exp exp '^' @{ $$ = pow ($1, $2); @} /* Exponentiation */ | exp exp '^' @{ $$ = pow ($1, $2); @} /* Exponentiation */
| exp 'n' @{ $$ = -$1; @} /* Unary minus */ | exp 'n' @{ $$ = -$1; @} /* Unary minus */
; ;
@end group @end group
%% %%
@@ -1828,7 +1828,7 @@ Here is the code for the lexical analyzer:
/* The lexical analyzer returns a double floating point /* The lexical analyzer returns a double floating point
number on the stack and the token NUM, or the numeric code number on the stack and the token NUM, or the numeric code
of the character read if not a number. It skips all blanks of the character read if not a number. It skips all blanks
and tabs, and returns 0 for end-of-input. */ and tabs, and returns 0 for end-of-input. */
#include <ctype.h> #include <ctype.h>
@end group @end group
@@ -1838,12 +1838,12 @@ int
yylex (void) yylex (void)
@{ @{
int c = getchar (); int c = getchar ();
/* Skip white space. */ /* Skip white space. */
while (c == ' ' || c == '\t') while (c == ' ' || c == '\t')
c = getchar (); c = getchar ();
@end group @end group
@group @group
/* Process numbers. */ /* Process numbers. */
if (c == '.' || isdigit (c)) if (c == '.' || isdigit (c))
@{ @{
ungetc (c, stdin); ungetc (c, stdin);
@@ -1852,10 +1852,10 @@ yylex (void)
@} @}
@end group @end group
@group @group
/* Return end-of-input. */ /* Return end-of-input. */
else if (c == EOF) else if (c == EOF)
return 0; return 0;
/* Return a single char. */ /* Return a single char. */
else else
return c; return c;
@} @}
@@ -1897,7 +1897,7 @@ here is the definition we will use:
#include <stdio.h> #include <stdio.h>
@group @group
/* Called by yyparse on error. */ /* Called by yyparse on error. */
void void
yyerror (char const *s) yyerror (char const *s)
@{ @{
@@ -2000,7 +2000,7 @@ parentheses nested to arbitrary depth. Here is the Bison code for
@file{calc.y}, an infix desk-top calculator. @file{calc.y}, an infix desk-top calculator.
@example @example
/* Infix notation calculator. */ /* Infix notation calculator. */
@group @group
%@{ %@{
@@ -2012,7 +2012,7 @@ parentheses nested to arbitrary depth. Here is the Bison code for
@end group @end group
@group @group
/* Bison declarations. */ /* Bison declarations. */
%define api.value.type @{double@} %define api.value.type @{double@}
%token NUM %token NUM
%left '-' '+' %left '-' '+'
@@ -2021,7 +2021,7 @@ parentheses nested to arbitrary depth. Here is the Bison code for
%right '^' /* exponentiation */ %right '^' /* exponentiation */
@end group @end group
%% /* The grammar follows. */ %% /* The grammar follows. */
@group @group
input: input:
%empty %empty
@@ -2160,7 +2160,7 @@ The C and Bison declarations for the location tracking calculator are
the same as the declarations for the infix notation calculator. the same as the declarations for the infix notation calculator.
@example @example
/* Location tracking calculator. */ /* Location tracking calculator. */
%@{ %@{
#include <math.h> #include <math.h>
@@ -2168,7 +2168,7 @@ the same as the declarations for the infix notation calculator.
void yyerror (char const *); void yyerror (char const *);
%@} %@}
/* Bison declarations. */ /* Bison declarations. */
%define api.value.type @{int@} %define api.value.type @{int@}
%token NUM %token NUM
@@ -2177,7 +2177,7 @@ the same as the declarations for the infix notation calculator.
%precedence NEG %precedence NEG
%right '^' %right '^'
%% /* The grammar follows. */ %% /* The grammar follows. */
@end example @end example
@noindent @noindent
@@ -2276,19 +2276,19 @@ yylex (void)
@end group @end group
@group @group
/* Skip white space. */ /* Skip white space. */
while ((c = getchar ()) == ' ' || c == '\t') while ((c = getchar ()) == ' ' || c == '\t')
++yylloc.last_column; ++yylloc.last_column;
@end group @end group
@group @group
/* Step. */ /* Step. */
yylloc.first_line = yylloc.last_line; yylloc.first_line = yylloc.last_line;
yylloc.first_column = yylloc.last_column; yylloc.first_column = yylloc.last_column;
@end group @end group
@group @group
/* Process numbers. */ /* Process numbers. */
if (isdigit (c)) if (isdigit (c))
@{ @{
yylval = c - '0'; yylval = c - '0';
@@ -2303,12 +2303,12 @@ yylex (void)
@} @}
@end group @end group
/* Return end-of-input. */ /* Return end-of-input. */
if (c == EOF) if (c == EOF)
return 0; return 0;
@group @group
/* Return a single char, and update location. */ /* Return a single char, and update location. */
if (c == '\n') if (c == '\n')
@{ @{
++yylloc.last_line; ++yylloc.last_line;
@@ -2415,15 +2415,15 @@ Here are the C and Bison declarations for the multi-function calculator.
@group @group
%@{ %@{
#include <stdio.h> /* For printf, etc. */ #include <stdio.h> /* For printf, etc. */
#include <math.h> /* For pow, used in the grammar. */ #include <math.h> /* For pow, used in the grammar. */
#include "calc.h" /* Contains definition of 'symrec'. */ #include "calc.h" /* Contains definition of 'symrec'. */
int yylex (void); int yylex (void);
void yyerror (char const *); void yyerror (char const *);
%@} %@}
@end group @end group
%define api.value.type union /* Generate YYSTYPE from these types: */ %define api.value.type union /* Generate YYSTYPE from these types: */
%token <double> NUM /* Double precision number. */ %token <double> NUM /* Double precision number. */
%token <symrec*> VAR FUN /* Symbol table pointer: variable/function. */ %token <symrec*> VAR FUN /* Symbol table pointer: variable/function. */
%type <double> exp %type <double> exp
@@ -2467,7 +2467,7 @@ those which mention @code{VAR} or @code{FUN}, are new.
@comment file: mfcalc.y: 3 @comment file: mfcalc.y: 3
@example @example
%% /* The grammar follows. */ %% /* The grammar follows. */
@group @group
input: input:
%empty %empty
@@ -2498,7 +2498,7 @@ exp:
| '(' exp ')' @{ $$ = $2; @} | '(' exp ')' @{ $$ = $2; @}
; ;
@end group @end group
/* End of grammar. */ /* End of grammar. */
%% %%
@end example @end example
@@ -2518,12 +2518,12 @@ provides for either functions or variables to be placed in the table.
@comment file: calc.h @comment file: calc.h
@example @example
@group @group
/* Function type. */ /* Function type. */
typedef double (func_t) (double); typedef double (func_t) (double);
@end group @end group
@group @group
/* Data type for links in the chain of symbols. */ /* Data type for links in the chain of symbols. */
struct symrec struct symrec
@{ @{
char *name; /* name of symbol */ char *name; /* name of symbol */
@@ -2540,7 +2540,7 @@ struct symrec
@group @group
typedef struct symrec symrec; typedef struct symrec symrec;
/* The symbol table: a chain of 'struct symrec'. */ /* The symbol table: a chain of 'struct symrec'. */
extern symrec *sym_table; extern symrec *sym_table;
symrec *putsym (char const *name, int sym_type); symrec *putsym (char const *name, int sym_type);
@@ -2575,12 +2575,12 @@ struct init const arith_funs[] =
@end group @end group
@group @group
/* The symbol table: a chain of 'struct symrec'. */ /* The symbol table: a chain of 'struct symrec'. */
symrec *sym_table; symrec *sym_table;
@end group @end group
@group @group
/* Put arithmetic functions in table. */ /* Put arithmetic functions in table. */
static void static void
init_table (void) init_table (void)
@end group @end group
@@ -2617,7 +2617,7 @@ putsym (char const *name, int sym_type)
symrec *res = (symrec *) malloc (sizeof (symrec)); symrec *res = (symrec *) malloc (sizeof (symrec));
res->name = strdup (name); res->name = strdup (name);
res->type = sym_type; res->type = sym_type;
res->value.var = 0; /* Set value to 0 even if fun. */ res->value.var = 0; /* Set value to 0 even if fun. */
res->next = sym_table; res->next = sym_table;
sym_table = res; sym_table = res;
return res; return res;
@@ -2664,7 +2664,7 @@ yylex (void)
@{ @{
int c; int c;
/* Ignore white space, get first nonwhite character. */ /* Ignore white space, get first nonwhite character. */
while ((c = getchar ()) == ' ' || c == '\t') while ((c = getchar ()) == ' ' || c == '\t')
continue; continue;
@@ -2673,7 +2673,7 @@ yylex (void)
@end group @end group
@group @group
/* Char starts a number => parse the number. */ /* Char starts a number => parse the number. */
if (c == '.' || isdigit (c)) if (c == '.' || isdigit (c))
@{ @{
ungetc (c, stdin); ungetc (c, stdin);
@@ -2690,11 +2690,11 @@ Bison generated a definition of @code{YYSTYPE} with a member named
@comment file: mfcalc.y: 3 @comment file: mfcalc.y: 3
@example @example
@group @group
/* Char starts an identifier => read the name. */ /* Char starts an identifier => read the name. */
if (isalpha (c)) if (isalpha (c))
@{ @{
/* Initially make the buffer long enough /* Initially make the buffer long enough
for a 40-character symbol name. */ for a 40-character symbol name. */
static size_t length = 40; static size_t length = 40;
static char *symbuf = 0; static char *symbuf = 0;
@end group @end group
@@ -2705,15 +2705,15 @@ Bison generated a definition of @code{YYSTYPE} with a member named
do do
@group @group
@{ @{
/* If buffer is full, make it bigger. */ /* If buffer is full, make it bigger. */
if (i == length) if (i == length)
@{ @{
length *= 2; length *= 2;
symbuf = realloc (symbuf, length + 1); symbuf = realloc (symbuf, length + 1);
@} @}
/* Add this character to the buffer. */ /* Add this character to the buffer. */
symbuf[i++] = c; symbuf[i++] = c;
/* Get another character. */ /* Get another character. */
c = getchar (); c = getchar ();
@} @}
@end group @end group
@@ -2728,11 +2728,11 @@ Bison generated a definition of @code{YYSTYPE} with a member named
symrec *s = getsym (symbuf); symrec *s = getsym (symbuf);
if (!s) if (!s)
s = putsym (symbuf, VAR); s = putsym (symbuf, VAR);
yylval.VAR = s; /* or yylval.FUN = s. */ yylval.VAR = s; /* or yylval.FUN = s. */
return s->type; return s->type;
@} @}
/* Any other character is a token by itself. */ /* Any other character is a token by itself. */
return c; return c;
@} @}
@end group @end group
@@ -2748,7 +2748,7 @@ on user demand (@xref{Tracing, , Tracing Your Parser}, for details):
@comment file: mfcalc.y: 3 @comment file: mfcalc.y: 3
@example @example
@group @group
/* Called by yyparse on error. */ /* Called by yyparse on error. */
void yyerror (char const *s) void yyerror (char const *s)
@{ @{
fprintf (stderr, "%s\n", s); fprintf (stderr, "%s\n", s);
@@ -2760,7 +2760,7 @@ int main (int argc, char const* argv[])
@end group @end group
@group @group
@{ @{
/* Enable parse traces on option -p. */ /* Enable parse traces on option -p. */
if (argc == 2 && strcmp(argv[1], "-p") == 0) if (argc == 2 && strcmp(argv[1], "-p") == 0)
yydebug = 1; yydebug = 1;
@end group @end group
@@ -2984,7 +2984,7 @@ the same time:
#include <stdio.h> #include <stdio.h>
/* WARNING: The following code really belongs /* WARNING: The following code really belongs
* in a '%code requires'; see below. */ * in a '%code requires'; see below. */
#include "ptypes.h" #include "ptypes.h"
#define YYLTYPE YYLTYPE #define YYLTYPE YYLTYPE
@@ -3769,15 +3769,15 @@ names on which you should not depend; instead, relying on C casts to access
the semantic value with the appropriate type: the semantic value with the appropriate type:
@example @example
/* For an "integer". */ /* For an "integer". */
yylval.INT = 42; yylval.INT = 42;
return INT; return INT;
/* For an 'n', also declared as int. */ /* For an 'n', also declared as int. */
*((int*)&yylval) = 42; *((int*)&yylval) = 42;
return 'n'; return 'n';
/* For an "identifier". */ /* For an "identifier". */
yylval.ID = "42"; yylval.ID = "42";
return ID; return ID;
@end example @end example
@@ -3788,7 +3788,7 @@ the union member names. For instance, with @samp{%define api.token.prefix
@{TOK_@}}: @{TOK_@}}:
@example @example
/* For an "integer". */ /* For an "integer". */
yylval.TOK_INT = 42; yylval.TOK_INT = 42;
return TOK_INT; return TOK_INT;
@end example @end example
@@ -6704,7 +6704,7 @@ parsers. To comply with this tradition, when @code{api.prefix} is used,
@code{YYDEBUG} (not renamed) is used as a default value: @code{YYDEBUG} (not renamed) is used as a default value:
@example @example
/* Debug traces. */ /* Debug traces. */
#ifndef CDEBUG #ifndef CDEBUG
# if defined YYDEBUG # if defined YYDEBUG
# if YYDEBUG # if YYDEBUG
@@ -6815,7 +6815,7 @@ Then call the parser like this:
@example @example
@{ @{
int nastiness, randomness; int nastiness, randomness;
@dots{} /* @r{Store proper data in @code{nastiness} and @code{randomness}.} */ @dots{} /* @r{Store proper data in @code{nastiness} and @code{randomness}.} */
value = yyparse (&nastiness, &randomness); value = yyparse (&nastiness, &randomness);
@dots{} @dots{}
@} @}
@@ -6973,13 +6973,13 @@ int
yylex (void) yylex (void)
@{ @{
@dots{} @dots{}
if (c == EOF) /* Detect end-of-input. */ if (c == EOF) /* Detect end-of-input. */
return 0; return 0;
@dots{} @dots{}
if (c == '+' || c == '-') if (c == '+' || c == '-')
return c; /* Assume token type for '+' is '+'. */ return c; /* Assume token type for '+' is '+'. */
@dots{} @dots{}
return INT; /* Return the type of the token. */ return INT; /* Return the type of the token. */
@dots{} @dots{}
@} @}
@end example @end example
@@ -7041,8 +7041,8 @@ Thus, if the type is @code{int} (the default), you might write this in
@example @example
@group @group
@dots{} @dots{}
yylval = value; /* Put value onto Bison stack. */ yylval = value; /* Put value onto Bison stack. */
return INT; /* Return the type of the token. */ return INT; /* Return the type of the token. */
@dots{} @dots{}
@end group @end group
@end example @end example
@@ -7069,8 +7069,8 @@ then the code in @code{yylex} might look like this:
@example @example
@group @group
@dots{} @dots{}
yylval.intval = value; /* Put value onto Bison stack. */ yylval.intval = value; /* Put value onto Bison stack. */
return INT; /* Return the type of the token. */ return INT; /* Return the type of the token. */
@dots{} @dots{}
@end group @end group
@end example @end example
@@ -7111,8 +7111,8 @@ int
yylex (YYSTYPE *lvalp, YYLTYPE *llocp) yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
@{ @{
@dots{} @dots{}
*lvalp = value; /* Put value onto Bison stack. */ *lvalp = value; /* Put value onto Bison stack. */
return INT; /* Return the type of the token. */ return INT; /* Return the type of the token. */
@dots{} @dots{}
@} @}
@end example @end example
@@ -8327,7 +8327,7 @@ distinct. In the above example, adding one rule to
return_spec: return_spec:
type type
| name ':' type | name ':' type
| "id" "bogus" /* This rule is never used. */ | "id" "bogus" /* This rule is never used. */
; ;
@end group @end group
@end example @end example
@@ -8970,7 +8970,7 @@ error recovery. A simple and useful strategy is simply to skip the rest of
the current input line or current statement if an error is detected: the current input line or current statement if an error is detected:
@example @example
stmt: error ';' /* On error, skip until ';' is read. */ stmt: error ';' /* On error, skip until ';' is read. */
@end example @end example
It is also useful to recover to the matching close-delimiter of an It is also useful to recover to the matching close-delimiter of an
@@ -9996,12 +9996,12 @@ prologue:
@comment file: mfcalc.y: 2 @comment file: mfcalc.y: 2
@example @example
/* Generate the parser description file. */ /* Generate the parser description file. */
%verbose %verbose
/* Enable run-time traces (yydebug). */ /* Enable run-time traces (yydebug). */
%define parse.trace %define parse.trace
/* Formatting semantic values. */ /* Formatting semantic values. */
%printer @{ fprintf (yyo, "%s", $$->name); @} VAR; %printer @{ fprintf (yyo, "%s", $$->name); @} VAR;
%printer @{ fprintf (yyo, "%s()", $$->name); @} FUN; %printer @{ fprintf (yyo, "%s()", $$->name); @} FUN;
%printer @{ fprintf (yyo, "%g", $$); @} <double>; %printer @{ fprintf (yyo, "%g", $$); @} <double>;
@@ -13078,7 +13078,7 @@ yyparse (char const *file)
@} @}
@end group @end group
@group @group
/* One token only. */ /* One token only. */
yylex (); yylex ();
if (fclose (yyin) != 0) if (fclose (yyin) != 0)
@{ @{
@@ -13164,7 +13164,7 @@ char *yylval = NULL;
int int
main () main ()
@{ @{
/* Similar to using $1, $2 in a Bison action. */ /* Similar to using $1, $2 in a Bison action. */
char *fst = (yylex (), yylval); char *fst = (yylex (), yylval);
char *snd = (yylex (), yylval); char *snd = (yylex (), yylval);
printf ("\"%s\", \"%s\"\n", fst, snd); printf ("\"%s\", \"%s\"\n", fst, snd);
@@ -13265,7 +13265,7 @@ available in the scanner (e.g., a global variable or using
@code{%lex-param} etc.), and use the following: @code{%lex-param} etc.), and use the following:
@example @example
/* @r{Prologue.} */ /* @r{Prologue.} */
%% %%
%@{ %@{
if (start_token) if (start_token)
@@ -13275,7 +13275,7 @@ available in the scanner (e.g., a global variable or using
return t; return t;
@} @}
%@} %@}
/* @r{The rules.} */ /* @r{The rules.} */
@end example @end example