mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-17 00:03:03 +00:00
doc: style changes.
* doc/bison.texinfo: Avoid line width issues with TeX.
Upgrade ancient messages.
Move some comments to better looking places.
Add more @group.
(Mfcalc Symbol Table): Reduce variable scopes.
Prefer size_t for sizes.
Prefer declarations with an initial value.
Fix a @group environment.
(cherry picked from commit aaaa2aaef4)
Conflicts:
doc/bison.texinfo
This commit is contained in:
@@ -1199,8 +1199,9 @@ will suffice. Otherwise, we suggest
|
|||||||
|
|
||||||
@example
|
@example
|
||||||
%@{
|
%@{
|
||||||
#if __STDC_VERSION__ < 199901 && ! defined __GNUC__ && ! defined inline
|
#if (__STDC_VERSION__ < 199901 && ! defined __GNUC__ \
|
||||||
#define inline
|
&& ! defined inline)
|
||||||
|
# define inline
|
||||||
#endif
|
#endif
|
||||||
%@}
|
%@}
|
||||||
@end example
|
@end example
|
||||||
@@ -1389,11 +1390,11 @@ simple program, all the rest of the program can go here.
|
|||||||
@cindex simple examples
|
@cindex simple examples
|
||||||
@cindex examples, simple
|
@cindex examples, simple
|
||||||
|
|
||||||
Now we show and explain three sample programs written using Bison: a
|
Now we show and explain several sample programs written using Bison: a
|
||||||
reverse polish notation calculator, an algebraic (infix) notation
|
reverse polish notation calculator, an algebraic (infix) notation
|
||||||
calculator, and a multi-function calculator. All three have been tested
|
calculator --- later extended to track ``locations'' ---
|
||||||
under BSD Unix 4.3; each produces a usable, though limited, interactive
|
and a multi-function calculator. All
|
||||||
desk-top calculator.
|
produce usable, though limited, interactive desk-top calculators.
|
||||||
|
|
||||||
These examples are simple, but Bison grammars for real programming
|
These examples are simple, but Bison grammars for real programming
|
||||||
languages are written the same way. You can copy these examples into a
|
languages are written the same way. You can copy these examples into a
|
||||||
@@ -1492,24 +1493,28 @@ type for numeric constants.
|
|||||||
Here are the grammar rules for the reverse polish notation calculator.
|
Here are the grammar rules for the reverse polish notation calculator.
|
||||||
|
|
||||||
@example
|
@example
|
||||||
|
@group
|
||||||
input: /* empty */
|
input: /* empty */
|
||||||
| input line
|
| input line
|
||||||
;
|
;
|
||||||
|
@end group
|
||||||
|
|
||||||
|
@group
|
||||||
line: '\n'
|
line: '\n'
|
||||||
| exp '\n' @{ printf ("\t%.10g\n", $1); @}
|
| exp '\n' @{ printf ("\t%.10g\n", $1); @}
|
||||||
;
|
;
|
||||||
|
@end group
|
||||||
|
|
||||||
|
@group
|
||||||
exp: NUM @{ $$ = $1; @}
|
exp: NUM @{ $$ = $1; @}
|
||||||
| exp exp '+' @{ $$ = $1 + $2; @}
|
| exp exp '+' @{ $$ = $1 + $2; @}
|
||||||
| exp exp '-' @{ $$ = $1 - $2; @}
|
| exp exp '-' @{ $$ = $1 - $2; @}
|
||||||
| exp exp '*' @{ $$ = $1 * $2; @}
|
| exp exp '*' @{ $$ = $1 * $2; @}
|
||||||
| exp exp '/' @{ $$ = $1 / $2; @}
|
| exp exp '/' @{ $$ = $1 / $2; @}
|
||||||
/* Exponentiation */
|
| exp exp '^' @{ $$ = pow ($1, $2); @} /* Exponentiation */
|
||||||
| exp exp '^' @{ $$ = pow ($1, $2); @}
|
| exp 'n' @{ $$ = -$1; @} /* Unary minus */
|
||||||
/* Unary minus */
|
|
||||||
| exp 'n' @{ $$ = -$1; @}
|
|
||||||
;
|
;
|
||||||
|
@end group
|
||||||
%%
|
%%
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
@@ -1765,7 +1770,9 @@ here is the definition we will use:
|
|||||||
@example
|
@example
|
||||||
@group
|
@group
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@end group
|
||||||
|
|
||||||
|
@group
|
||||||
/* Called by yyparse on error. */
|
/* Called by yyparse on error. */
|
||||||
void
|
void
|
||||||
yyerror (char const *s)
|
yyerror (char const *s)
|
||||||
@@ -1871,6 +1878,7 @@ parentheses nested to arbitrary depth. Here is the Bison code for
|
|||||||
@example
|
@example
|
||||||
/* Infix notation calculator. */
|
/* Infix notation calculator. */
|
||||||
|
|
||||||
|
@group
|
||||||
%@{
|
%@{
|
||||||
#define YYSTYPE double
|
#define YYSTYPE double
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@@ -1878,32 +1886,41 @@ parentheses nested to arbitrary depth. Here is the Bison code for
|
|||||||
int yylex (void);
|
int yylex (void);
|
||||||
void yyerror (char const *);
|
void yyerror (char const *);
|
||||||
%@}
|
%@}
|
||||||
|
@end group
|
||||||
|
|
||||||
|
@group
|
||||||
/* Bison declarations. */
|
/* Bison declarations. */
|
||||||
%token NUM
|
%token NUM
|
||||||
%left '-' '+'
|
%left '-' '+'
|
||||||
%left '*' '/'
|
%left '*' '/'
|
||||||
%left NEG /* negation--unary minus */
|
%left NEG /* negation--unary minus */
|
||||||
%right '^' /* exponentiation */
|
%right '^' /* exponentiation */
|
||||||
|
@end group
|
||||||
|
|
||||||
%% /* The grammar follows. */
|
%% /* The grammar follows. */
|
||||||
|
@group
|
||||||
input: /* empty */
|
input: /* empty */
|
||||||
| input line
|
| input line
|
||||||
;
|
;
|
||||||
|
@end group
|
||||||
|
|
||||||
|
@group
|
||||||
line: '\n'
|
line: '\n'
|
||||||
| exp '\n' @{ printf ("\t%.10g\n", $1); @}
|
| exp '\n' @{ printf ("\t%.10g\n", $1); @}
|
||||||
;
|
;
|
||||||
|
@end group
|
||||||
|
|
||||||
exp: NUM @{ $$ = $1; @}
|
@group
|
||||||
| exp '+' exp @{ $$ = $1 + $3; @}
|
exp: NUM @{ $$ = $1; @}
|
||||||
| exp '-' exp @{ $$ = $1 - $3; @}
|
| exp '+' exp @{ $$ = $1 + $3; @}
|
||||||
| exp '*' exp @{ $$ = $1 * $3; @}
|
| exp '-' exp @{ $$ = $1 - $3; @}
|
||||||
| exp '/' exp @{ $$ = $1 / $3; @}
|
| exp '*' exp @{ $$ = $1 * $3; @}
|
||||||
| '-' exp %prec NEG @{ $$ = -$2; @}
|
| exp '/' exp @{ $$ = $1 / $3; @}
|
||||||
|
| '-' exp %prec NEG @{ $$ = -$2; @}
|
||||||
| exp '^' exp @{ $$ = pow ($1, $3); @}
|
| exp '^' exp @{ $$ = pow ($1, $3); @}
|
||||||
| '(' exp ')' @{ $$ = $2; @}
|
| '(' exp ')' @{ $$ = $2; @}
|
||||||
;
|
;
|
||||||
|
@end group
|
||||||
%%
|
%%
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
@@ -2439,10 +2456,9 @@ void
|
|||||||
init_table (void)
|
init_table (void)
|
||||||
@{
|
@{
|
||||||
int i;
|
int i;
|
||||||
symrec *ptr;
|
|
||||||
for (i = 0; arith_fncts[i].fname != 0; i++)
|
for (i = 0; arith_fncts[i].fname != 0; i++)
|
||||||
@{
|
@{
|
||||||
ptr = putsym (arith_fncts[i].fname, FNCT);
|
symrec *ptr = putsym (arith_fncts[i].fname, FNCT);
|
||||||
ptr->value.fnctptr = arith_fncts[i].fnct;
|
ptr->value.fnctptr = arith_fncts[i].fnct;
|
||||||
@}
|
@}
|
||||||
@}
|
@}
|
||||||
@@ -2476,8 +2492,7 @@ found, a pointer to that symbol is returned; otherwise zero is returned.
|
|||||||
symrec *
|
symrec *
|
||||||
putsym (char const *sym_name, int sym_type)
|
putsym (char const *sym_name, int sym_type)
|
||||||
@{
|
@{
|
||||||
symrec *ptr;
|
symrec *ptr = (symrec *) malloc (sizeof (symrec));
|
||||||
ptr = (symrec *) malloc (sizeof (symrec));
|
|
||||||
ptr->name = (char *) malloc (strlen (sym_name) + 1);
|
ptr->name = (char *) malloc (strlen (sym_name) + 1);
|
||||||
strcpy (ptr->name,sym_name);
|
strcpy (ptr->name,sym_name);
|
||||||
ptr->type = sym_type;
|
ptr->type = sym_type;
|
||||||
@@ -2550,21 +2565,20 @@ yylex (void)
|
|||||||
/* Char starts an identifier => read the name. */
|
/* Char starts an identifier => read the name. */
|
||||||
if (isalpha (c))
|
if (isalpha (c))
|
||||||
@{
|
@{
|
||||||
symrec *s;
|
/* Initially make the buffer long enough
|
||||||
|
for a 40-character symbol name. */
|
||||||
|
static size_t length = 40;
|
||||||
static char *symbuf = 0;
|
static char *symbuf = 0;
|
||||||
static int length = 0;
|
symrec *s;
|
||||||
int i;
|
int i;
|
||||||
@end group
|
@end group
|
||||||
|
|
||||||
@group
|
@group
|
||||||
/* Initially make the buffer long enough
|
if (!symbuf)
|
||||||
for a 40-character symbol name. */
|
symbuf = (char *) malloc (length + 1);
|
||||||
if (length == 0)
|
|
||||||
length = 40, symbuf = (char *)malloc (length + 1);
|
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
do
|
do
|
||||||
@end group
|
|
||||||
@group
|
@group
|
||||||
@{
|
@{
|
||||||
/* If buffer is full, make it bigger. */
|
/* If buffer is full, make it bigger. */
|
||||||
@@ -4027,6 +4041,7 @@ By default, @code{YYLLOC_DEFAULT} is defined this way:
|
|||||||
@end group
|
@end group
|
||||||
@end smallexample
|
@end smallexample
|
||||||
|
|
||||||
|
@noindent
|
||||||
where @code{YYRHSLOC (rhs, k)} is the location of the @var{k}th symbol
|
where @code{YYRHSLOC (rhs, k)} is the location of the @var{k}th symbol
|
||||||
in @var{rhs} when @var{k} is positive, and the location of the symbol
|
in @var{rhs} when @var{k} is positive, and the location of the symbol
|
||||||
just before the reduction when @var{k} and @var{n} are both zero.
|
just before the reduction when @var{k} and @var{n} are both zero.
|
||||||
@@ -8906,9 +8921,9 @@ The types for semantics value and locations.
|
|||||||
@end defcv
|
@end defcv
|
||||||
|
|
||||||
@defcv {Type} {parser} {token}
|
@defcv {Type} {parser} {token}
|
||||||
A structure that contains (only) the definition of the tokens as the
|
A structure that contains (only) the @code{yytokentype} enumeration, which
|
||||||
@code{yytokentype} enumeration. To refer to the token @code{FOO}, the
|
defines the tokens. To refer to the token @code{FOO},
|
||||||
scanner should use @code{yy::parser::token::FOO}. The scanner can use
|
use @code{yy::parser::token::FOO}. The scanner can use
|
||||||
@samp{typedef yy::parser::token token;} to ``import'' the token enumeration
|
@samp{typedef yy::parser::token token;} to ``import'' the token enumeration
|
||||||
(@pxref{Calc++ Scanner}).
|
(@pxref{Calc++ Scanner}).
|
||||||
@end defcv
|
@end defcv
|
||||||
@@ -9430,7 +9445,7 @@ calcxx_driver::scan_begin ()
|
|||||||
yyin = stdin;
|
yyin = stdin;
|
||||||
else if (!(yyin = fopen (file.c_str (), "r")))
|
else if (!(yyin = fopen (file.c_str (), "r")))
|
||||||
@{
|
@{
|
||||||
error (std::string ("cannot open ") + file + ": " + strerror(errno));
|
error ("cannot open " + file + ": " + strerror(errno));
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
@}
|
@}
|
||||||
@}
|
@}
|
||||||
|
|||||||
Reference in New Issue
Block a user