mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-20 17:53:02 +00:00
* doc/bison.texinfo: Update the copyright.
ANSIfy and GNUify the examples. Remove the old menu.
This commit is contained in:
@@ -1,3 +1,9 @@
|
|||||||
|
2000-09-18 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
|
* doc/bison.texinfo: Update the copyright.
|
||||||
|
ANSIfy and GNUify the examples.
|
||||||
|
Remove the old menu.
|
||||||
|
|
||||||
2000-09-18 Akim Demaille <akim@epita.fr>
|
2000-09-18 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
First set of tests: use the `calc' example from the documentation.
|
First set of tests: use the `calc' example from the documentation.
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ END-INFO-DIR-ENTRY
|
|||||||
@ifinfo
|
@ifinfo
|
||||||
This file documents the Bison parser generator.
|
This file documents the Bison parser generator.
|
||||||
|
|
||||||
Copyright (C) 1988, 89, 90, 91, 92, 93, 95, 98, 1999 Free Software Foundation, Inc.
|
Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1995, 1998, 1999, 2000
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
|
||||||
Permission is granted to make and distribute verbatim copies of
|
Permission is granted to make and distribute verbatim copies of
|
||||||
this manual provided the copyright notice and this permission notice
|
this manual provided the copyright notice and this permission notice
|
||||||
@@ -86,8 +87,9 @@ instead of in the original English.
|
|||||||
|
|
||||||
@page
|
@page
|
||||||
@vskip 0pt plus 1filll
|
@vskip 0pt plus 1filll
|
||||||
Copyright @copyright{} 1988, 89, 90, 91, 92, 93, 95, 98, 1999 Free Software
|
Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1995, 1998,
|
||||||
Foundation
|
1999, 2000
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
|
||||||
@sp 2
|
@sp 2
|
||||||
Published by the Free Software Foundation @*
|
Published by the Free Software Foundation @*
|
||||||
@@ -1428,7 +1430,8 @@ Here is the code for the lexical analyzer:
|
|||||||
@end group
|
@end group
|
||||||
|
|
||||||
@group
|
@group
|
||||||
yylex ()
|
int
|
||||||
|
yylex (void)
|
||||||
@{
|
@{
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
@@ -1466,9 +1469,10 @@ kept to the bare minimum. The only requirement is that it call
|
|||||||
|
|
||||||
@example
|
@example
|
||||||
@group
|
@group
|
||||||
main ()
|
int
|
||||||
|
main (void)
|
||||||
@{
|
@{
|
||||||
yyparse ();
|
return yyparse ();
|
||||||
@}
|
@}
|
||||||
@end group
|
@end group
|
||||||
@end example
|
@end example
|
||||||
@@ -1478,16 +1482,17 @@ main ()
|
|||||||
@cindex error reporting routine
|
@cindex error reporting routine
|
||||||
|
|
||||||
When @code{yyparse} detects a syntax error, it calls the error reporting
|
When @code{yyparse} detects a syntax error, it calls the error reporting
|
||||||
function @code{yyerror} to print an error message (usually but not always
|
function @code{yyerror} to print an error message (usually but not
|
||||||
@code{"parse error"}). It is up to the programmer to supply @code{yyerror}
|
always @code{"parse error"}). It is up to the programmer to supply
|
||||||
(@pxref{Interface, ,Parser C-Language Interface}), so here is the definition we will use:
|
@code{yyerror} (@pxref{Interface, ,Parser C-Language Interface}), so
|
||||||
|
here is the definition we will use:
|
||||||
|
|
||||||
@example
|
@example
|
||||||
@group
|
@group
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
yyerror (s) /* Called by yyparse on error */
|
void
|
||||||
char *s;
|
yyerror (const char *s) /* Called by yyparse on error */
|
||||||
@{
|
@{
|
||||||
printf ("%s\n", s);
|
printf ("%s\n", s);
|
||||||
@}
|
@}
|
||||||
@@ -1851,6 +1856,7 @@ The symbol table itself consists of a linked list of records. Its
|
|||||||
definition, which is kept in the header @file{calc.h}, is as follows. It
|
definition, which is kept in the header @file{calc.h}, is as follows. It
|
||||||
provides for either functions or variables to be placed in the table.
|
provides for either functions or variables to be placed in the table.
|
||||||
|
|
||||||
|
@c FIXME: ANSIfy the prototypes for FNCTPTR etc.
|
||||||
@smallexample
|
@smallexample
|
||||||
@group
|
@group
|
||||||
/* Data type for links in the chain of symbols. */
|
/* Data type for links in the chain of symbols. */
|
||||||
@@ -1885,16 +1891,17 @@ function that initializes the symbol table. Here it is, and
|
|||||||
@group
|
@group
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
main ()
|
int
|
||||||
|
main (void)
|
||||||
@{
|
@{
|
||||||
init_table ();
|
init_table ();
|
||||||
yyparse ();
|
return yyparse ();
|
||||||
@}
|
@}
|
||||||
@end group
|
@end group
|
||||||
|
|
||||||
@group
|
@group
|
||||||
yyerror (s) /* Called by yyparse on error */
|
void
|
||||||
char *s;
|
yyerror (const char *s) /* Called by yyparse on error */
|
||||||
@{
|
@{
|
||||||
printf ("%s\n", s);
|
printf ("%s\n", s);
|
||||||
@}
|
@}
|
||||||
@@ -1907,23 +1914,25 @@ struct init
|
|||||||
@end group
|
@end group
|
||||||
|
|
||||||
@group
|
@group
|
||||||
struct init arith_fncts[]
|
struct init arith_fncts[] =
|
||||||
= @{
|
@{
|
||||||
"sin", sin,
|
"sin", sin,
|
||||||
"cos", cos,
|
"cos", cos,
|
||||||
"atan", atan,
|
"atan", atan,
|
||||||
"ln", log,
|
"ln", log,
|
||||||
"exp", exp,
|
"exp", exp,
|
||||||
"sqrt", sqrt,
|
"sqrt", sqrt,
|
||||||
0, 0
|
0, 0
|
||||||
@};
|
@};
|
||||||
|
|
||||||
/* The symbol table: a chain of `struct symrec'. */
|
/* The symbol table: a chain of `struct symrec'. */
|
||||||
symrec *sym_table = (symrec *)0;
|
symrec *sym_table = (symrec *)0;
|
||||||
@end group
|
@end group
|
||||||
|
|
||||||
@group
|
@group
|
||||||
init_table () /* puts arithmetic functions in table. */
|
/* Put arithmetic functions in table. */
|
||||||
|
void
|
||||||
|
init_table (void)
|
||||||
@{
|
@{
|
||||||
int i;
|
int i;
|
||||||
symrec *ptr;
|
symrec *ptr;
|
||||||
@@ -1948,9 +1957,7 @@ found, a pointer to that symbol is returned; otherwise zero is returned.
|
|||||||
|
|
||||||
@smallexample
|
@smallexample
|
||||||
symrec *
|
symrec *
|
||||||
putsym (sym_name,sym_type)
|
putsym (char *sym_name, int sym_type)
|
||||||
char *sym_name;
|
|
||||||
int sym_type;
|
|
||||||
@{
|
@{
|
||||||
symrec *ptr;
|
symrec *ptr;
|
||||||
ptr = (symrec *) malloc (sizeof (symrec));
|
ptr = (symrec *) malloc (sizeof (symrec));
|
||||||
@@ -1964,8 +1971,7 @@ putsym (sym_name,sym_type)
|
|||||||
@}
|
@}
|
||||||
|
|
||||||
symrec *
|
symrec *
|
||||||
getsym (sym_name)
|
getsym (const char *sym_name)
|
||||||
char *sym_name;
|
|
||||||
@{
|
@{
|
||||||
symrec *ptr;
|
symrec *ptr;
|
||||||
for (ptr = sym_table; ptr != (symrec *) 0;
|
for (ptr = sym_table; ptr != (symrec *) 0;
|
||||||
@@ -1994,7 +2000,9 @@ operators in @code{yylex}.
|
|||||||
@smallexample
|
@smallexample
|
||||||
@group
|
@group
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
yylex ()
|
|
||||||
|
int
|
||||||
|
yylex (void)
|
||||||
@{
|
@{
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
@@ -3355,7 +3363,8 @@ signifies end-of-input.
|
|||||||
Here is an example showing these things:
|
Here is an example showing these things:
|
||||||
|
|
||||||
@example
|
@example
|
||||||
yylex ()
|
int
|
||||||
|
yylex (void)
|
||||||
@{
|
@{
|
||||||
@dots{}
|
@dots{}
|
||||||
if (c == EOF) /* Detect end of file. */
|
if (c == EOF) /* Detect end of file. */
|
||||||
@@ -3487,9 +3496,8 @@ shown here, and pass the information back by storing it through those
|
|||||||
pointers.
|
pointers.
|
||||||
|
|
||||||
@example
|
@example
|
||||||
yylex (lvalp, llocp)
|
int
|
||||||
YYSTYPE *lvalp;
|
yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
|
||||||
YYLTYPE *llocp;
|
|
||||||
@{
|
@{
|
||||||
@dots{}
|
@dots{}
|
||||||
*lvalp = value; /* Put value onto Bison stack. */
|
*lvalp = value; /* Put value onto Bison stack. */
|
||||||
@@ -3620,8 +3628,8 @@ The following definition suffices in simple programs:
|
|||||||
|
|
||||||
@example
|
@example
|
||||||
@group
|
@group
|
||||||
yyerror (s)
|
void
|
||||||
char *s;
|
yyerror (char *s)
|
||||||
@{
|
@{
|
||||||
@end group
|
@end group
|
||||||
@group
|
@group
|
||||||
@@ -4831,10 +4839,7 @@ calculator (@pxref{Mfcalc Decl, ,Declarations for @code{mfcalc}}):
|
|||||||
#define YYPRINT(file, type, value) yyprint (file, type, value)
|
#define YYPRINT(file, type, value) yyprint (file, type, value)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
yyprint (file, type, value)
|
yyprint (FILE *file, int type, YYSTYPE value)
|
||||||
FILE *file;
|
|
||||||
int type;
|
|
||||||
YYSTYPE value;
|
|
||||||
@{
|
@{
|
||||||
if (type == VAR)
|
if (type == VAR)
|
||||||
fprintf (file, " %s", value.tptr->name);
|
fprintf (file, " %s", value.tptr->name);
|
||||||
@@ -5006,7 +5011,7 @@ would like to direct Bison to use a different copy, setting the
|
|||||||
environment variable @code{BISON_SIMPLE} to the path of the file will
|
environment variable @code{BISON_SIMPLE} to the path of the file will
|
||||||
cause Bison to use that copy instead.
|
cause Bison to use that copy instead.
|
||||||
|
|
||||||
When the @samp{%semantic_parser} delcaration is used, Bison copies from
|
When the @samp{%semantic_parser} declaration is used, Bison copies from
|
||||||
a file called @file{bison.hairy} instead. The location of this file can
|
a file called @file{bison.hairy} instead. The location of this file can
|
||||||
also be specified or overridden in a similar fashion, with the
|
also be specified or overridden in a similar fashion, with the
|
||||||
@code{BISON_HAIRY} environment variable.
|
@code{BISON_HAIRY} environment variable.
|
||||||
@@ -5160,10 +5165,10 @@ Macro for the data type of semantic values; @code{int} by default.
|
|||||||
@xref{Value Type, ,Data Types of Semantic Values}.
|
@xref{Value Type, ,Data Types of Semantic Values}.
|
||||||
|
|
||||||
@item yychar
|
@item yychar
|
||||||
External integer variable that contains the integer value of the
|
External integer variable that contains the integer value of the current
|
||||||
current look-ahead token. (In a pure parser, it is a local variable
|
look-ahead token. (In a pure parser, it is a local variable within
|
||||||
within @code{yyparse}.) Error-recovery rule actions may examine this
|
@code{yyparse}.) Error-recovery rule actions may examine this variable.
|
||||||
variable. @xref{Action Features, ,Special Features for Use in Actions}.
|
@xref{Action Features, ,Special Features for Use in Actions}.
|
||||||
|
|
||||||
@item yyclearin
|
@item yyclearin
|
||||||
Macro used in error-recovery rule actions. It clears the previous
|
Macro used in error-recovery rule actions. It clears the previous
|
||||||
@@ -5181,7 +5186,8 @@ after a parse error. @xref{Error Recovery}.
|
|||||||
@item yyerror
|
@item yyerror
|
||||||
User-supplied function to be called by @code{yyparse} on error. The
|
User-supplied function to be called by @code{yyparse} on error. The
|
||||||
function receives one argument, a pointer to a character string
|
function receives one argument, a pointer to a character string
|
||||||
containing an error message. @xref{Error Reporting, ,The Error Reporting Function @code{yyerror}}.
|
containing an error message. @xref{Error Reporting, ,The Error
|
||||||
|
Reporting Function @code{yyerror}}.
|
||||||
|
|
||||||
@item yylex
|
@item yylex
|
||||||
User-supplied lexical analyzer function, called with no arguments
|
User-supplied lexical analyzer function, called with no arguments
|
||||||
@@ -5194,16 +5200,17 @@ variable within @code{yyparse}, and its address is passed to
|
|||||||
@code{yylex}.) @xref{Token Values, ,Semantic Values of Tokens}.
|
@code{yylex}.) @xref{Token Values, ,Semantic Values of Tokens}.
|
||||||
|
|
||||||
@item yylloc
|
@item yylloc
|
||||||
External variable in which @code{yylex} should place the line and
|
External variable in which @code{yylex} should place the line and column
|
||||||
column numbers associated with a token. (In a pure parser, it is a
|
numbers associated with a token. (In a pure parser, it is a local
|
||||||
local variable within @code{yyparse}, and its address is passed to
|
variable within @code{yyparse}, and its address is passed to
|
||||||
@code{yylex}.) You can ignore this variable if you don't use the
|
@code{yylex}.) You can ignore this variable if you don't use the
|
||||||
@samp{@@} feature in the grammar actions. @xref{Token Positions, ,Textual Positions of Tokens}.
|
@samp{@@} feature in the grammar actions. @xref{Token Positions,
|
||||||
|
,Textual Positions of Tokens}.
|
||||||
|
|
||||||
@item yynerrs
|
@item yynerrs
|
||||||
Global variable which Bison increments each time there is a parse
|
Global variable which Bison increments each time there is a parse error.
|
||||||
error. (In a pure parser, it is a local variable within
|
(In a pure parser, it is a local variable within @code{yyparse}.)
|
||||||
@code{yyparse}.) @xref{Error Reporting, ,The Error Reporting Function @code{yyerror}}.
|
@xref{Error Reporting, ,The Error Reporting Function @code{yyerror}}.
|
||||||
|
|
||||||
@item yyparse
|
@item yyparse
|
||||||
The parser function produced by Bison; call this function to start
|
The parser function produced by Bison; call this function to start
|
||||||
@@ -5448,31 +5455,3 @@ is a token. @xref{Language and Grammar, ,Languages and Context-Free Grammars}.
|
|||||||
@contents
|
@contents
|
||||||
|
|
||||||
@bye
|
@bye
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@c old menu
|
|
||||||
|
|
||||||
* Introduction::
|
|
||||||
* Conditions::
|
|
||||||
* Copying:: The GNU General Public License says
|
|
||||||
how you can copy and share Bison
|
|
||||||
|
|
||||||
Tutorial sections:
|
|
||||||
* Concepts:: Basic concepts for understanding Bison.
|
|
||||||
* Examples:: Three simple explained examples of using Bison.
|
|
||||||
|
|
||||||
Reference sections:
|
|
||||||
* Grammar File:: Writing Bison declarations and rules.
|
|
||||||
* Interface:: C-language interface to the parser function @code{yyparse}.
|
|
||||||
* Algorithm:: How the Bison parser works at run-time.
|
|
||||||
* Error Recovery:: Writing rules for error recovery.
|
|
||||||
* Context Dependency::What to do if your language syntax is too
|
|
||||||
messy for Bison to handle straightforwardly.
|
|
||||||
* Debugging:: Debugging Bison parsers that parse wrong.
|
|
||||||
* Invocation:: How to run Bison (to produce the parser source file).
|
|
||||||
* Table of Symbols:: All the keywords of the Bison language are explained.
|
|
||||||
* Glossary:: Basic concepts are explained.
|
|
||||||
* Index:: Cross-references to the text.
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user