X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/ce24f7f59b9ececb3137a53a881e25fa28e19466..dd5611579b3978eff5c4aa22dc8459b8f53c2fc0:/doc/bison.texinfo?ds=sidebyside diff --git a/doc/bison.texinfo b/doc/bison.texinfo index 0d6675bd..329d81d0 100644 --- a/doc/bison.texinfo +++ b/doc/bison.texinfo @@ -33,7 +33,7 @@ This manual (@value{UPDATED}) is for GNU Bison (version @value{VERSION}), the GNU parser generator. -Copyright @copyright{} 1988-1993, 1995, 1998-2011 Free Software +Copyright @copyright{} 1988-1993, 1995, 1998-2012 Free Software Foundation, Inc. @quotation @@ -125,7 +125,7 @@ The Concepts of Bison the name of an identifier, etc.). * Semantic Actions:: Each rule can have an action containing C code. * GLR Parsers:: Writing parsers for general context-free languages. -* Locations Overview:: Tracking Locations. +* Locations:: Overview of location tracking. * Bison Parser:: What are Bison's input and output, how is the output used? * Stages:: Stages in writing and running Bison grammars. @@ -180,15 +180,15 @@ Multi-Function Calculator: @code{mfcalc} Bison Grammar Files -* Grammar Outline:: Overall layout of the grammar file. -* Symbols:: Terminal and nonterminal symbols. -* Rules:: How to write grammar rules. -* Recursion:: Writing recursive rules. -* Semantics:: Semantic values and actions. -* Locations:: Locations and actions. -* Named References:: Using named references in actions. -* Declarations:: All kinds of Bison declarations are described here. -* Multiple Parsers:: Putting more than one Bison parser in one program. +* Grammar Outline:: Overall layout of the grammar file. +* Symbols:: Terminal and nonterminal symbols. +* Rules:: How to write grammar rules. +* Recursion:: Writing recursive rules. +* Semantics:: Semantic values and actions. +* Tracking Locations:: Locations and actions. +* Named References:: Using named references in actions. +* Declarations:: All kinds of Bison declarations are described here. +* Multiple Parsers:: Putting more than one Bison parser in one program. Outline of a Bison Grammar @@ -449,7 +449,7 @@ use Bison or Yacc, we suggest you start by reading this chapter carefully. the name of an identifier, etc.). * Semantic Actions:: Each rule can have an action containing C code. * GLR Parsers:: Writing parsers for general context-free languages. -* Locations Overview:: Tracking Locations. +* Locations:: Overview of location tracking. * Bison Parser:: What are Bison's input and output, how is the output used? * Stages:: Stages in writing and running Bison grammars. @@ -1205,7 +1205,7 @@ will suffice. Otherwise, we suggest %@} @end example -@node Locations Overview +@node Locations @section Locations @cindex location @cindex textual location @@ -1217,9 +1217,10 @@ the @dfn{textual location}, or @dfn{location}, of each syntactic construct. Bison provides a mechanism for handling these locations. Each token has a semantic value. In a similar fashion, each token has an -associated location, but the type of locations is the same for all tokens and -groupings. Moreover, the output parser is equipped with a default data -structure for storing locations (@pxref{Locations}, for more details). +associated location, but the type of locations is the same for all tokens +and groupings. Moreover, the output parser is equipped with a default data +structure for storing locations (@pxref{Tracking Locations}, for more +details). Like semantic values, locations can be reached in actions using a dedicated set of constructs. In the example above, the location of the whole grouping @@ -2621,15 +2622,15 @@ The Bison grammar file conventionally has a name ending in @samp{.y}. @xref{Invocation, ,Invoking Bison}. @menu -* Grammar Outline:: Overall layout of the grammar file. -* Symbols:: Terminal and nonterminal symbols. -* Rules:: How to write grammar rules. -* Recursion:: Writing recursive rules. -* Semantics:: Semantic values and actions. -* Locations:: Locations and actions. -* Named References:: Using named references in actions. -* Declarations:: All kinds of Bison declarations are described here. -* Multiple Parsers:: Putting more than one Bison parser in one program. +* Grammar Outline:: Overall layout of the grammar file. +* Symbols:: Terminal and nonterminal symbols. +* Rules:: How to write grammar rules. +* Recursion:: Writing recursive rules. +* Semantics:: Semantic values and actions. +* Tracking Locations:: Locations and actions. +* Named References:: Using named references in actions. +* Declarations:: All kinds of Bison declarations are described here. +* Multiple Parsers:: Putting more than one Bison parser in one program. @end menu @node Grammar Outline @@ -3806,7 +3807,7 @@ compound: subroutine Now Bison can execute the action in the rule for @code{subroutine} without deciding which rule for @code{compound} it will eventually use. -@node Locations +@node Tracking Locations @section Tracking Locations @cindex location @cindex textual location @@ -4918,9 +4919,8 @@ Unless your parser is pure, the parser header file declares (Reentrant) Parser}. If you have also used locations, the parser header file declares -@code{YYLTYPE} and @code{yylloc} using a protocol similar to that of -the @code{YYSTYPE} macro and @code{yylval}. @xref{Locations, -,Tracking Locations}. +@code{YYLTYPE} and @code{yylloc} using a protocol similar to that of the +@code{YYSTYPE} macro and @code{yylval}. @xref{Tracking Locations}. This parser header file is normally essential if you wish to put the definition of @code{yylex} in a separate source file, because @@ -5759,12 +5759,12 @@ then the code in @code{yylex} might look like this: @subsection Textual Locations of Tokens @vindex yylloc -If you are using the @samp{@@@var{n}}-feature (@pxref{Locations, , -Tracking Locations}) in actions to keep track of the textual locations -of tokens and groupings, then you must provide this information in -@code{yylex}. The function @code{yyparse} expects to find the textual -location of a token just parsed in the global variable @code{yylloc}. -So @code{yylex} must store the proper data in that variable. +If you are using the @samp{@@@var{n}}-feature (@pxref{Tracking Locations}) +in actions to keep track of the textual locations of tokens and groupings, +then you must provide this information in @code{yylex}. The function +@code{yyparse} expects to find the textual location of a token just parsed +in the global variable @code{yylloc}. So @code{yylex} must store the proper +data in that variable. By default, the value of @code{yylloc} is a structure and you need only initialize the members that are going to be used by the actions. The @@ -6090,9 +6090,9 @@ Actions}). @deffn {Value} @@$ @findex @@$ -Acts like a structure variable containing information on the textual location -of the grouping made by the current rule. @xref{Locations, , -Tracking Locations}. +Acts like a structure variable containing information on the textual +location of the grouping made by the current rule. @xref{Tracking +Locations}. @c Check if those paragraphs are still useful or not. @@ -6116,9 +6116,9 @@ Tracking Locations}. @deffn {Value} @@@var{n} @findex @@@var{n} -Acts like a structure variable containing information on the textual location -of the @var{n}th component of the current rule. @xref{Locations, , -Tracking Locations}. +Acts like a structure variable containing information on the textual +location of the @var{n}th component of the current rule. @xref{Tracking +Locations}. @end deffn @node Internationalization @@ -8760,10 +8760,10 @@ Symbols}. @c - %define filename_type "const symbol::Symbol" When the directive @code{%locations} is used, the C++ parser supports -location tracking, see @ref{Locations, , Locations Overview}. Two -auxiliary classes define a @code{position}, a single point in a file, -and a @code{location}, a range composed of a pair of -@code{position}s (possibly spanning several files). +location tracking, see @ref{Tracking Locations}. Two auxiliary classes +define a @code{position}, a single point in a file, and a @code{location}, a +range composed of a pair of @code{position}s (possibly spanning several +files). @deftypemethod {position} {std::string*} file The name of the file. It will always be handled as a pointer, the @@ -9366,8 +9366,8 @@ calcxx_driver::scan_begin () yyin = stdin; else if (!(yyin = fopen (file.c_str (), "r"))) @{ - error (std::string ("cannot open ") + file); - exit (1); + error (std::string ("cannot open ") + file + ": " + strerror(errno)); + exit (EXIT_FAILURE); @} @} @@ -9515,14 +9515,13 @@ can be used to print the semantic values. This however may change @c - class Position @c - class Location -When the directive @code{%locations} is used, the Java parser -supports location tracking, see @ref{Locations, , Locations Overview}. -An auxiliary user-defined class defines a @dfn{position}, a single point -in a file; Bison itself defines a class representing a @dfn{location}, -a range composed of a pair of positions (possibly spanning several -files). The location class is an inner class of the parser; the name -is @code{Location} by default, and may also be renamed using -@code{%define location_type "@var{class-name}"}. +When the directive @code{%locations} is used, the Java parser supports +location tracking, see @ref{Tracking Locations}. An auxiliary user-defined +class defines a @dfn{position}, a single point in a file; Bison itself +defines a class representing a @dfn{location}, a range composed of a pair of +positions (possibly spanning several files). The location class is an inner +class of the parser; the name is @code{Location} by default, and may also be +renamed using @code{%define location_type "@var{class-name}"}. The location class treats the position as a completely opaque value. By default, the class name is @code{Position}, but this can be changed @@ -10046,11 +10045,17 @@ yyparse (char const *file) { yyin = fopen (file, "r"); if (!yyin) - exit (2); + { + perror ("fopen"); + exit (EXIT_FAILURE); + } /* One token only. */ yylex (); if (fclose (yyin) != 0) - exit (3); + { + perror ("fclose"); + exit (EXIT_FAILURE); + } return 0; } @@ -10309,7 +10314,7 @@ transcript of the build session, starting with the invocation of send additional files as well (such as `config.h' or `config.cache'). Patches are most welcome, but not required. That is, do not hesitate to -send a bug report just because you can not provide a fix. +send a bug report just because you cannot provide a fix. Send bug reports to @email{bug-bison@@gnu.org}. @@ -10362,22 +10367,22 @@ See @url{http://lists.gnu.org/}. @deffn {Variable} @@$ In an action, the location of the left-hand side of the rule. -@xref{Locations, , Locations Overview}. +@xref{Tracking Locations}. @end deffn @deffn {Variable} @@@var{n} -In an action, the location of the @var{n}-th symbol of the right-hand -side of the rule. @xref{Locations, , Locations Overview}. +In an action, the location of the @var{n}-th symbol of the right-hand side +of the rule. @xref{Tracking Locations}. @end deffn @deffn {Variable} @@@var{name} -In an action, the location of a symbol addressed by name. -@xref{Locations, , Locations Overview}. +In an action, the location of a symbol addressed by name. @xref{Tracking +Locations}. @end deffn @deffn {Variable} @@[@var{name}] -In an action, the location of a symbol addressed by name. -@xref{Locations, , Locations Overview}. +In an action, the location of a symbol addressed by name. @xref{Tracking +Locations}. @end deffn @deffn {Variable} $$