Lines Matching full:bison
3 @setfilename bison.info
5 @settitle Bison @value{VERSION}
16 @c This feature is experimental and may change in future Bison versions.
33 This manual (@value{UPDATED}) is for GNU Bison (version
57 * bison: (bison). GNU parser generator (Yacc replacement).
61 @title Bison
63 @subtitle @value{UPDATED}, Bison Version @value{VERSION}
84 @top Bison
92 how you can copy and share Bison.
95 * Concepts:: Basic concepts for understanding Bison.
96 * Examples:: Three simple explained examples of using Bison.
99 * Grammar File:: Writing Bison declarations and rules.
101 * Algorithm:: How the Bison parser works at run-time.
104 messy for Bison to handle straightforwardly.
105 * Debugging:: Understanding or debugging Bison parsers.
106 * Invocation:: How to run Bison (to produce the parser implementation).
109 * Table of Symbols:: All the keywords of the Bison language are explained.
118 The Concepts of Bison
122 * Grammar in Bison:: How we represent grammars for Bison's sake.
129 * Bison Parser:: What are Bison's input and output,
131 * Stages:: Stages in writing and running Bison grammars.
132 * Grammar Layout:: Overall structure of a Bison grammar file.
160 * Rpcalc Generate:: Running Bison on the grammar file.
171 * Ltcalc Declarations:: Bison and C declarations for ltcalc.
177 * Mfcalc Declarations:: Bison declarations for multi-function calculator.
181 Bison Grammar Files
190 * Declarations:: All kinds of Bison declarations are described here.
191 * Multiple Parsers:: Putting more than one Bison parser in one program.
193 Outline of a Bison Grammar
197 * Bison Declarations:: Syntax and usage of the Bison declarations section.
223 Bison Declarations
225 * Require Decl:: Requiring a Bison version.
237 * Decl Summary:: Table of all Bison declarations.
238 * %define Summary:: Defining variables to adjust Bison's behavior.
266 The Bison Parser Algorithm
282 * Using Precedence:: How to specify precedence in Bison grammars.
314 Invoking Bison
316 * Bison Options:: All the options described in detail,
328 * C++ Bison Interface:: Asking for C++ parser generation
351 * Java Bison Interface:: Asking for Java parser generation
358 * Java Declarations Summary:: List of Bison declarations used with Java
367 * Secure? Conform?:: Is Bison POSIX safe?
368 * I can't build Bison:: Troubleshooting
373 * Mailing Lists:: Meeting other Bison users
386 @dfn{Bison} is a general-purpose parser generator that converts an
389 feature, Bison can also generate IELR(1) or canonical LR(1) parser
390 tables. Once you are proficient with Bison, you can use it to develop
394 Bison is upward compatible with Yacc: all properly-written Yacc
395 grammars ought to work with Bison with no change. Anyone familiar
396 with Yacc should be able to use Bison with little trouble. You need
397 to be fluent in C or C++ programming in order to use Bison or to
402 using Bison and show three explained examples, each building on the
403 last. If you don't know Bison or Yacc, start by reading these
405 of Bison in detail.
407 Bison was written originally by Robert Corbett. Richard Stallman made
410 Bison has grown more robust and evolved many other new features thanks
412 @file{THANKS} and @file{ChangeLog} files included in the Bison
415 This edition corresponds to version @value{VERSION} of Bison.
418 @unnumbered Conditions for Using Bison
420 The distribution terms for Bison-generated parsers permit using the
421 parsers in nonfree programs. Before Bison version 2.2, these extra
422 permissions applied only when Bison was generating LALR(1)
423 parsers in C@. And before Bison version 1.24, Bison-generated
429 software. The reason Bison was different was not due to a special
431 License to all of the Bison source code.
433 The main output of the Bison utility---the Bison parser implementation
434 file---contains a verbatim copy of a sizable piece of Bison, which is
439 the effect was to restrict the use of Bison output to free software.
443 concluded that limiting Bison's use to free software was doing little to
445 practical conditions for using Bison match the practical conditions for
448 This exception applies when Bison is generating code for a parser.
449 You can tell whether the exception applies to a Bison output file by
459 @chapter The Concepts of Bison
462 details of Bison will not make sense. If you do not already know how to
463 use Bison or Yacc, we suggest you start by reading this chapter carefully.
468 * Grammar in Bison:: How we represent grammars for Bison's sake.
475 * Bison Parser:: What are Bison's input and output,
477 * Stages:: Stages in writing and running Bison grammars.
478 * Grammar Layout:: Overall structure of a Bison grammar file.
486 In order for Bison to parse a language, it must be described by a
501 BNF is a context-free grammar. The input to Bison is
508 it can handle almost all context-free grammars, Bison is optimized for what
511 of lookahead. For historical reasons, Bison by default is limited by the
531 With the proper declarations, Bison is also able to parse these more
533 parsing (for Generalized LR). Bison's GLR parsers
606 The Bison parser reads a sequence of tokens as its input, and groups the
613 @node Grammar in Bison
614 @section From Formal Rules to Bison Input
615 @cindex Bison grammar
616 @cindex grammar, Bison
620 for Bison, you must write a file expressing the grammar in Bison syntax:
621 a @dfn{Bison grammar} file. @xref{Grammar File, ,Bison Grammar Files}.
623 A nonterminal symbol in the formal grammar is represented in Bison input
627 The Bison representation for a terminal symbol is also called a @dfn{token
644 The grammar rules also have an expression in Bison syntax. For example,
645 here is the Bison rule for a C @code{return} statement. The semicolon in
647 the statement; the naked semicolon, and the colon, are Bison punctuation
671 3989 as constants in the program! Therefore, each token in a Bison grammar
706 also produce some output based on the input. In a Bison grammar, a grammar
739 In some grammars, Bison's deterministic
751 @code{%glr-parser} among the Bison declarations in your file
753 (GLR) parser. These parsers handle Bison grammars that
771 reduction makes two parsers identical, causing them to merge, Bison
773 merge, reverting to the single-parser case, Bison resolves all the
879 and the current Bison parser even takes exponential time and space
888 Here is a Bison grammar corresponding to the example above. It
931 When used as a normal LR(1) grammar, Bison correctly complains
941 The parser can be turned into a GLR parser, while also telling Bison
943 these two declarations to the Bison grammar file (before the first
960 analyze the conflicts reported by Bison to make sure that GLR
1050 Bison detects this as a reduce/reduce conflict between the rules
1065 declarations specify that Bison is to give precedence
1085 However, at the time the Bison parser encounters @code{x}, it does not
1141 Bison requires that all of the
1153 This raises caveats for several Bison features you might use in a semantic
1178 future versions of Bison.
1185 Another Bison feature requiring special consideration is @code{YYERROR}
1235 Bison provides a mechanism for handling these locations.
1256 @node Bison Parser
1257 @section Bison Output: the Parser Implementation File
1258 @cindex Bison parser
1259 @cindex Bison utility
1263 When you run Bison, you give it a Bison grammar file as input. The
1266 @dfn{Bison parser}, and this file is called a @dfn{Bison parser
1267 implementation file}. Keep in mind that the Bison utility and the
1268 Bison parser are two distinct programs: the Bison utility is a program
1269 whose output is the Bison parser implementation file that becomes part
1272 The job of the Bison parser is to group tokens into groupings according to
1278 you must supply in some fashion (such as by writing it in C). The Bison
1282 parsing characters of text, but Bison does not depend on this.
1285 The Bison parser implementation file is C code which defines a
1296 write, all symbols defined in the Bison parser implementation file
1302 identifiers starting with @samp{yy} or @samp{YY} in the Bison grammar
1307 In some cases the Bison parser implementation file includes system
1318 @section Stages in Using Bison
1319 @cindex stages in using Bison
1320 @cindex using Bison
1322 The actual language-design process using Bison, from grammar specification
1327 Formally specify the grammar in a form recognized by Bison
1328 (@pxref{Grammar File, ,Bison Grammar Files}). For each grammatical rule
1340 Write a controlling function that calls the Bison-produced parser.
1351 Run Bison on the grammar to produce the parser.
1354 Compile the code output by Bison, as well as any other source files.
1361 @section The Overall Layout of a Bison Grammar
1365 @cindex layout of Bison grammar
1367 The input file for the Bison utility is a @dfn{Bison grammar file}. The
1368 general form of a Bison grammar file is as follows:
1375 @var{Bison declarations}
1385 in every Bison grammar file to separate the sections.
1394 The Bison declarations declare the names of the terminal and nonterminal
1410 Now we show and explain several sample programs written using Bison: a
1416 These examples are simple, but Bison grammars for real programming
1445 @samp{.y} extension is a convention used for Bison grammar files.
1453 * Rpcalc Generate:: Running Bison on the grammar file.
1460 Here are the C and Bison declarations for the reverse polish notation
1484 Bison parser will use whatever type @code{YYSTYPE} is defined as; if you
1498 The second section, Bison declarations, provides information to Bison
1499 about the token types (@pxref{Bison Declarations, ,The Bison
1552 You must specify these actions in C, but Bison provides the means for
1663 action, Bison by default copies the value of @code{$1} into @code{$$}.
1666 The formatting shown here is the recommended convention, but Bison does
1694 or sequences of characters into tokens. The Bison parser gets its
1706 represents a token type. The same text used in Bison rules to stand for
1711 token type is an identifier, that identifier is defined by Bison as a C
1716 global variable @code{yylval}, which is where the Bison parser will look
1722 (Bison recognizes any nonpositive value as indicating end-of-input.)
1809 After @code{yyerror} returns, the Bison parser may recover from the error
1817 @subsection Running Bison to Make the Parser
1818 @cindex running Bison (introduction)
1820 Before running Bison to produce a parser, we need to decide how to
1825 (@pxref{Grammar Layout, ,The Overall Layout of a Bison Grammar}).
1834 bison @var{file}.y
1839 ``Reverse Polish @sc{calc}ulator''). Bison produces a parser
1860 # @r{Compile the Bison parser.}
1899 parentheses nested to arbitrary depth. Here is the Bison code for
1916 /* Bison declarations. */
1960 In the second section (Bison declarations), @code{%left} declares token
1977 Bison that the rule @samp{| '-' exp} has the same precedence as
2005 The Bison language itself includes the reserved word @code{error}, which
2024 @code{yyerrok}, a macro defined automatically by Bison; its meaning is
2035 Bison programs.
2050 * Ltcalc Declarations:: Bison and C declarations for ltcalc.
2058 The C and Bison declarations for the location tracking calculator are
2071 /* Bison declarations. */
2161 Until now, we relied on Bison's defaults to enable location
2255 Now that the basics of Bison have been discussed, it is time to move on to
2296 * Mfcalc Declarations:: Bison declarations for multi-function calculator.
2304 Here are the C and Bison declarations for the multi-function calculator.
2336 The above grammar introduces only two new features of the Bison language.
2351 The Bison construct @code{%type} is used for declaring nonterminal
2408 grammar rules (except for the actions) or the Bison declarations, but it
2709 @chapter Bison Grammar Files
2711 Bison takes as input a context-free grammar specification and produces a
2714 The Bison grammar file conventionally has a name ending in @samp{.y}.
2715 @xref{Invocation, ,Invoking Bison}.
2725 * Declarations:: All kinds of Bison declarations are described here.
2726 * Multiple Parsers:: Putting more than one Bison parser in one program.
2730 @section Outline of a Bison Grammar
2735 A Bison grammar file has four main sections, shown here with the
2743 @var{Bison declarations}
2759 * Bison Declarations:: Syntax and usage of the Bison declarations section.
2783 @var{Bison declarations}. This allows you to have C and Bison
2811 Bison declarations, rather than after. For example, any definitions
2813 @code{_POSIX_C_SOURCE} should appear before all Bison declarations, as
2814 Bison-generated
2827 inflexible. As an alternative, Bison provides a @code{%code}
2829 purpose of the code and thus the location(s) where Bison should
2859 decide to override Bison's default definition for @code{YYLTYPE}, in
2861 You should write it in the first since Bison will insert that code
2866 prototype it in the second since Bison will insert that code
2927 implementation file. However, if you've instructed Bison to generate
2985 Now Bison will insert @code{#include "ptypes.h"} and the new
2986 @code{YYLTYPE} definition before the Bison-generated @code{YYSTYPE}
2994 @code{%code top} regardless of whether you instruct Bison to generate
2995 a parser header file. When you are writing code that you need Bison
2999 make the purpose of each block of your code explicit to Bison and to
3007 parser. Thus, you might wish for Bison to insert the prototype into
3067 Bison will insert the @code{trace_token} prototype into both the
3076 easier to read if you also follow this order, Bison does not require
3077 it. Instead, Bison lets you choose an organization that makes sense
3081 In that case, Bison concatenates the contained code in declaration order.
3122 code according to its purpose and let Bison handle the ordering.
3127 @node Bison Declarations
3128 @subsection The Bison Declarations Section
3129 @cindex Bison declarations (introduction)
3130 @cindex declarations, Bison (introduction)
3132 The @var{Bison declarations} section contains declarations that define
3135 @xref{Declarations, ,Bison Declarations}.
3142 The @dfn{grammar rules} section contains one or more Bison grammar
3169 The Bison parser itself contains many macros and identifiers whose names
3181 @dfn{Symbols} in Bison grammars represent the grammatical classifications
3187 represented in the Bison parser by a numeric code, and the @code{yylex}
3210 such name must be defined with a Bison declaration such as
3232 used in Bison as well, but you must not use the null character as a
3236 special meaning in Bison character literals, nor is backslash-newline
3259 type @code{"<="} to represent the string @samp{<=} as a token. Bison
3264 Bison as well, except that you must not use a null character within a
3266 meaning in Bison string literals, nor is backslash-newline allowed. A
3290 option when you run Bison, so that it will write these macro definitions
3292 in the other source files that need it. @xref{Invocation, ,Invoking Bison}.
3304 The @code{yylex} function and Bison must use a consistent character set
3305 and encoding for character tokens. For example, if you run Bison in an
3309 generated by Bison will assume ASCII numeric values for
3311 contain C source files that were generated by Bison in an
3328 A Bison grammar rule has the following general form:
3367 any sequence of C tokens, so long as its braces are balanced. Bison
3376 and not by a digraph. Bison does not look for trigraphs, so if braced
3430 appears also on its right hand side. Nearly all Bison grammars need to
3464 Right recursion uses up space on the Bison stack in proportion to the
3467 @xref{Algorithm, ,The Bison Parser Algorithm}, for further explanation
3534 Bison normally uses the type @code{int} for semantic values if your
3546 (@pxref{Grammar Outline, ,Outline of a Bison Grammar}).
3557 To use more than one data type for semantic values in one parser, Bison
3563 @code{%union} Bison declaration (@pxref{Union Decl, ,The Collection of
3571 @code{%token} Bison declaration (@pxref{Token Decl, ,Token Type Names})
3572 and for groupings with the @code{%type} Bison declaration (@pxref{Type
3602 Bison translates both of these constructs into expressions of the
3656 If you don't specify an action for a rule, Bison supplies a default:
3846 However, Bison currently provides no means to declare a destructor specific to
3879 this is what Bison actually does to implement mid-rule actions.
3887 rules and actions. The various reports generated by Bison (textual,
3930 final action does not use @code{$3}). Bison reports these errors when the
3932 Bison}):
3935 $ bison -fcaret -Wmidrule-value mid.y
4005 But this does not help, because Bison does not realize that the two actions
4006 are identical. (Bison never tries to understand the C code in an action.)
4024 which would in any case tell Bison which rule to use, can still do so.
4045 Now Bison can execute the action in the rule for @code{subroutine} without
4079 When @code{YYLTYPE} is not defined, Bison uses a default structure type with
4092 When @code{YYLTYPE} is not defined, at the beginning of the parsing, Bison
4343 C punctuation marks and operators. By default, Bison will read
4346 value. In order to force Bison to recognize @samp{name.suffix} in its
4354 @section Bison Declarations
4355 @cindex declarations, Bison
4356 @cindex Bison declarations
4358 The @dfn{Bison declarations} section of a Bison grammar defines the symbols
4373 * Require Decl:: Requiring a Bison version.
4385 * Decl Summary:: Table of all Bison declarations.
4386 * %define Summary:: Defining variables to adjust Bison's behavior.
4391 @subsection Require a Version of Bison
4393 @cindex requiring a version of Bison
4396 You may require the minimum version of Bison to process the grammar. If
4397 the requirement is not met, @command{bison} exits with an error (exit
4417 Bison will convert this into a @code{#define} directive in
4436 It is generally best, however, to let Bison choose the numeric codes for
4437 all token types. Bison will automatically select codes that don't conflict
4774 A Bison-generated parser invokes the default @code{%destructor}s only for
4775 user-defined as opposed to Bison-defined symbols.
4777 @code{%destructor} for the special Bison-defined symbols @code{$accept},
4778 @code{$undefined}, or @code{$end} (@pxref{Table of Symbols, ,Bison Symbols}),
4781 Symbols, ,error}), which is always defined by Bison regardless of whether you
4792 Finally, Bison will never invoke a @code{%destructor} for an unreferenced
4794 That is, Bison does not consider a mid-rule to have a semantic value if you
4798 Bison-generated parser will invoke the @code{<>} @code{%destructor} whenever
4911 Bison normally warns if there are any conflicts in the grammar
4926 Bison reports an error if the number of shift/reduce conflicts differs
4930 serious, and should be eliminated entirely. Bison will always report
4946 to get a verbose list of where the conflicts occur. Bison will also
4950 Check each of the conflicts to make sure that Bison's default
4956 number which Bison printed. With GLR parsers, add an
4960 Now Bison will report an error if you introduce an unexpected conflict,
4970 Bison assumes by default that the start symbol for the grammar is the first
4991 Normally, Bison generates a parser which is not reentrant. This is
4997 Alternatively, you can generate a pure, reentrant parser. The Bison
5037 Normally, Bison generates a pull parser.
5038 The following Bison declaration says that you want the parser to be a push
5061 When a push parser is selected, Bison will generate some new symbols in
5100 Bison also supports both the push parser interface along with the pull parser
5130 @subsection Bison Declaration Summary
5131 @cindex Bison declaration summary
5133 @cindex summary, Bison declaration
5188 In order to change the behavior of @command{bison}, use the following
5210 Define a variable to adjust Bison's behavior. @xref{%define Summary}.
5278 Specify a prefix to use for all Bison output file names. The names
5307 implementation file. Ordinarily Bison writes these commands in the
5321 Summary,,api.pure}), for which Bison is more careful to warn about
5326 Require version @var{version} or higher of Bison. @xref{Require Decl, ,
5327 Require a Version of Bison}.
5333 @c You probably don't need this option unless you are developing Bison.
5339 file in the Bison installation directory.
5348 the name of the token whose internal Bison token code number is
5355 the token in Bison. For single-character literals and literal
5357 escape sequences. For example, the Bison single-character literal
5359 @code{"'+'"}; and the Bison two-character literal string @code{"\\/"}
5363 When you specify @code{%token-table}, Bison also generates macro
5388 including its naming conventions. @xref{Bison Options}, for more.
5395 There are many features of Bison's behavior that can be controlled by
5413 multiple times, but see @ref{Bison Options,,-D
5420 Some @var{variable}s take Boolean values. In this case, Bison will
5433 In this case, Bison selects a default value.
5458 @item History: introduced in Bison 2.7
5475 @item History: introduced in Bison 2.6
5522 @item History: the @code{full} value was introduced in Bison 2.7
5571 @item Purpose: Request that Bison allow unreachable parser states to
5609 Bison uses @code{foo::bar} verbatim in references such as:
5615 However, to open a namespace, Bison removes any leading @code{::} and then
5673 supported by Bison. For a detailed discussion of how to use
5692 location(s) where Bison should insert it. That is, if you need to
5699 multiple occurrences of the @code{%code} directive, Bison concatenates
5716 directives, and it's the best place to override Bison's default @code{YYSTYPE}
5720 before the Bison-generated @code{YYSTYPE} and @code{YYLTYPE}
5734 file after the Bison-generated @code{YYSTYPE}, @code{YYLTYPE}, and
5775 of the standard Bison skeletons.
5781 Most programs that use Bison parse only one language and therefore contain
5782 only one Bison parser. But what if you want to parse more than one language
5794 @ref{Invocation, ,Invoking Bison}) renames the interface functions and
5795 variables of the Bison parser to start with @var{prefix} instead of
5861 Prior to Bison 2.6, a feature similar to @code{api.prefix} was provided by
5862 the obsolete directive @code{%name-prefix} (@pxref{Table of Symbols, ,Bison
5863 Symbols}) and the option @code{--name-prefix} (@pxref{Bison Options}).
5870 The Bison parser is actually a C function named @code{yyparse}. Here we
6064 the input stream and returns them to the parser. Bison does not create
6069 Bison grammar file. If @code{yylex} is defined in a separate source
6072 Bison, so that it will write these macro definitions into the separate
6075 Bison}.
6145 to Bison.
6182 yylval = value; /* Put value onto Bison stack. */
6210 yylval.intval = value; /* Put value onto Bison stack. */
6239 When you use the Bison declaration @code{%define api.pure full} to request a
6252 *lvalp = value; /* Put value onto Bison stack. */
6302 The Bison parser detects a @dfn{syntax error} or @dfn{parse error}
6308 The Bison parser expects to report the error by calling an error
6315 If you invoke the directive @code{%error-verbose} in the Bison declarations
6316 section (@pxref{Bison Declarations, ,The Bison Declarations Section}), then
6317 Bison provides a more verbose and specific error message string instead of
6323 nested. It isn't likely you will encounter this, since the Bison
6365 The prototypes are only indications of how the code produced by Bison
6366 uses @code{yyerror}. Bison-generated code always ignores the returned
6387 Here is a table of Bison constructs, variables and macros that
6540 @cindex bison-po
6542 A Bison-generated parser can print diagnostics, including error and
6543 tracing messages. By default, they appear in English. However, Bison
6552 The maintainer of a package that uses a Bison-generated parser enables
6559 @cindex bison-i18n.m4
6562 @file{bison-i18n.m4} file installed by Bison under
6563 @samp{share/aclocal/bison-i18n.m4} in Bison's installation directory.
6567 cp /usr/local/share/aclocal/bison-i18n.m4 m4/bison-i18n.m4
6576 defined in the file @file{bison-i18n.m4} that you copied earlier. It
6580 Bison-generated parser.
6584 containing Bison's runtime message catalog, through a call to
6585 @samp{bindtextdomain} with domain name @samp{bison-runtime}.
6589 bindtextdomain ("bison-runtime", BISON_LOCALEDIR);
6619 @chapter The Bison Parser Algorithm
6620 @cindex Bison parser algorithm
6627 As Bison reads tokens, it pushes them onto a stack along with their
6691 The Bison parser does @emph{not} always reduce immediately as soon as the
6778 called a @dfn{shift/reduce conflict}. Bison is designed to resolve
6806 else-clause to the innermost if-statement; this is what Bison accomplishes
6812 To avoid warnings from Bison about predictable, legitimate shift/reduce
6815 is exactly @var{n}, and Bison will report an error if there is a
6826 rules. Here is a complete Bison grammar file that actually manifests
6859 Bison declarations for operator precedence allow you to specify when to
6864 * Using Precedence:: How to specify precedence in Bison grammars.
6898 To decide which one Bison should do, we must consider the results. If
6924 Bison allows you to specify these choices with the operator precedence
6976 (@pxref{Invocation, ,Invoking Bison}) says how each conflict was
7012 Neither solution is perfect however. Since Bison does not provide, so far,
7033 The Bison precedence declarations, @code{%left}, @code{%right} and
7081 minus, Bison silently assumes that minus has its usual precedence.
7092 Then you will see any shift/reduce conflict until you tell Bison how
7174 Bison resolves a reduce/reduce conflict by choosing to use the rule that
7357 However, for historical reasons, Bison cannot by default handle all
7361 @code{return_spec}, are similar enough that Bison assumes they are the
7365 a @code{type}. Bison is unable to determine at that stage of processing
7379 details. (Bison's IELR(1) and canonical LR(1) implementations are
7430 The default behavior of Bison's LR-based parsers is chosen mostly for
7433 produced by LALR(1), Bison's default parser table construction algorithm.
7434 Another example is Bison's @code{%error-verbose} directive, which instructs
7438 In this section, we explore several modern features of Bison that allow you
7461 For historical reasons, Bison constructs LALR(1) parser tables by default.
7473 Fortunately, Bison provides an easy way to eliminate the possibility of such
7514 Bison:
7530 parser tables Bison can currently construct, so they may then be preferable.
7586 After parser table construction, Bison identifies the reduction with the
7588 parser state, traditional Bison behavior is to remove that lookahead set and
7604 Upon reaching a defaulted state, a Bison-generated parser does not bother to
7607 determines how soon a Bison-generated parser invokes @code{yylex} for a
7643 be fixed by another Bison feature, LAC. We discuss the effects of delayed
7647 For canonical LR, the only default reduction that Bison enables by default
7653 For LALR and IELR, Bison enables default reductions in nearly all states by
7659 versions of Bison might drop this exception when LAC is activated. Second,
7738 intuitive, so Bison currently provides no way to achieve the former behavior
7755 parsers generated by Bison can loop infinitely. LAC does not fix infinite
7762 Because of internationalization considerations, Bison-generated parsers
7794 some state @var{s}, then Bison considers @var{s} to be an @dfn{unreachable
7795 state}. A state can become unreachable during conflict resolution if Bison
7798 By default, Bison removes unreachable states from the parser after conflict
7804 Request that Bison allow unreachable states to remain in the parser tables.
7818 behavior will likely remain in future Bison releases.
7822 While Bison is able to remove unreachable states, it is not guaranteed to
7823 remove other kinds of useless states. Specifically, when Bison disables
7825 useless, and thus some additional states may become useless. If Bison were
7828 However, Bison does not compute which goto actions are useless.
7838 Bison produces @emph{deterministic} parsers that choose uniquely
7841 As a result, normal Bison handles a proper subset of the family of
7849 there are languages where Bison's default choice of how to
7853 Bison generates a parser that uses a different algorithm, called
7854 Generalized LR (or GLR). A Bison GLR
7856 algorithm for parsing as an ordinary Bison parser, but behaves
7865 a Bison GLR parsing stack is what is in effect a tree of states.
7890 Bison resolves and evaluates both and then calls the merge function on
7898 context-free grammar in cubic worst-case time. However, Bison currently
7908 deterministic LR(1) Bison parser.
7921 The Bison parser stack can run out of memory if too many tokens are shifted and
7925 Because Bison parsers have growing stacks, hitting the upper limit
7962 parsers in C produced by Bison cannot grow when compiled
7964 suggested to grow @code{YYINITDEPTH}. The Bison maintainers hope to fix
7989 handling. The Bison parser generates an @code{error} token whenever a
8014 But Bison can force the situation to fit the rule, by discarding part of
8022 this example, Bison reads and discards input until the next newline so
8093 The Bison paradigm is to parse tokens first, then group them into larger
8095 its context. Although this violates the Bison paradigm, certain techniques
8096 (known as @dfn{kludges}) may enable you to write Bison parsers for such
8120 name, then this is actually a declaration of @code{x}. How can a Bison
8158 As a result, part of the Bison parser for C needs to be duplicated, with
8197 which is set by Bison actions, whose purpose is to alter the way tokens are
8306 the algorithm (@pxref{Algorithm, ,The Bison Parser Algorithm}). This
8338 As documented elsewhere (@pxref{Algorithm, ,The Bison Parser Algorithm})
8339 Bison parsers are @dfn{shift/reduce automata}. In some cases (much more
8345 Bison}. Its name is made by removing @samp{.tab.c} or @samp{.c} from
8373 @command{bison} reports:
8422 Then Bison reproduces the exact grammar it used:
8467 Bison then proceeds onto the automaton itself, describing each state
8497 at the beginning of any rule deriving an @code{exp}. By default Bison
8499 you want to see more detail you can invoke @command{bison} with
8642 Because in deterministic parsing a single decision can be made, Bison
8658 @option{--report=lookahead}, Bison specifies these lookahead tokens:
8679 @option{--report=solved}, Bison includes information about the solved
8750 Bison may also produce an HTML version of this output, via an XML file and
8760 automaton corresponding to the Bison parser, a DOT file can be generated. Note
8768 (@pxref{Invocation, , Invoking Bison}). Its name is made by removing
8860 a single decision can be made, Bison can arbitrarily choose to disable a
8879 Bison supports two major report formats: textual output
8889 @command{bison} with options @option{--verbose} or @option{--graph}.
8892 @option{--xml[=FILE]} are specified, see @ref{Invocation,,Invoking Bison}.
8898 Bison ships with a @file{data/xslt} directory, containing XSL Transformation
8912 $ bison -x gr.y
8914 $ bison --print-datadir
8915 /usr/local/share/bison
8917 $ xsltproc /usr/local/share/bison/xslt/xml2xhtml.xsl gr.xml >gr.html
8928 When a Bison grammar compiles properly but parses ``incorrectly'', the
8957 @itemx the option @option{--debug} (Bison extension)
8958 Use the @samp{-t} option when you run Bison (@pxref{Invocation, ,Invoking
8959 Bison}). With @samp{%define api.prefix c}, it defines @code{CDEBUG} to 1,
8964 Add the @code{%debug} directive (@pxref{Decl Summary, ,Bison Declaration
8965 Summary}). This is a Bison extension, especially useful for languages that
9047 The @code{%define} directive instructs Bison to generate run-time trace
9227 @c ================================================= Invoking Bison
9230 @chapter Invoking Bison
9231 @cindex invoking Bison
9232 @cindex Bison invocation
9233 @cindex options for invoking Bison
9235 The usual way to invoke Bison is as follows:
9238 bison @var{infile}
9244 Thus, the @samp{bison foo.y} file name yields @file{foo.tab.c}, and
9245 the @samp{bison hack/foo.y} file name yields @file{foo.tab.c}. It's
9256 bison -d @var{infile.yxx}
9262 bison -d -o @var{output.c++} @var{infile.y}
9267 For compatibility with POSIX, the standard Bison
9269 invokes Bison with the @option{-y} option.
9272 * Bison Options:: All the options described in detail,
9278 @node Bison Options
9279 @section Bison Options
9281 Bison supports both traditional single-letter options and mnemonic long
9288 Here is a list of options that can be used with Bison, alphabetized by
9292 @c Please, keep this ordered as in `bison --help'.
9298 Print a summary of the command-line options to Bison and exit.
9302 Print the version number of Bison and exit.
9320 substitute for Yacc, and the Bison distribution contains such a script
9325 bison -y "$@@"
9329 traditional Yacc grammars. If your grammar uses a Bison extension
9330 like @samp{%glr-parser}, Bison might not be Yacc-compatible even if
9373 releases of Bison may move warnings from this category to new, more specific
9406 When invoked with @option{-fcaret}, Bison will report:
9454 (@pxref{%define Summary}) except that Bison processes multiple
9459 Bison quietly ignores all command-line definitions for @var{name} except
9463 @code{--define}, Bison reports an error for any @code{%define}
9467 @code{--force-define} instead, Bison quietly ignores all @code{%define}
9470 Otherwise, Bison reports an error if there are multiple @code{%define}
9481 @code{%language} was specified (@pxref{Decl Summary, , Bison Declaration
9497 implementation file. Ordinarily Bison puts them in the parser
9506 (@pxref{Decl Summary, , Bison Declaration Summary}).
9508 @c You probably don't need this option unless you are developing Bison.
9514 file in the Bison installation directory.
9541 for all Bison output file names. @xref{Decl Summary}.
9591 automaton computed by Bison, in @uref{http://www.graphviz.org/, Graphviz}
9599 Output an XML report of the parser's automaton computed by Bison.
9614 @headitem Long Option @tab Short Option @tab Bison Directive
9625 @option{-ly} option. Note that Bison's implementation of the Yacc
9636 Bison ignores the @code{int} value returned by this @code{yyerror}.
9644 @c ================================================= C++ Bison
9658 * C++ Bison Interface:: Asking for C++ parser generation
9666 @node C++ Bison Interface
9667 @subsection C++ Bison Interface
9677 When run, @command{bison} will create several entities in the @samp{yy}
9702 @option{-d}/@option{--defines} to @command{bison}, or use the
10006 ready to compile, in the directory @dfn{../bison/examples/calc++}. It
10007 focuses on the use of Bison, therefore the design of the various C++
10530 * Java Bison Interface:: Asking for Java parser generation
10537 * Java Declarations Summary:: List of Bison declarations used with Java
10540 @node Java Bison Interface
10541 @subsection Java Bison Interface
10551 When generating a Java parser, @code{bison @var{basename}.y} will
10622 implementation of Bison, and may change in future releases.
10630 (in a backwards-compatible way) in future versions of Bison.
10641 class defines a @dfn{position}, a single point in a file; Bison itself
10762 There are two possible ways to interface a Bison-generated Java parser
10905 opaque to the Bison grammar, and it might change in the future. The
10946 and may give an error in future versions of Bison.
10974 @xref{Java Bison Interface}.
11022 @xref{Java Bison Interface}.
11027 @xref{Java Bison Interface}.
11032 @xref{Java Bison Interface}.
11038 @xref{Java Bison Interface}.
11050 class by @command{bison}. Default is @code{Location}.
11057 @xref{Java Bison Interface}.
11063 @xref{Java Bison Interface}.
11075 @xref{Java Bison Interface}.
11085 @xref{Java Bison Interface}.
11102 Several questions about Bison come up occasionally. Here some of them
11111 * Secure? Conform?:: Is Bison POSIX safe?
11112 * I can't build Bison:: Troubleshooting
11117 * Mailing Lists:: Meeting other Bison users
11152 These problems typically come not from Bison itself, but from
11246 Bison lists, but is only concerned with a misunderstanding of the role
11266 /* Similar to using $1, $2 in a Bison action. */
11340 Bison does not support multiple start-symbols, but there is a very
11385 Is Bison secure? Does it conform to POSIX?
11389 However, Bison is intended to be a reliable program that conforms to the
11393 @node I can't build Bison
11394 @section I can't build Bison
11397 I can't build Bison because @command{make} complains that
11405 support is lacking. You can re-configure Bison with
11408 Bison. See the file @file{ABOUT-NLS} for more information.
11415 I'm having trouble using Bison. Where can I find help?
11419 @email{help-bison@@gnu.org}. This mailing list is intended to be
11421 and installing Bison. Please keep in mind that (most of) the people on
11422 the list have aspects of their lives which are not related to Bison (!),
11436 version. Check @url{ftp://ftp.gnu.org/pub/gnu/bison/} or one of its
11443 complete (i.e., I should be able to run it through Bison without having
11457 Send bug reports to @email{bug-bison@@gnu.org}.
11463 Will Bison ever have C++ and Java support? How about @var{insert your
11494 How do I join the help-bison and bug-bison mailing lists?
11502 @appendix Bison Symbols
11503 @cindex Bison symbols, table of
11504 @cindex symbols in Bison, table of
11516 In a grammar, the Bison-generated nonterminal symbol for a mid-rule action
11527 In a grammar, the Bison-generated nonterminal symbol for a mid-rule action
11549 Bison declarations section or the epilogue.
11550 @xref{Grammar Layout, ,The Overall Layout of a Bison Grammar}.
11557 the grammar file. @xref{Grammar Outline, ,Outline of a Bison
11630 Define a variable to adjust Bison's behavior. @xref{%define Summary}.
11634 Bison declaration to create a parser header file, which is usually
11649 Bison declaration to assign a precedence to a rule that is used at parse
11661 grammar rules so as to allow the Bison parser to recognize an error in
11671 Bison declaration to request verbose, specific error message strings
11676 Bison declaration to set the prefix of the output files. @xref{Decl
11681 Bison declaration to produce a GLR parser. @xref{GLR
11695 Bison declaration to assign left associativity to token(s).
11700 Bison declaration to specifying an additional parameter that
11706 Bison declaration to assign a merging function to a rule. If there is a
11740 Bison declaration to avoid generating @code{#line} directives in the
11745 Bison declaration to assign nonassociativity to token(s).
11750 Bison declaration to set the name of the parser implementation file.
11755 Bison declaration to specifying an additional parameter that
11761 Bison declaration to assign a precedence to a specific rule.
11767 Summary,,api.pure}), for which Bison is more careful to warn about
11772 Require version @var{version} or higher of Bison. @xref{Require Decl, ,
11773 Require a Version of Bison}.
11777 Bison declaration to assign right associativity to token(s).
11787 Bison declaration to specify the start symbol. @xref{Start Decl, ,The
11792 Bison declaration to declare token(s) without specifying precedence.
11797 Bison declaration to include a token name table in the parser
11802 Bison declaration to declare nonterminals. @xref{Type Decl,
11813 Bison declaration to specify several possible data types for semantic
11951 Global variable which Bison increments each time it reports a syntax error.
11958 The parser function produced by Bison; call this function to start
11969 The function to delete a parser instance, produced by Bison in push mode;
11978 The function to create a parser instance, produced by Bison in push mode;
11987 The parser function produced by Bison in push mode; call this function to
11996 The parser function produced by Bison in push mode; call this function to
12021 reserved for future Bison extensions. If not defined,
12028 @code{alloca} is called. You can inspect the code that Bison
12067 states, Bison declares the reduction with the largest lookahead set to be
12088 rules. @xref{Algorithm, ,The Bison Parser Algorithm}.
12092 that are not LR(1). It resolves situations that Bison's
12147 left to right. @xref{Algorithm, ,The Bison Parser Algorithm}.
12165 The class of context-free grammars that Bison (like most other parser
12189 nonterminal, according to a grammar rule. @xref{Algorithm, ,The Bison
12213 already-recognized rule. @xref{Algorithm, ,The Bison Parser Algorithm}.
12217 @xref{Grammar in Bison, ,From Formal Rules to Bison Input}.
12237 The input of the Bison parser is a stream of tokens which comes from