X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/38a92d500a6c26a97e90256726241255f6f09d0a..b317297e4d0eec259d54a9ce0c7f82da8099353c:/doc/bison.texinfo diff --git a/doc/bison.texinfo b/doc/bison.texinfo index aa6f9ee8..96100d29 100644 --- a/doc/bison.texinfo +++ b/doc/bison.texinfo @@ -119,7 +119,8 @@ Reference sections: * Copying This Manual:: License for copying this manual. * Index:: Cross-references to the text. -@detailmenu --- The Detailed Node Listing --- +@detailmenu + --- The Detailed Node Listing --- The Concepts of Bison @@ -130,6 +131,8 @@ The Concepts of Bison a semantic value (the value of an integer, 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. * Bison Parser:: What are Bison's input and output, how is the output used? * Stages:: Stages in writing and running Bison grammars. @@ -143,8 +146,8 @@ Examples Operator precedence is introduced. * Simple Error Recovery:: Continuing after syntax errors. * Location Tracking Calc:: Demonstrating the use of @@@var{n} and @@$. -* Multi-function Calc:: Calculator with memory and trig functions. - It uses multiple data-types for semantic values. +* Multi-function Calc:: Calculator with memory and trig functions. + It uses multiple data-types for semantic values. * Exercises:: Ideas for improving the multi-function calculator. Reverse Polish Notation Calculator @@ -182,15 +185,16 @@ Bison Grammar Files * Rules:: How to write grammar rules. * Recursion:: Writing recursive rules. * Semantics:: Semantic values and actions. +* Locations:: Locations and 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 -* Prologue:: Syntax and usage of the prologue (declarations section). +* Prologue:: Syntax and usage of the prologue. * Bison Declarations:: Syntax and usage of the Bison declarations section. * Grammar Rules:: Syntax and usage of the grammar rules section. -* Epilogue:: Syntax and usage of the epilogue (additional code section). +* Epilogue:: Syntax and usage of the epilogue. Defining Language Semantics @@ -202,6 +206,12 @@ Defining Language Semantics This says when, why and how to use the exceptional action in the middle of a rule. +Tracking Locations + +* Location Type:: Specifying a data type for locations. +* Actions and Locations:: Using locations in actions. +* Location Default Action:: Defining a general way to compute locations. + Bison Declarations * Token Decl:: Declaring terminal symbols. @@ -229,7 +239,7 @@ The Lexical Analyzer Function @code{yylex} of the token it has read. * Token Positions:: How @code{yylex} must return the text position (line number, etc.) of the token, if the - actions want that. + actions want that. * Pure Calling:: How the calling convention differs in a pure parser (@pxref{Pure Decl, ,A Pure (Reentrant) Parser}). @@ -259,7 +269,7 @@ Handling Context Dependencies * Tie-in Recovery:: Lexical tie-ins have implications for how error recovery rules must be written. -Understanding or Debugging Your Parser +Debugging Your Parser * Understanding:: Understanding the structure of your parser. * Tracing:: Tracing the execution of your parser. @@ -269,6 +279,7 @@ Invoking Bison * Bison Options:: All the options described in detail, in alphabetical order by short options. * Option Cross Key:: Alphabetical list of long options. +* Yacc Library:: Yacc-compatible @code{yylex} and @code{main}. Frequently Asked Questions @@ -4219,8 +4230,8 @@ void yyerror (YYLTYPE *locp, char const *msg); /* GLR parsers. */ If @samp{%parse-param @{int *nastiness@}} is used, then: @example -void yyerror (int *randomness, char const *msg); /* Yacc parsers. */ -void yyerror (int *randomness, char const *msg); /* GLR parsers. */ +void yyerror (int *nastiness, char const *msg); /* Yacc parsers. */ +void yyerror (int *nastiness, char const *msg); /* GLR parsers. */ @end example Finally, GLR and Yacc parsers share the same @code{yyerror} calling @@ -6071,10 +6082,15 @@ bison -d -o @var{output.c++} @var{infile.y} @noindent will produce @file{output.c++} and @file{outfile.h++}. +For compatibility with @acronym{POSIX}, the standard Bison +distribution also contains a shell script called @command{yacc} that +invokes Bison with the @option{-y} option. + @menu * Bison Options:: All the options described in detail, in alphabetical order by short options. * Option Cross Key:: Alphabetical list of long options. +* Yacc Library:: Yacc-compatible @code{yylex} and @code{main}. @end menu @node Bison Options @@ -6110,10 +6126,12 @@ Equivalent to @samp{-o y.tab.c}; the parser output file is called @file{y.tab.c}, and the other outputs are called @file{y.output} and @file{y.tab.h}. The purpose of this option is to imitate Yacc's output file name conventions. Thus, the following shell script can substitute -for Yacc: +for Yacc, and the Bison distribution contains such a script for +compatibility with @acronym{POSIX}: @example -bison -y $* +#! /bin/sh +bison -y "$@" @end example @end table @@ -6266,6 +6284,32 @@ the corresponding short option. @end example @end ifinfo +@node Yacc Library +@section Yacc Library + +The Yacc library contains default implementations of the +@code{yyerror} and @code{main} functions. These default +implementations are normally not useful, but @acronym{POSIX} requires +them. To use the Yacc library, link your program with the +@option{-ly} option. Note that Bison's implementation of the Yacc +library is distributed under the terms of the @acronym{GNU} General +Public License (@pxref{Copying}). + +If you use the Yacc library's @code{yyerror} function, you should +declare @code{yyerror} as follows: + +@example +int yyerror (char const *); +@end example + +Bison ignores the @code{int} value returned by this @code{yyerror}. +If you use the Yacc library's @code{main} function, your +@code{yyparse} function should have the following type signature: + +@example +int yyparse (void); +@end example + @c ================================================= Invoking Bison @node FAQ @@ -6377,8 +6421,8 @@ Macro to pretend that a syntax error has just been detected: call @end deffn @deffn {Macro} YYERROR_VERBOSE -An obsolete macro that you define with @code{#define} in the Bison -declarations section to request verbose, specific error message strings +An obsolete macro that you define with @code{#define} in the prologue +to request verbose, specific error message strings when @code{yyerror} is called. It doesn't matter what definition you use for @code{YYERROR_VERBOSE}, just whether you define it. Using @code{%error-verbose} is preferred.