3 * Noteworthy changes in release ?.? (????-??-??) [?]
6 * Noteworthy changes in release 3.7.91 (2021-09-02) [beta]
8 Portability issues in the test suite and in C++ skeletons.
10 * Noteworthy changes in release 3.7.90 (2021-08-13) [beta]
12 ** Backward incompatible changes
14 In conformance with the recommendations of the Graphviz team
15 (https://marc.info/?l=graphviz-devel&m=129418103126092), `-g`/`--graph`
16 now generates a *.gv file by default, instead of *.dot. A transition
19 To comply with the latest POSIX standard, in Yacc compatibility mode
20 (options `-y`/`--yacc`) Bison now generates prototypes for yyerror and
21 yylex. In some situations, this is breaking compatibility: if the user
22 has already declared these functions but with some differences (e.g., to
23 declare them as static, or to use specific attributes), the generated
24 parser will fail to compile. To disable these prototypes, #define yyerror
25 (to `yyerror`), and likewise for yylex.
27 ** Deprecated features
29 Support for the YYPRINT macro is removed. It worked only with yacc.c and
30 only for tokens. It was obsoleted by %printer, introduced in Bison 1.50
33 It has always been recommended to prefer `%define api.value.type foo` to
34 `#define YYSTYPE foo`. The latter is supported in C for compatibility
35 with Yacc, but not in C++. Warnings are now issued if `#define YYSTYPE`
36 is used in C++, and eventually support will be removed.
38 In C++ code, prefer value_type to semantic_type to denote the semantic
39 value type, which is specified by the `api.value.type` %define variable.
43 *** A skeleton for the D programming language
45 The "lalr1.d" skeleton is now officially part of Bison.
47 It was originally contributed by Oliver Mangold, based on Paolo Bonzini's
48 lalr1.java, and was improved by H. S. Teoh. Adela Vais then took over
49 maintenance and invested a lot of efforts to complete, test and document
52 It now supports all the bells and whistles of the other deterministic
53 parsers, which include: pull/push interfaces, verbose and custom error
54 messages, lookahead correction, token constructors, internationalization,
55 locations, printers, token and symbol prefixes, etc.
57 Two examples demonstrate the D parsers: a basic one (examples/d/simple),
58 and an advanced one (examples/d/calc).
60 *** Option -H, --header and directive %header
62 The option `-H`/`--header` supersedes the option `--defines`, and the
63 directive %header supersedes %defines. Both `--defines` and `%defines`
64 are, of course, maintained for backward compatibility.
68 Since version 2.4 Bison can be used to generate HTML reports. However it
69 was a two-step process: first bison must be invoked with option `--xml`,
70 and then xsltproc must be run to the convert the XML reports into HTML.
72 The new option `--html` combines these steps. The xsltproc program must
75 *** A C++ native GLR parser
77 A new version of the C++ GLR parser was added: "glr2.cc". It generates
78 "true C++11", instead of a C++ wrapper around a C parser as does the
79 existing "glr.cc" parser. As a first significant consequence, it supports
80 `%define api.value.type variant`, contrary to glr.cc.
82 It should be upward compatible in terms of interface, feature and
83 performance to "glr.cc". To try it out, simply use
87 It will eventually replace "glr.cc". However we need user feedback on
88 this skeleton. _Please_ report your results and comments about it.
92 Counterexamples now show the rule numbers, and always show ε for rules
93 with an empty right-hand side. For instance
105 *** Lookahead correction in Java
107 The Java skeleton (lalr1.java) now supports LAC, via the `parse.lac`
110 *** Abort parsing for memory exhaustion (C)
112 User actions may now use `YYNOMEM` (similar to `YYACCEPT` and `YYABORT`)
113 to abort the current parse with memory exhaustion.
115 *** Printing locations in debug traces (C)
117 The `YYLOCATION_PRINT(File, Loc)` macro prints a location. It is defined
118 when (i) locations are enabled, (ii) the default type for locations is
119 used, (iii) debug traces are enabled, and (iv) `YYLOCATION_PRINT` is not
122 Users may define `YYLOCATION_PRINT` to cover other cases.
126 There were no debug traces for deferred calls to user actions. They are
130 * Noteworthy changes in release 3.7.6 (2021-03-08) [stable]
134 *** Reused Push Parsers
136 When a push-parser state structure is used for multiple parses, it was
137 possible for some state to leak from one run into the following one.
139 *** Fix Table Generation
141 In some very rare conditions, when there are many useless tokens, it was
142 possible to generate incorrect parsers.
145 * Noteworthy changes in release 3.7.5 (2021-01-24) [stable]
149 *** Counterexample Generation
151 In some cases counterexample generation could crash. This is fixed.
153 *** Fix Table Generation
155 In some very rare conditions, when there are many useless tokens, it was
156 possible to generate incorrect parsers.
158 *** GLR parsers now support %merge together with api.value.type=union.
160 *** C++ parsers use noexcept in more places.
162 *** Generated parsers avoid some warnings about signedness issues.
164 *** C-language parsers now avoid warnings from pedantic clang.
166 *** C-language parsers now work around quirks of HP-UX 11.23 (2003).
169 * Noteworthy changes in release 3.7.4 (2020-11-14) [stable]
173 *** Bug fixes in yacc.c
175 In Yacc mode, all the tokens are defined twice: once as an enum, and then
176 as a macro. YYEMPTY was missing its macro.
178 *** Bug fixes in lalr1.cc
180 The lalr1.cc skeleton used to emit internal assertions (using YY_ASSERT)
181 even when the `parse.assert` %define variable is not enabled. It no
184 The private internal macro YY_ASSERT now obeys the `api.prefix` %define
187 When there is a very large number of tokens, some assertions could be long
188 enough to hit arbitrary limits in Visual C++. They have been rewritten to
189 work around this limitation.
193 The YYBISON macro in generated "regular C parsers" (from the "yacc.c"
194 skeleton) used to be defined to 1. It is now defined to the version of
195 Bison as an integer (e.g., 30704 for version 3.7.4).
198 * Noteworthy changes in release 3.7.3 (2020-10-13) [stable]
202 Fix concurrent build issues.
204 The bison executable is no longer linked uselessly against libreadline.
206 Fix incorrect use of yytname in glr.cc.
209 * Noteworthy changes in release 3.7.2 (2020-09-05) [stable]
211 This release of Bison fixes all known bugs reported for Bison in MITRE's
212 Common Vulnerabilities and Exposures (CVE) system. These vulnerabilities
213 are only about bison-the-program itself, not the generated code.
215 Although these bugs are typically irrelevant to how Bison is used, they
216 are worth fixing if only to give users peace of mind.
218 There is no known vulnerability in the generated parsers.
222 Fix concurrent build issues (introduced in Bison 3.5).
224 Push parsers always use YYMALLOC/YYFREE (no direct calls to malloc/free).
226 Fix portability issues of the test suite, and of bison itself.
228 Some unlikely crashes found by fuzzing have been fixed. This is only
229 about bison itself, not the generated parsers.
232 * Noteworthy changes in release 3.7.1 (2020-08-02) [stable]
236 Crash when a token alias contains a NUL byte.
238 Portability issues with libtextstyle.
240 Portability issues of Bison itself with MSVC.
244 Improvements and fixes in the documentation.
246 More precise location about symbol type redefinitions.
249 * Noteworthy changes in release 3.7 (2020-07-23) [stable]
251 ** Deprecated features
253 The YYPRINT macro, which works only with yacc.c and only for tokens, was
254 obsoleted long ago by %printer, introduced in Bison 1.50 (November 2002).
255 It is deprecated and its support will be removed eventually.
257 In conformance with the recommendations of the Graphviz team, in the next
258 version Bison the option `--graph` will generate a *.gv file by default,
259 instead of *.dot. A transition started in Bison 3.4.
263 *** Counterexample Generation
265 Contributed by Vincent Imbimbo.
267 When given `-Wcounterexamples`/`-Wcex`, bison will now output
268 counterexamples for conflicts.
270 **** Unifying Counterexamples
272 Unifying counterexamples are strings which can be parsed in two ways due
273 to the conflict. For example on a grammar that contains the usual
274 "dangling else" ambiguity:
277 else.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
278 else.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
281 else.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
282 else.y: warning: shift/reduce conflict on token "else" [-Wcounterexamples]
283 Example: "if" exp "then" "if" exp "then" exp • "else" exp
286 ↳ "if" exp "then" exp
287 ↳ "if" exp "then" exp • "else" exp
288 Example: "if" exp "then" "if" exp "then" exp • "else" exp
291 ↳ "if" exp "then" exp "else" exp
292 ↳ "if" exp "then" exp •
294 When text styling is enabled, colors are used in the examples and the
295 derivations to highlight the structure of both analyses. In this case,
297 "if" exp "then" [ "if" exp "then" exp • ] "else" exp
301 "if" exp "then" [ "if" exp "then" exp • "else" exp ]
304 The counterexamples are "focused", in two different ways. First, they do
305 not clutter the output with all the derivations from the start symbol,
306 rather they start on the "conflicted nonterminal". They go straight to the
307 point. Second, they don't "expand" nonterminal symbols uselessly.
309 **** Nonunifying Counterexamples
311 In the case of the dangling else, Bison found an example that can be
312 parsed in two ways (therefore proving that the grammar is ambiguous).
313 When it cannot find such an example, it instead generates two examples
314 that are the same up until the dot:
317 foo.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
318 foo.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
319 foo.y:4.4-7: warning: rule useless in parser due to conflicts [-Wother]
324 foo.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
325 foo.y: warning: shift/reduce conflict on token ID [-Wcounterexamples]
326 First example: expr • ID ',' ID $end
333 Second example: expr • ID $end
339 foo.y:4.4-7: warning: rule useless in parser due to conflicts [-Wother]
343 In these cases, the parser usually doesn't have enough lookahead to
344 differentiate the two given examples.
348 Counterexamples are also included in the report when given
349 `--report=counterexamples`/`-rcex` (or `--report=all`), with more
354 1 exp: "if" exp "then" exp • [$end, "then", "else"]
355 2 | "if" exp "then" exp • "else" exp
357 "else" shift, and go to state 8
359 "else" [reduce using rule 1 (exp)]
360 $default reduce using rule 1 (exp)
362 shift/reduce conflict on token "else":
363 1 exp: "if" exp "then" exp •
364 2 exp: "if" exp "then" exp • "else" exp
365 Example: "if" exp "then" "if" exp "then" exp • "else" exp
368 ↳ "if" exp "then" exp
369 ↳ "if" exp "then" exp • "else" exp
370 Example: "if" exp "then" "if" exp "then" exp • "else" exp
373 ↳ "if" exp "then" exp "else" exp
374 ↳ "if" exp "then" exp •
376 *** File prefix mapping
378 Contributed by Joshua Watt.
380 Bison learned a new argument, `--file-prefix-map OLD=NEW`. Any file path
381 in the output (specifically `#line` directives and `#ifdef` header guards)
382 that begins with the prefix OLD will have it replaced with the prefix NEW,
383 similar to the `-ffile-prefix-map` in GCC. This option can be used to
384 make bison output reproducible.
390 When text styling is enabled and the terminal supports it, the warnings
391 now include hyperlinks to the documentation.
393 *** Relocatable installation
395 When installed to be relocatable (via `configure --enable-relocatable`),
396 bison will now also look for a relocated m4.
400 The `filename_type` %define variable was renamed `api.filename.type`.
403 %define filename_type "symbol"
407 %define api.filename.type {symbol}
409 (Or let `bison --update` do it for you).
411 It now defaults to `const std::string` instead of `std::string`.
413 *** Deprecated %define variable names
415 The following variables have been renamed for consistency. Backward
416 compatibility is ensured, but upgrading is recommended.
418 filename_type -> api.filename.type
419 package -> api.package
421 *** Push parsers no longer clear their state when parsing is finished
423 Previously push-parsers cleared their state when parsing was finished (on
424 success and on failure). This made it impossible to check if there were
425 parse errors, since `yynerrs` was also reset. This can be especially
426 troublesome when used in autocompletion, since a parser with error
427 recovery would suggest (irrelevant) expected tokens even if there were
430 Now the parser state can be examined when parsing is finished. The parser
431 state is reset when starting a new parse.
437 The bistromathic demonstrates %param and how to quote sources in the error
441 1.5-7: syntax error: expected end of file or + or - or * or / or ^ before number
447 *** Include the generated header (yacc.c)
449 Historically, when --defines was used, bison generated a header and pasted
450 an exact copy of it into the generated parser implementation file. Since
451 Bison 3.4 it is possible to specify that the header should be `#include`d,
452 and how. For instance
454 %define api.header.include {"parse.h"}
458 %define api.header.include {<parser/parse.h>}
460 Now api.header.include defaults to `"header-basename"`, as was intended in
461 Bison 3.4, where `header-basename` is the basename of the generated
462 header. This is disabled when the generated header is `y.tab.h`, to
463 comply with Automake's ylwrap.
465 *** String aliases are faithfully propagated
467 Bison used to interpret user strings (i.e., decoding backslash escapes)
468 when reading them, and to escape them (i.e., issue non-printable
469 characters as backslash escapes, taking the locale into account) when
470 outputting them. As a consequence non-ASCII strings (say in UTF-8) ended
471 up "ciphered" as sequences of backslash escapes. This happened not only
472 in the generated sources (where the compiler will reinterpret them), but
473 also in all the generated reports (text, xml, html, dot, etc.). Reports
474 were therefore not readable when string aliases were not pure ASCII.
475 Worse yet: the output depended on the user's locale.
477 Now Bison faithfully treats the string aliases exactly the way the user
478 spelled them. This fixes all the aforementioned problems. However, now,
479 string aliases semantically equivalent but syntactically different (e.g.,
480 "A", "\x41", "\101") are considered to be different.
482 *** Crash when generating IELR
484 An old, well hidden, bug in the generation of IELR parsers was fixed.
487 * Noteworthy changes in release 3.6.4 (2020-06-15) [stable]
491 In glr.cc some internal macros leaked in the user's code, and could damage
492 access to the token kinds.
495 * Noteworthy changes in release 3.6.3 (2020-06-03) [stable]
499 Incorrect comments in the generated parsers.
501 Warnings in push parsers (yacc.c).
503 Incorrect display of gotos in LAC traces (lalr1.cc).
506 * Noteworthy changes in release 3.6.2 (2020-05-17) [stable]
510 Some tests were fixed.
512 When token aliases contain comment delimiters:
514 %token FOO "/* foo */"
516 bison used to emit "nested" comments, which is invalid C.
519 * Noteworthy changes in release 3.6.1 (2020-05-10) [stable]
523 Restored ANSI-C compliance in yacc.c.
525 GNU readline portability issues.
527 In C++, yy::parser::symbol_name is now a public member, as was intended.
531 In C++, yy::parser::symbol_type now has a public name() member function.
534 * Noteworthy changes in release 3.6 (2020-05-08) [stable]
536 ** Backward incompatible changes
538 TL;DR: replace "#define YYERROR_VERBOSE 1" by "%define parse.error verbose".
540 The YYERROR_VERBOSE macro is no longer supported; the parsers that still
541 depend on it will now produce Yacc-like error messages (just "syntax
542 error"). It was superseded by the "%error-verbose" directive in Bison
543 1.875 (2003-01-01). Bison 2.6 (2012-07-19) clearly announced that support
544 for YYERROR_VERBOSE would be removed. Note that since Bison 3.0
545 (2013-07-25), "%error-verbose" is deprecated in favor of "%define
546 parse.error verbose".
548 ** Deprecated features
550 The YYPRINT macro, which works only with yacc.c and only for tokens, was
551 obsoleted long ago by %printer, introduced in Bison 1.50 (November 2002).
552 It is deprecated and its support will be removed eventually.
556 *** Improved syntax error messages
558 Two new values for the %define parse.error variable offer more control to
559 the user. Available in all the skeletons (C, C++, Java).
561 **** %define parse.error detailed
563 The behavior of "%define parse.error detailed" is closely resembling that
564 of "%define parse.error verbose" with a few exceptions. First, it is safe
565 to use non-ASCII characters in token aliases (with 'verbose', the result
566 depends on the locale with which bison was run). Second, a yysymbol_name
567 function is exposed to the user, instead of the yytnamerr function and the
568 yytname table. Third, token internationalization is supported (see
571 **** %define parse.error custom
573 With this directive, the user forges and emits the syntax error message
574 herself by defining the yyreport_syntax_error function. A new type,
575 yypcontext_t, captures the circumstances of the error, and provides the
576 user with functions to get details, such as yypcontext_expected_tokens to
577 get the list of expected token kinds.
579 A possible implementation of yyreport_syntax_error is:
582 yyreport_syntax_error (const yypcontext_t *ctx)
585 YY_LOCATION_PRINT (stderr, *yypcontext_location (ctx));
586 fprintf (stderr, ": syntax error");
587 // Report the tokens expected at this point.
589 enum { TOKENMAX = 10 };
590 yysymbol_kind_t expected[TOKENMAX];
591 int n = yypcontext_expected_tokens (ctx, expected, TOKENMAX);
593 // Forward errors to yyparse.
596 for (int i = 0; i < n; ++i)
597 fprintf (stderr, "%s %s",
598 i == 0 ? ": expected" : " or", yysymbol_name (expected[i]));
600 // Report the unexpected token.
602 yysymbol_kind_t lookahead = yypcontext_token (ctx);
603 if (lookahead != YYSYMBOL_YYEMPTY)
604 fprintf (stderr, " before %s", yysymbol_name (lookahead));
606 fprintf (stderr, "\n");
610 **** Token aliases internationalization
612 When the %define variable parse.error is set to `custom` or `detailed`,
613 one may specify which token aliases are to be translated using _(). For
625 In that case the user must define _() and N_(), and yysymbol_name returns
626 the translated symbol (i.e., it returns '_("variable")' rather that
627 '"variable"'). In Java, the user must provide an i18n() function.
629 *** List of expected tokens (yacc.c)
631 Push parsers may invoke yypstate_expected_tokens at any point during
632 parsing (including even before submitting the first token) to get the list
633 of possible tokens. This feature can be used to propose autocompletion
634 (see below the "bistromathic" example).
636 It makes little sense to use this feature without enabling LAC (lookahead
639 *** Returning the error token
641 When the scanner returns an invalid token or the undefined token
642 (YYUNDEF), the parser generates an error message and enters error
643 recovery. Because of that error message, most scanners that find lexical
644 errors generate an error message, and then ignore the invalid input
645 without entering the error-recovery.
647 The scanners may now return YYerror, the error token, to enter the
648 error-recovery mode without triggering an additional error message. See
649 the bistromathic for an example.
651 *** Deep overhaul of the symbol and token kinds
653 To avoid the confusion with types in programming languages, we now refer
654 to token and symbol "kinds" instead of token and symbol "types". The
655 documentation and error messages have been revised.
657 All the skeletons have been updated to use dedicated enum types rather
658 than integral types. Special symbols are now regular citizens, instead of
659 being declared in ad hoc ways.
663 The "token kind" is what is returned by the scanner, e.g., PLUS, NUMBER,
664 LPAREN, etc. While backward compatibility is of course ensured, users are
665 nonetheless invited to replace their uses of "enum yytokentype" by
668 This type now also includes tokens that were previously hidden: YYEOF (end
669 of input), YYUNDEF (undefined token), and YYerror (error token). They
670 now have string aliases, internationalized when internationalization is
671 enabled. Therefore, by default, error messages now refer to "end of file"
672 (internationalized) rather than the cryptic "$end", or to "invalid token"
673 rather than "$undefined".
675 Therefore in most cases it is now useless to define the end-of-line token
678 %token T_EOF 0 "end of file"
680 Rather simply use "YYEOF" in your scanner.
684 The "symbol kinds" is what the parser actually uses. (Unless the
685 api.token.raw %define variable is used, the symbol kind of a terminal
686 differs from the corresponding token kind.)
688 They are now exposed as a enum, "yysymbol_kind_t".
690 This allows users to tailor the error messages the way they want, or to
691 process some symbols in a specific way in autocompletion (see the
692 bistromathic example below).
694 *** Modernize display of explanatory statements in diagnostics
696 Since Bison 2.7, output was indented four spaces for explanatory
697 statements. For example:
699 input.y:2.7-13: error: %type redeclaration for exp
700 input.y:1.7-11: previous declaration
702 Since the introduction of caret-diagnostics, it became less clear. This
703 indentation has been removed and submessages are displayed similarly as in
706 input.y:2.7-13: error: %type redeclaration for exp
707 2 | %type <float> exp
709 input.y:1.7-11: note: previous declaration
713 Contributed by Victor Morales Cayuela.
717 The token and symbol kinds are yy::parser::token_kind_type and
718 yy::parser::symbol_kind_type.
720 The symbol_type::kind() member function allows to get the kind of a
721 symbol. This can be used to write unit tests for scanners, e.g.,
723 yy::parser::symbol_type t = make_NUMBER ("123");
724 assert (t.kind () == yy::parser::symbol_kind::S_NUMBER);
725 assert (t.value.as<int> () == 123);
731 In order to avoid ambiguities with "type" as in "typing", we now refer to
732 the "token kind" (e.g., `PLUS`, `NUMBER`, etc.) rather than the "token
733 type". We now also refer to the "symbol type" (e.g., `PLUS`, `expr`,
738 There are now examples/java: a very simple calculator, and a more complete
739 one (push-parser, location tracking, and debug traces).
741 The lexcalc example (a simple example in C based on Flex and Bison) now
742 also demonstrates location tracking.
745 A new C example, bistromathic, is a fully featured interactive calculator
746 using many Bison features: pure interface, push parser, autocompletion
747 based on the current parser state (using yypstate_expected_tokens),
748 location tracking, internationalized custom error messages, lookahead
749 correction, rich debug traces, etc.
751 It shows how to depend on the symbol kinds to tailor autocompletion. For
752 instance it recognizes the symbol kind "VARIABLE" to propose
753 autocompletion on the existing variables, rather than of the word
757 * Noteworthy changes in release 3.5.4 (2020-04-05) [stable]
759 ** WARNING: Future backward-incompatibilities!
761 TL;DR: replace "#define YYERROR_VERBOSE 1" by "%define parse.error verbose".
763 Bison 3.6 will no longer support the YYERROR_VERBOSE macro; the parsers
764 that still depend on it will produce Yacc-like error messages (just
765 "syntax error"). It was superseded by the "%error-verbose" directive in
766 Bison 1.875 (2003-01-01). Bison 2.6 (2012-07-19) clearly announced that
767 support for YYERROR_VERBOSE would be removed. Note that since Bison 3.0
768 (2013-07-25), "%error-verbose" is deprecated in favor of "%define
769 parse.error verbose".
773 Fix portability issues of the package itself on old compilers.
775 Fix api.token.raw support in Java.
778 * Noteworthy changes in release 3.5.3 (2020-03-08) [stable]
782 Error messages could quote lines containing zero-width characters (such as
783 \005) with incorrect styling. Fixes for similar issues with unexpectedly
784 short lines (e.g., the file was changed between parsing and diagnosing).
786 Some unlikely crashes found by fuzzing have been fixed. This is only
787 about bison itself, not the generated parsers.
790 * Noteworthy changes in release 3.5.2 (2020-02-13) [stable]
794 Portability issues and minor cosmetic issues.
796 The lalr1.cc skeleton properly rejects unsupported values for parse.lac
800 * Noteworthy changes in release 3.5.1 (2020-01-19) [stable]
806 Fix compiler warnings.
809 * Noteworthy changes in release 3.5 (2019-12-11) [stable]
811 ** Backward incompatible changes
813 Lone carriage-return characters (aka \r or ^M) in the grammar files are no
814 longer treated as end-of-lines. This changes the diagnostics, and in
815 particular their locations.
817 In C++, line numbers and columns are now represented as 'int' not
818 'unsigned', so that integer overflow on positions is easily checkable via
819 'gcc -fsanitize=undefined' and the like. This affects the API for
820 positions. The default position and location classes now expose
821 'counter_type' (int), used to define line and column numbers.
823 ** Deprecated features
825 The YYPRINT macro, which works only with yacc.c and only for tokens, was
826 obsoleted long ago by %printer, introduced in Bison 1.50 (November 2002).
827 It is deprecated and its support will be removed eventually.
831 *** Lookahead correction in C++
833 Contributed by Adrian Vogelsgesang.
835 The C++ deterministic skeleton (lalr1.cc) now supports LAC, via the
836 %define variable parse.lac.
838 *** Variable api.token.raw: Optimized token numbers (all skeletons)
840 In the generated parsers, tokens have two numbers: the "external" token
841 number as returned by yylex (which starts at 257), and the "internal"
842 symbol number (which starts at 3). Each time yylex is called, a table
843 lookup maps the external token number to the internal symbol number.
845 When the %define variable api.token.raw is set, tokens are assigned their
846 internal number, which saves one table lookup per token, and also saves
847 the generation of the mapping table.
849 The gain is typically moderate, but in extreme cases (very simple user
850 actions), a 10% improvement can be observed.
852 *** Generated parsers use better types for states
854 Stacks now use the best integral type for state numbers, instead of always
855 using 15 bits. As a result "small" parsers now have a smaller memory
856 footprint (they use 8 bits), and there is support for large automata (16
857 bits), and extra large (using int, i.e., typically 31 bits).
859 *** Generated parsers prefer signed integer types
861 Bison skeletons now prefer signed to unsigned integer types when either
862 will do, as the signed types are less error-prone and allow for better
863 checking with 'gcc -fsanitize=undefined'. Also, the types chosen are now
864 portable to unusual machines where char, short and int are all the same
865 width. On non-GNU platforms this may entail including <limits.h> and (if
866 available) <stdint.h> to define integer types and constants.
868 *** A skeleton for the D programming language
870 For the last few releases, Bison has shipped a stealth experimental
871 skeleton: lalr1.d. It was first contributed by Oliver Mangold, based on
872 Paolo Bonzini's lalr1.java, and was cleaned and improved thanks to
875 However, because nobody has committed to improving, testing, and
876 documenting this skeleton, it is not clear that it will be supported in
879 The lalr1.d skeleton *is functional*, and works well, as demonstrated in
880 examples/d/calc.d. Please try it, enjoy it, and... commit to support it.
882 *** Debug traces in Java
884 The Java backend no longer emits code and data for parser tracing if the
885 %define variable parse.trace is not defined.
889 *** New diagnostic: -Wdangling-alias
891 String literals, which allow for better error messages, are (too)
892 liberally accepted by Bison, which might result in silent errors. For
895 %type <exVal> cond "condition"
897 does not define "condition" as a string alias to 'cond' (nonterminal
898 symbols do not have string aliases). It is rather equivalent to
901 %token <exVal> "condition"
903 i.e., it gives the type 'exVal' to the "condition" token, which was
904 clearly not the intention.
906 Also, because string aliases need not be defined, typos such as "baz"
907 instead of "bar" will be not reported.
909 The option `-Wdangling-alias` catches these situations. On
912 %type <ival> foo "foo"
916 bison -Wdangling-alias reports
918 warning: string literal not attached to a symbol
919 | %type <ival> foo "foo"
921 warning: string literal not attached to a symbol
925 The `-Wall` option does not (yet?) include `-Wdangling-alias`.
927 *** Better POSIX Yacc compatibility diagnostics
929 POSIX Yacc restricts %type to nonterminals. This is now diagnosed by
933 %type <ival> TOKEN1 TOKEN2 't'
940 input.y:2.15-20: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
941 2 | %type <ival> TOKEN1 TOKEN2 't'
943 input.y:2.29-31: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
944 2 | %type <ival> TOKEN1 TOKEN2 't'
946 input.y:2.22-27: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
947 2 | %type <ival> TOKEN1 TOKEN2 't'
950 *** Diagnostics with insertion
952 The diagnostics now display the suggestion below the underlined source.
953 Replacement for undeclared symbols are now also suggested.
960 foo.y:2.7-9: error: symbol 'lis' is used, but is not defined as a token and has no rules; did you mean 'list'?
964 foo.y:2.16: warning: empty rule without %empty [-Wempty-rule]
968 foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
970 *** Diagnostics about long lines
972 Quoted sources may now be truncated to fit the screen. For instance, on a
973 30-column wide terminal:
980 foo.y:1.34-36: warning: symbol FOO redeclared [-Wother]
983 foo.y:1.8-10: previous declaration
986 foo.y:1.62-64: warning: symbol FOO redeclared [-Wother]
989 foo.y:1.8-10: previous declaration
995 *** Debugging glr.c and glr.cc
997 The glr.c skeleton always had asserts to check its own behavior (not the
998 user's). These assertions are now under the control of the parse.assert
999 %define variable (disabled by default).
1003 Several new compiler warnings in the generated output have been avoided.
1004 Some unused features are no longer emitted. Cleaner generated code in
1009 Portability issues in the test suite.
1011 In theory, parsers using %nonassoc could crash when reporting verbose
1012 error messages. This unlikely bug has been fixed.
1014 In Java, %define api.prefix was ignored. It now behaves as expected.
1017 * Noteworthy changes in release 3.4.2 (2019-09-12) [stable]
1021 In some cases, when warnings are disabled, bison could emit tons of white
1022 spaces as diagnostics.
1024 When running out of memory, bison could crash (found by fuzzing).
1026 When defining twice the EOF token, bison would crash.
1028 New warnings from recent compilers have been addressed in the generated
1029 parsers (yacc.c, glr.c, glr.cc).
1031 When lone carriage-return characters appeared in the input file,
1032 diagnostics could hang forever.
1035 * Noteworthy changes in release 3.4.1 (2019-05-22) [stable]
1042 * Noteworthy changes in release 3.4 (2019-05-19) [stable]
1044 ** Deprecated features
1046 The %pure-parser directive is deprecated in favor of '%define api.pure'
1047 since Bison 2.3b (2008-05-27), but no warning was issued; there is one
1048 now. Note that since Bison 2.7 you are strongly encouraged to use
1049 '%define api.pure full' instead of '%define api.pure'.
1053 *** Colored diagnostics
1055 As an experimental feature, diagnostics are now colored, controlled by the
1056 new options --color and --style.
1058 To use them, install the libtextstyle library before configuring Bison.
1059 It is available from
1061 https://alpha.gnu.org/gnu/gettext/
1065 https://alpha.gnu.org/gnu/gettext/libtextstyle-0.8.tar.gz
1067 The option --color supports the following arguments:
1068 - always, yes: Enable colors.
1069 - never, no: Disable colors.
1070 - auto, tty (default): Enable colors if the output device is a tty.
1072 To customize the styles, create a CSS file similar to
1076 .error { font-weight: 800; text-decoration: underline; }
1079 then invoke bison with --style=bison-bw.css, or set the BISON_STYLE
1080 environment variable to "bison-bw.css".
1082 *** Disabling output
1084 When given -fsyntax-only, the diagnostics are reported, but no output is
1087 The name of this option is somewhat misleading as bison does more than
1088 just checking the syntax: every stage is run (including checking for
1089 conflicts for instance), except the generation of the output files.
1091 *** Include the generated header (yacc.c)
1093 Before, when --defines is used, bison generated a header, and pasted an
1094 exact copy of it into the generated parser implementation file. If the
1095 header name is not "y.tab.h", it is now #included instead of being
1098 To use an '#include' even if the header name is "y.tab.h" (which is what
1099 happens with --yacc, or when using the Autotools' ylwrap), define
1100 api.header.include to the exact argument to pass to #include. For
1103 %define api.header.include {"parse.h"}
1107 %define api.header.include {<parser/parse.h>}
1109 *** api.location.type is now supported in C (yacc.c, glr.c)
1111 The %define variable api.location.type defines the name of the type to use
1112 for locations. When defined, Bison no longer defines YYLTYPE.
1114 This can be used in programs with several parsers to factor their
1115 definition of locations: let one of them generate them, and the others
1122 In conformance with the recommendations of the Graphviz team, if %require
1123 "3.4" (or better) is specified, the option --graph generates a *.gv file
1124 by default, instead of *.dot.
1126 *** Diagnostics overhaul
1128 Column numbers were wrong with multibyte characters, which would also
1129 result in skewed diagnostics with carets. Beside, because we were
1130 indenting the quoted source with a single space, lines with tab characters
1131 were incorrectly underlined.
1133 To address these issues, and to be clearer, Bison now issues diagnostics
1134 as GCC9 does. For instance it used to display (there's a tab before the
1137 foo.y:3.37-38: error: $2 of ‘expr’ has no declared type
1138 expr: expr '+' "number" { $$ = $1 + $2; }
1142 foo.y:3.37-38: error: $2 of ‘expr’ has no declared type
1143 3 | expr: expr '+' "number" { $$ = $1 + $2; }
1146 Other constructs now also have better locations, resulting in more precise
1149 *** Fix-it hints for %empty
1151 Running Bison with -Wempty-rules and --update will remove incorrect %empty
1152 annotations, and add the missing ones.
1154 *** Generated reports
1156 The format of the reports (parse.output) was improved for readability.
1158 *** Better support for --no-line.
1160 When --no-line is used, the generated files are now cleaner: no lines are
1161 generated instead of empty lines. Together with using api.header.include,
1162 that should help people saving the generated files into version control
1163 systems get smaller diffs.
1167 A new example in C shows an simple infix calculator with a hand-written
1168 scanner (examples/c/calc).
1170 A new example in C shows a reentrant parser (capable of recursive calls)
1171 built with Flex and Bison (examples/c/reccalc).
1173 There is a new section about the history of Yaccs and Bison.
1177 A few obscure bugs were fixed, including the second oldest (known) bug in
1178 Bison: it was there when Bison was entered in the RCS version control
1179 system, in December 1987. See the NEWS of Bison 3.3 for the previous
1183 * Noteworthy changes in release 3.3.2 (2019-02-03) [stable]
1187 Bison 3.3 failed to generate parsers for grammars with unused nonterminal
1191 * Noteworthy changes in release 3.3.1 (2019-01-27) [stable]
1195 The option -y/--yacc used to imply -Werror=yacc, which turns uses of Bison
1196 extensions into errors. It now makes them simple warnings (-Wyacc).
1199 * Noteworthy changes in release 3.3 (2019-01-26) [stable]
1201 A new mailing list was created, Bison Announce. It is low traffic, and is
1202 only about announcing new releases and important messages (e.g., polls
1203 about major decisions to make).
1205 https://lists.gnu.org/mailman/listinfo/bison-announce
1207 ** Backward incompatible changes
1209 Support for DJGPP, which has been unmaintained and untested for years, is
1212 ** Deprecated features
1214 A new feature, --update (see below) helps adjusting existing grammars to
1217 *** Deprecated directives
1219 The %error-verbose directive is deprecated in favor of '%define
1220 parse.error verbose' since Bison 3.0, but no warning was issued.
1222 The '%name-prefix "xx"' directive is deprecated in favor of '%define
1223 api.prefix {xx}' since Bison 3.0, but no warning was issued. These
1224 directives are slightly different, you might need to adjust your code.
1225 %name-prefix renames only symbols with external linkage, while api.prefix
1226 also renames types and macros, including YYDEBUG, YYTOKENTYPE,
1227 yytokentype, YYSTYPE, YYLTYPE, etc.
1229 Users of Flex that move from '%name-prefix "xx"' to '%define api.prefix
1230 {xx}' will typically have to update YY_DECL from
1232 #define YY_DECL int xxlex (YYSTYPE *yylval, YYLTYPE *yylloc)
1236 #define YY_DECL int xxlex (XXSTYPE *yylval, XXLTYPE *yylloc)
1238 *** Deprecated %define variable names
1240 The following variables, mostly related to parsers in Java, have been
1241 renamed for consistency. Backward compatibility is ensured, but upgrading
1244 abstract -> api.parser.abstract
1245 annotations -> api.parser.annotations
1246 extends -> api.parser.extends
1247 final -> api.parser.final
1248 implements -> api.parser.implements
1249 parser_class_name -> api.parser.class
1250 public -> api.parser.public
1251 strictfp -> api.parser.strictfp
1255 *** Generation of fix-its for IDEs/Editors
1257 When given the new option -ffixit (aka -fdiagnostics-parseable-fixits),
1258 bison now generates machine readable editing instructions to fix some
1259 issues. Currently, this is mostly limited to updating deprecated
1260 directives and removing duplicates. For instance:
1264 %define parser_class_name "Parser"
1265 %define api.parser.class "Parser"
1269 See the "fix-it:" lines below:
1271 $ bison -ffixit foo.y
1272 foo.y:1.1-14: warning: deprecated directive, use '%define parse.error verbose' [-Wdeprecated]
1275 fix-it:"foo.y":{1:1-1:15}:"%define parse.error verbose"
1276 foo.y:2.1-34: warning: deprecated directive, use '%define api.parser.class {Parser}' [-Wdeprecated]
1277 %define parser_class_name "Parser"
1278 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1279 fix-it:"foo.y":{2:1-2:35}:"%define api.parser.class {Parser}"
1280 foo.y:3.1-33: error: %define variable 'api.parser.class' redefined
1281 %define api.parser.class "Parser"
1282 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1283 foo.y:2.1-34: previous definition
1284 %define parser_class_name "Parser"
1285 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1286 fix-it:"foo.y":{3:1-3:34}:""
1287 foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
1289 This uses the same output format as GCC and Clang.
1291 *** Updating grammar files
1293 Fixes can be applied on the fly. The previous example ends with the
1294 suggestion to re-run bison with the option -u/--update, which results in a
1295 cleaner grammar file.
1297 $ bison --update foo.y
1299 bison: file 'foo.y' was updated (backup: 'foo.y~')
1302 %define parse.error verbose
1303 %define api.parser.class {Parser}
1307 *** Bison is now relocatable
1309 If you pass '--enable-relocatable' to 'configure', Bison is relocatable.
1311 A relocatable program can be moved or copied to a different location on
1312 the file system. It can also be used through mount points for network
1313 sharing. It is possible to make symbolic links to the installed and moved
1314 programs, and invoke them through the symbolic link.
1316 *** %expect and %expect-rr modifiers on individual rules
1318 One can now document (and check) which rules participate in shift/reduce
1319 and reduce/reduce conflicts. This is particularly important GLR parsers,
1320 where conflicts are a normal occurrence. For example,
1336 | argument_list ',' expression
1341 Looking at the output from -v, one can see that the shift/reduce conflict
1342 here is due to the fact that the parser does not know whether to reduce
1343 arguments to argument_list until it sees the token _after_ the following
1344 ','. By marking the rule with %expect 1 (because there is a conflict in
1345 one state), we document the source of the 1 overall shift/reduce conflict.
1347 In GLR parsers, we can use %expect-rr in a rule for reduce/reduce
1348 conflicts. In this case, we mark each of the conflicting rules. For
1357 target_list '=' expr ';'
1363 | target ',' target_list
1372 | expr ',' expr_list
1380 In a statement such as
1384 the parser must reduce x to a target or an expr, but does not know which
1385 until it sees the '='. So we notate the two possible reductions to
1386 indicate that each conflicts in one rule.
1388 This feature needs user feedback, and might evolve in the future.
1390 *** C++: Actual token constructors
1392 When variants and token constructors are enabled, in addition to the
1393 type-safe named token constructors (make_ID, make_INT, etc.), we now
1394 generate genuine constructors for symbol_type.
1396 For instance with these declarations
1402 you may use these constructors:
1404 symbol_type (int token, const std::string&);
1405 symbol_type (int token, const int&);
1406 symbol_type (int token);
1408 Correct matching between token types and value types is checked via
1409 'assert'; for instance, 'symbol_type (ID, 42)' would abort. Named
1410 constructors are preferable, as they offer better type safety (for
1411 instance 'make_ID (42)' would not even compile), but symbol_type
1412 constructors may help when token types are discovered at run-time, e.g.,
1415 if (auto i = lookup_keyword (yytext))
1416 return yy::parser::symbol_type (i);
1418 return yy::parser::make_ID (yytext);
1421 *** C++: Variadic emplace
1423 If your application requires C++11 and you don't use symbol constructors,
1424 you may now use a variadic emplace for semantic values:
1426 %define api.value.type variant
1427 %token <std::pair<int, int>> PAIR
1431 int yylex (parser::semantic_type *lvalp)
1433 lvalp->emplace <std::pair<int, int>> (1, 2);
1434 return parser::token::PAIR;
1437 *** C++: Syntax error exceptions in GLR
1439 The glr.cc skeleton now supports syntax_error exceptions thrown from user
1440 actions, or from the scanner.
1442 *** More POSIX Yacc compatibility warnings
1444 More Bison specific directives are now reported with -y or -Wyacc. This
1445 change was ready since the release of Bison 3.0 in September 2015. It was
1446 delayed because Autoconf used to define YACC as `bison -y`, which resulted
1447 in numerous warnings for Bison users that use the GNU Build System.
1449 If you still experience that problem, either redefine YACC as `bison -o
1450 y.tab.c`, or pass -Wno-yacc to Bison.
1452 *** The tables yyrhs and yyphrs are back
1454 Because no Bison skeleton uses them, these tables were removed (no longer
1455 passed to the skeletons, not even computed) in 2008. However, some users
1456 have expressed interest in being able to use them in their own skeletons.
1460 *** Incorrect number of reduce/reduce conflicts
1462 On a grammar such as
1464 exp: "num" | "num" | "num"
1466 bison used to report a single RR conflict, instead of two. This is now
1467 fixed. This was the oldest (known) bug in Bison: it was there when Bison
1468 was entered in the RCS version control system, in December 1987.
1470 Some grammar files might have to adjust their %expect-rr.
1472 *** Parser directives that were not careful enough
1474 Passing invalid arguments to %nterm, for instance character literals, used
1475 to result in unclear error messages.
1479 The examples/ directory (installed in .../share/doc/bison/examples) has
1480 been restructured per language for clarity. The examples come with a
1481 README and a Makefile. Not only can they be used to toy with Bison, they
1482 can also be starting points for your own grammars.
1484 There is now a Java example, and a simple example in C based on Flex and
1485 Bison (examples/c/lexcalc/).
1491 They now use noexcept and constexpr. Please, report missing annotations.
1493 *** Symbol Declarations
1495 The syntax of the variation directives to declare symbols was overhauled
1496 for more consistency, and also better POSIX Yacc compliance (which, for
1497 instance, allows "%type" without actually providing a type). The %nterm
1498 directive, supported by Bison since its inception, is now documented and
1499 officially supported.
1501 The syntax is now as follows:
1503 %token TAG? ( ID NUMBER? STRING? )+ ( TAG ( ID NUMBER? STRING? )+ )*
1504 %left TAG? ( ID NUMBER? )+ ( TAG ( ID NUMBER? )+ )*
1505 %type TAG? ( ID | CHAR | STRING )+ ( TAG ( ID | CHAR | STRING )+ )*
1506 %nterm TAG? ID+ ( TAG ID+ )*
1508 where TAG denotes a type tag such as ‘<ival>’, ID denotes an identifier
1509 such as ‘NUM’, NUMBER a decimal or hexadecimal integer such as ‘300’ or
1510 ‘0x12d’, CHAR a character literal such as ‘'+'’, and STRING a string
1511 literal such as ‘"number"’. The post-fix quantifiers are ‘?’ (zero or
1512 one), ‘*’ (zero or more) and ‘+’ (one or more).
1515 * Noteworthy changes in release 3.2.4 (2018-12-24) [stable]
1519 Fix the move constructor of symbol_type.
1521 Always provide a copy constructor for symbol_type, even in modern C++.
1524 * Noteworthy changes in release 3.2.3 (2018-12-18) [stable]
1528 Properly support token constructors in C++ with types that include commas
1529 (e.g., std::pair<int, int>). A regression introduced in Bison 3.2.
1532 * Noteworthy changes in release 3.2.2 (2018-11-21) [stable]
1536 C++ portability issues.
1539 * Noteworthy changes in release 3.2.1 (2018-11-09) [stable]
1543 Several portability issues have been fixed in the build system, in the
1544 test suite, and in the generated parsers in C++.
1547 * Noteworthy changes in release 3.2 (2018-10-29) [stable]
1549 ** Backward incompatible changes
1551 Support for DJGPP, which has been unmaintained and untested for years, is
1552 obsolete. Unless there is activity to revive it, it will be removed.
1556 %printers should use yyo rather than yyoutput to denote the output stream.
1558 Variant-based symbols in C++ should use emplace() rather than build().
1560 In C++ parsers, parser::operator() is now a synonym for the parser::parse.
1564 A new section, "A Simple C++ Example", is a tutorial for parsers in C++.
1566 A comment in the generated code now emphasizes that users should not
1567 depend upon non-documented implementation details, such as macros starting
1572 *** C++: Support for move semantics (lalr1.cc)
1574 The lalr1.cc skeleton now fully supports C++ move semantics, while
1575 maintaining compatibility with C++98. You may now store move-only types
1576 when using Bison's variants. For instance:
1583 %skeleton "lalr1.cc"
1584 %define api.value.type variant
1588 %token <int> INT "int";
1589 %type <std::unique_ptr<int>> int;
1590 %type <std::vector<std::unique_ptr<int>>> list;
1594 | list int { $$ = std::move($1); $$.emplace_back(std::move($2)); }
1596 int: "int" { $$ = std::make_unique<int>($1); }
1598 *** C++: Implicit move of right-hand side values (lalr1.cc)
1600 In modern C++ (C++11 and later), you should always use 'std::move' with
1601 the values of the right-hand side symbols ($1, $2, etc.), as they will be
1602 popped from the stack anyway. Using 'std::move' is mandatory for
1603 move-only types such as unique_ptr, and it provides a significant speedup
1604 for large types such as std::string, or std::vector, etc.
1606 If '%define api.value.automove' is set, every occurrence '$n' is replaced
1607 by 'std::move ($n)'. The second rule in the previous grammar can be
1610 list: list int { $$ = $1; $$.emplace_back($2); }
1612 With automove enabled, the semantic values are no longer lvalues, so do
1613 not use the swap idiom:
1615 list: list int { std::swap($$, $1); $$.emplace_back($2); }
1617 This idiom is anyway obsolete: it is preferable to move than to swap.
1619 A warning is issued when automove is enabled, and a value is used several
1622 input.yy:16.31-32: warning: multiple occurrences of $2 with api.value.automove enabled [-Wother]
1623 exp: "twice" exp { $$ = $2 + $2; }
1626 Enabling api.value.automove does not require support for modern C++. The
1627 generated code is valid C++98/03, but will use copies instead of moves.
1629 The new examples/c++/variant-11.yy shows these features in action.
1631 *** C++: The implicit default semantic action is always run
1633 When variants are enabled, the default action was not run, so
1641 It now behaves like in all the other cases, as
1643 exp: "number" { $$ = $1; }
1645 possibly using std::move if automove is enabled.
1647 We do not expect backward compatibility issues. However, beware of
1648 forward compatibility issues: if you rely on default actions with
1649 variants, be sure to '%require "3.2"' to avoid older versions of Bison to
1650 generate incorrect parsers.
1652 *** C++: Renaming location.hh
1654 When both %defines and %locations are enabled, Bison generates a
1655 location.hh file. If you don't use locations outside of the parser, you
1656 may avoid its creation with:
1658 %define api.location.file none
1660 However this file is useful if, for instance, your parser builds an AST
1661 decorated with locations: you may use Bison's location independently of
1662 Bison's parser. You can now give it another name, for instance:
1664 %define api.location.file "my-location.hh"
1666 This name can have directory components, and even be absolute. The name
1667 under which the location file is included is controlled by
1668 api.location.include.
1670 This way it is possible to have several parsers share the same location
1673 For instance, in src/foo/parser.hh, generate the include/ast/loc.hh file:
1676 %define api.namespace {foo}
1677 %define api.location.file "include/ast/loc.hh"
1678 %define api.location.include {<ast/loc.hh>}
1680 and use it in src/bar/parser.hh:
1683 %define api.namespace {bar}
1684 %code requires {#include <ast/loc.hh>}
1685 %define api.location.type {bar::location}
1687 Absolute file names are supported, so in your Makefile, passing the flag
1688 -Dapi.location.file='"$(top_srcdir)/include/ast/location.hh"' to bison is
1691 *** C++: stack.hh and position.hh are deprecated
1693 When asked to generate a header file (%defines), the lalr1.cc skeleton
1694 generates a stack.hh file. This file had no interest for users; it is now
1695 made useless: its content is included in the parser definition. It is
1696 still generated for backward compatibility.
1698 When in addition to %defines, location support is requested (%locations),
1699 the file position.hh is also generated. It is now also useless: its
1700 content is now included in location.hh.
1702 These files are no longer generated when your grammar file requires at
1703 least Bison 3.2 (%require "3.2").
1707 Portability issues on MinGW and VS2015.
1709 Portability issues in the test suite.
1711 Portability/warning issues with Flex.
1714 * Noteworthy changes in release 3.1 (2018-08-27) [stable]
1716 ** Backward incompatible changes
1718 Compiling Bison now requires a C99 compiler---as announced during the
1719 release of Bison 3.0, five years ago. Generated parsers do not require a
1722 Support for DJGPP, which has been unmaintained and untested for years, is
1723 obsolete. Unless there is activity to revive it, the next release of Bison
1724 will have it removed.
1728 *** Typed midrule actions
1730 Because their type is unknown to Bison, the values of midrule actions are
1731 not treated like the others: they don't have %printer and %destructor
1732 support. It also prevents C++ (Bison) variants to handle them properly.
1734 Typed midrule actions address these issues. Instead of:
1736 exp: { $<ival>$ = 1; } { $<ival>$ = 2; } { $$ = $<ival>1 + $<ival>2; }
1740 exp: <ival>{ $$ = 1; } <ival>{ $$ = 2; } { $$ = $1 + $2; }
1742 *** Reports include the type of the symbols
1744 The sections about terminal and nonterminal symbols of the '*.output' file
1745 now specify their declared type. For instance, for:
1749 the report now shows '<ival>':
1751 Terminals, with rules where they appear
1755 *** Diagnostics about useless rules
1757 In the following grammar, the 'exp' nonterminal is trivially useless. So,
1758 of course, its rules are useless too.
1762 exp: exp '+' exp | exp '-' exp | '(' exp ')'
1764 Previously all the useless rules were reported, including those whose
1765 left-hand side is the 'exp' nonterminal:
1767 warning: 1 nonterminal useless in grammar [-Wother]
1768 warning: 4 rules useless in grammar [-Wother]
1769 2.14-16: warning: nonterminal useless in grammar: exp [-Wother]
1772 2.14-16: warning: rule useless in grammar [-Wother]
1775 3.6-16: warning: rule useless in grammar [-Wother]
1776 exp: exp '+' exp | exp '-' exp | '(' exp ')'
1778 3.20-30: warning: rule useless in grammar [-Wother]
1779 exp: exp '+' exp | exp '-' exp | '(' exp ')'
1781 3.34-44: warning: rule useless in grammar [-Wother]
1782 exp: exp '+' exp | exp '-' exp | '(' exp ')'
1785 Now, rules whose left-hand side symbol is useless are no longer reported
1786 as useless. The locations of the errors have also been adjusted to point
1787 to the first use of the nonterminal as a left-hand side of a rule:
1789 warning: 1 nonterminal useless in grammar [-Wother]
1790 warning: 4 rules useless in grammar [-Wother]
1791 3.1-3: warning: nonterminal useless in grammar: exp [-Wother]
1792 exp: exp '+' exp | exp '-' exp | '(' exp ')'
1794 2.14-16: warning: rule useless in grammar [-Wother]
1798 *** C++: Generated parsers can be compiled with -fno-exceptions (lalr1.cc)
1800 When compiled with exceptions disabled, the generated parsers no longer
1801 uses try/catch clauses.
1803 Currently only GCC and Clang are supported.
1807 *** A demonstration of variants
1809 A new example was added (installed in .../share/doc/bison/examples),
1810 'variant.yy', which shows how to use (Bison) variants in C++.
1812 The other examples were made nicer to read.
1814 *** Some features are no longer 'experimental'
1816 The following features, mature enough, are no longer flagged as
1817 experimental in the documentation: push parsers, default %printer and
1818 %destructor (typed: <*> and untyped: <>), %define api.value.type union and
1819 variant, Java parsers, XML output, LR family (lr, ielr, lalr), and
1820 semantic predicates (%?).
1824 *** GLR: Predicates support broken by #line directives
1826 Predicates (%?) in GLR such as
1829 %? {new_syntax} 'w' id new_args
1830 | %?{!new_syntax} 'w' id old_args
1832 were issued with #lines in the middle of C code.
1834 *** Printer and destructor with broken #line directives
1836 The #line directives were not properly escaped when emitting the code for
1837 %printer/%destructor, which resulted in compiler errors if there are
1838 backslashes or double-quotes in the grammar file name.
1840 *** Portability on ICC
1842 The Intel compiler claims compatibility with GCC, yet rejects its _Pragma.
1843 Generated parsers now work around this.
1847 There were several small fixes in the test suite and in the build system,
1848 many warnings in bison and in the generated parsers were eliminated. The
1849 documentation also received its share of minor improvements.
1851 Useless code was removed from C++ parsers, and some of the generated
1852 constructors are more 'natural'.
1855 * Noteworthy changes in release 3.0.5 (2018-05-27) [stable]
1859 *** C++: Fix support of 'syntax_error'
1861 One incorrect 'inline' resulted in linking errors about the constructor of
1862 the syntax_error exception.
1864 *** C++: Fix warnings
1866 GCC 7.3 (with -O1 or -O2 but not -O0 or -O3) issued null-dereference
1867 warnings about yyformat being possibly null. It also warned about the
1868 deprecated implicit definition of copy constructors when there's a
1869 user-defined (copy) assignment operator.
1871 *** Location of errors
1873 In C++ parsers, out-of-bounds errors can happen when a rule with an empty
1874 ride-hand side raises a syntax error. The behavior of the default parser
1875 (yacc.c) in such a condition was undefined.
1877 Now all the parsers match the behavior of glr.c: @$ is used as the
1878 location of the error. This handles gracefully rules with and without
1881 *** Portability fixes in the test suite
1883 On some platforms, some Java and/or C++ tests were failing.
1886 * Noteworthy changes in release 3.0.4 (2015-01-23) [stable]
1890 *** C++ with Variants (lalr1.cc)
1892 Fix a compiler warning when no %destructor use $$.
1896 Several portability issues in tests were fixed.
1899 * Noteworthy changes in release 3.0.3 (2015-01-15) [stable]
1903 *** C++ with Variants (lalr1.cc)
1905 Problems with %destructor and '%define parse.assert' have been fixed.
1907 *** Named %union support (yacc.c, glr.c)
1909 Bison 3.0 introduced a regression on named %union such as
1911 %union foo { int ival; };
1913 The possibility to use a name was introduced "for Yacc compatibility".
1914 It is however not required by POSIX Yacc, and its usefulness is not clear.
1916 *** %define api.value.type union with %defines (yacc.c, glr.c)
1918 The C parsers were broken when %defines was used together with "%define
1919 api.value.type union".
1921 *** Redeclarations are reported in proper order
1929 bison used to report:
1931 foo.yy:2.10-11: error: %printer redeclaration for FOO
1934 foo.yy:3.10-11: previous declaration
1938 Now, the "previous" declaration is always the first one.
1943 Bison now installs various files in its docdir (which defaults to
1944 '/usr/local/share/doc/bison'), including the three fully blown examples
1945 extracted from the documentation:
1948 Reverse Polish Calculator, a simple introductory example.
1950 Multi-function Calc, a calculator with memory and functions and located
1953 a calculator in C++ using variant support and token constructors.
1956 * Noteworthy changes in release 3.0.2 (2013-12-05) [stable]
1960 *** Generated source files when errors are reported
1962 When warnings are issued and -Werror is set, bison would still generate
1963 the source files (*.c, *.h...). As a consequence, some runs of "make"
1964 could fail the first time, but not the second (as the files were generated
1967 This is fixed: bison no longer generates this source files, but, of
1968 course, still produces the various reports (*.output, *.xml, etc.).
1970 *** %empty is used in reports
1972 Empty right-hand sides are denoted by '%empty' in all the reports (text,
1973 dot, XML and formats derived from it).
1975 *** YYERROR and variants
1977 When C++ variant support is enabled, an error triggered via YYERROR, but
1978 not caught via error recovery, resulted in a double deletion.
1981 * Noteworthy changes in release 3.0.1 (2013-11-12) [stable]
1985 *** Errors in caret diagnostics
1987 On some platforms, some errors could result in endless diagnostics.
1989 *** Fixes of the -Werror option
1991 Options such as "-Werror -Wno-error=foo" were still turning "foo"
1992 diagnostics into errors instead of warnings. This is fixed.
1994 Actually, for consistency with GCC, "-Wno-error=foo -Werror" now also
1995 leaves "foo" diagnostics as warnings. Similarly, with "-Werror=foo
1996 -Wno-error", "foo" diagnostics are now errors.
2000 As demonstrated in the documentation, one can now leave spaces between
2005 The yacc.1 man page is no longer installed if --disable-yacc was
2008 *** Fixes in the test suite
2010 Bugs and portability issues.
2013 * Noteworthy changes in release 3.0 (2013-07-25) [stable]
2015 ** WARNING: Future backward-incompatibilities!
2017 Like other GNU packages, Bison will start using some of the C99 features
2018 for its own code, especially the definition of variables after statements.
2019 The generated C parsers still aim at C90.
2021 ** Backward incompatible changes
2023 *** Obsolete features
2025 Support for YYFAIL is removed (deprecated in Bison 2.4.2): use YYERROR.
2027 Support for yystype and yyltype is removed (deprecated in Bison 1.875):
2028 use YYSTYPE and YYLTYPE.
2030 Support for YYLEX_PARAM and YYPARSE_PARAM is removed (deprecated in Bison
2031 1.875): use %lex-param, %parse-param, or %param.
2033 Missing semicolons at the end of actions are no longer added (as announced
2034 in the release 2.5).
2036 *** Use of YACC='bison -y'
2038 TL;DR: With Autoconf <= 2.69, pass -Wno-yacc to (AM_)YFLAGS if you use
2041 Traditional Yacc generates 'y.tab.c' whatever the name of the input file.
2042 Therefore Makefiles written for Yacc expect 'y.tab.c' (and possibly
2043 'y.tab.h' and 'y.output') to be generated from 'foo.y'.
2045 To this end, for ages, AC_PROG_YACC, Autoconf's macro to look for an
2046 implementation of Yacc, was using Bison as 'bison -y'. While it does
2047 ensure compatible output file names, it also enables warnings for
2048 incompatibilities with POSIX Yacc. In other words, 'bison -y' triggers
2049 warnings for Bison extensions.
2051 Autoconf 2.70+ fixes this incompatibility by using YACC='bison -o y.tab.c'
2052 (which also generates 'y.tab.h' and 'y.output' when needed).
2053 Alternatively, disable Yacc warnings by passing '-Wno-yacc' to your Yacc
2054 flags (YFLAGS, or AM_YFLAGS with Automake).
2058 *** The epilogue is no longer affected by internal #defines (glr.c)
2060 The glr.c skeleton uses defines such as #define yylval (yystackp->yyval) in
2061 generated code. These weren't properly undefined before the inclusion of
2062 the user epilogue, so functions such as the following were butchered by the
2063 preprocessor expansion:
2065 int yylex (YYSTYPE *yylval);
2067 This is fixed: yylval, yynerrs, yychar, and yylloc are now valid
2068 identifiers for user-provided variables.
2070 *** stdio.h is no longer needed when locations are enabled (yacc.c)
2072 Changes in Bison 2.7 introduced a dependency on FILE and fprintf when
2073 locations are enabled. This is fixed.
2075 *** Warnings about useless %pure-parser/%define api.pure are restored
2077 ** Diagnostics reported by Bison
2079 Most of these features were contributed by Théophile Ranquet and Victor
2084 Version 2.7 introduced caret errors, for a prettier output. These are now
2085 activated by default. The old format can still be used by invoking Bison
2086 with -fno-caret (or -fnone).
2088 Some error messages that reproduced excerpts of the grammar are now using
2089 the caret information only. For instance on:
2096 in.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
2097 in.y:2.12-14: warning: rule useless in parser due to conflicts: exp: 'a' [-Wother]
2101 in.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
2102 in.y:2.12-14: warning: rule useless in parser due to conflicts [-Wother]
2106 and "bison -fno-caret" reports:
2108 in.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
2109 in.y:2.12-14: warning: rule useless in parser due to conflicts [-Wother]
2111 *** Enhancements of the -Werror option
2113 The -Werror=CATEGORY option is now recognized, and will treat specified
2114 warnings as errors. The warnings need not have been explicitly activated
2115 using the -W option, this is similar to what GCC 4.7 does.
2117 For example, given the following command line, Bison will treat both
2118 warnings related to POSIX Yacc incompatibilities and S/R conflicts as
2119 errors (and only those):
2121 $ bison -Werror=yacc,error=conflicts-sr input.y
2123 If no categories are specified, -Werror will make all active warnings into
2124 errors. For example, the following line does the same the previous example:
2126 $ bison -Werror -Wnone -Wyacc -Wconflicts-sr input.y
2128 (By default -Wconflicts-sr,conflicts-rr,deprecated,other is enabled.)
2130 Note that the categories in this -Werror option may not be prefixed with
2131 "no-". However, -Wno-error[=CATEGORY] is valid.
2133 Note that -y enables -Werror=yacc. Therefore it is now possible to require
2134 Yacc-like behavior (e.g., always generate y.tab.c), but to report
2135 incompatibilities as warnings: "-y -Wno-error=yacc".
2137 *** The display of warnings is now richer
2139 The option that controls a given warning is now displayed:
2141 foo.y:4.6: warning: type clash on default action: <foo> != <bar> [-Wother]
2143 In the case of warnings treated as errors, the prefix is changed from
2144 "warning: " to "error: ", and the suffix is displayed, in a manner similar
2145 to GCC, as [-Werror=CATEGORY].
2147 For instance, where the previous version of Bison would report (and exit
2150 bison: warnings being treated as errors
2151 input.y:1.1: warning: stray ',' treated as white space
2155 input.y:1.1: error: stray ',' treated as white space [-Werror=other]
2157 *** Deprecated constructs
2159 The new 'deprecated' warning category flags obsolete constructs whose
2160 support will be discontinued. It is enabled by default. These warnings
2161 used to be reported as 'other' warnings.
2163 *** Useless semantic types
2165 Bison now warns about useless (uninhabited) semantic types. Since
2166 semantic types are not declared to Bison (they are defined in the opaque
2167 %union structure), it is %printer/%destructor directives about useless
2168 types that trigger the warning:
2172 %printer {} <type1> <type3>
2173 %destructor {} <type2> <type4>
2175 nterm: term { $$ = $1; };
2177 3.28-34: warning: type <type3> is used, but is not associated to any symbol
2178 4.28-34: warning: type <type4> is used, but is not associated to any symbol
2180 *** Undefined but unused symbols
2182 Bison used to raise an error for undefined symbols that are not used in
2183 the grammar. This is now only a warning.
2186 %destructor {} symbol2
2187 %type <type> symbol3
2191 *** Useless destructors or printers
2193 Bison now warns about useless destructors or printers. In the following
2194 example, the printer for <type1>, and the destructor for <type2> are
2195 useless: all symbols of <type1> (token1) already have a printer, and all
2196 symbols of type <type2> (token2) already have a destructor.
2198 %token <type1> token1
2202 %printer {} token1 <type1> <type3>
2203 %destructor {} token2 <type2> <type4>
2207 The warnings and error messages about shift/reduce and reduce/reduce
2208 conflicts have been normalized. For instance on the following foo.y file:
2212 exp: exp '+' exp | '0' | '0';
2214 compare the previous version of bison:
2217 foo.y: conflicts: 1 shift/reduce, 2 reduce/reduce
2218 $ bison -Werror foo.y
2219 bison: warnings being treated as errors
2220 foo.y: conflicts: 1 shift/reduce, 2 reduce/reduce
2222 with the new behavior:
2225 foo.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
2226 foo.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
2227 $ bison -Werror foo.y
2228 foo.y: error: 1 shift/reduce conflict [-Werror=conflicts-sr]
2229 foo.y: error: 2 reduce/reduce conflicts [-Werror=conflicts-rr]
2231 When %expect or %expect-rr is used, such as with bar.y:
2236 exp: exp '+' exp | '0' | '0';
2241 bar.y: conflicts: 1 shift/reduce, 2 reduce/reduce
2242 bar.y: expected 0 shift/reduce conflicts
2243 bar.y: expected 0 reduce/reduce conflicts
2248 bar.y: error: shift/reduce conflicts: 1 found, 0 expected
2249 bar.y: error: reduce/reduce conflicts: 2 found, 0 expected
2251 ** Incompatibilities with POSIX Yacc
2253 The 'yacc' category is no longer part of '-Wall', enable it explicitly
2256 ** Additional yylex/yyparse arguments
2258 The new directive %param declares additional arguments to both yylex and
2259 yyparse. The %lex-param, %parse-param, and %param directives support one
2260 or more arguments. Instead of
2262 %lex-param {arg1_type *arg1}
2263 %lex-param {arg2_type *arg2}
2264 %parse-param {arg1_type *arg1}
2265 %parse-param {arg2_type *arg2}
2269 %param {arg1_type *arg1} {arg2_type *arg2}
2271 ** Types of values for %define variables
2273 Bison used to make no difference between '%define foo bar' and '%define
2274 foo "bar"'. The former is now called a 'keyword value', and the latter a
2275 'string value'. A third kind was added: 'code values', such as '%define
2278 Keyword variables are used for fixed value sets, e.g.,
2280 %define lr.type lalr
2282 Code variables are used for value in the target language, e.g.,
2284 %define api.value.type {struct semantic_type}
2286 String variables are used remaining cases, e.g. file names.
2288 ** Variable api.token.prefix
2290 The variable api.token.prefix changes the way tokens are identified in
2291 the generated files. This is especially useful to avoid collisions
2292 with identifiers in the target language. For instance
2294 %token FILE for ERROR
2295 %define api.token.prefix {TOK_}
2297 start: FILE for ERROR;
2299 will generate the definition of the symbols TOK_FILE, TOK_for, and
2300 TOK_ERROR in the generated sources. In particular, the scanner must
2301 use these prefixed token names, although the grammar itself still
2302 uses the short names (as in the sample rule given above).
2304 ** Variable api.value.type
2306 This new %define variable supersedes the #define macro YYSTYPE. The use
2307 of YYSTYPE is discouraged. In particular, #defining YYSTYPE *and* either
2308 using %union or %defining api.value.type results in undefined behavior.
2310 Either define api.value.type, or use "%union":
2317 %token <ival> INT "integer"
2318 %token <sval> STRING "string"
2319 %printer { fprintf (yyo, "%d", $$); } <ival>
2320 %destructor { free ($$); } <sval>
2323 yylval.ival = 42; return INT;
2324 yylval.sval = "42"; return STRING;
2326 The %define variable api.value.type supports both keyword and code values.
2328 The keyword value 'union' means that the user provides genuine types, not
2329 union member names such as "ival" and "sval" above (WARNING: will fail if
2330 -y/--yacc/%yacc is enabled).
2332 %define api.value.type union
2333 %token <int> INT "integer"
2334 %token <char *> STRING "string"
2335 %printer { fprintf (yyo, "%d", $$); } <int>
2336 %destructor { free ($$); } <char *>
2339 yylval.INT = 42; return INT;
2340 yylval.STRING = "42"; return STRING;
2342 The keyword value variant is somewhat equivalent, but for C++ special
2343 provision is made to allow classes to be used (more about this below).
2345 %define api.value.type variant
2346 %token <int> INT "integer"
2347 %token <std::string> STRING "string"
2349 Code values (in braces) denote user defined types. This is where YYSTYPE
2367 %define api.value.type {struct my_value}
2368 %token <u.ival> INT "integer"
2369 %token <u.sval> STRING "string"
2370 %printer { fprintf (yyo, "%d", $$); } <u.ival>
2371 %destructor { free ($$); } <u.sval>
2374 yylval.u.ival = 42; return INT;
2375 yylval.u.sval = "42"; return STRING;
2377 ** Variable parse.error
2379 This variable controls the verbosity of error messages. The use of the
2380 %error-verbose directive is deprecated in favor of "%define parse.error
2383 ** Deprecated %define variable names
2385 The following variables have been renamed for consistency. Backward
2386 compatibility is ensured, but upgrading is recommended.
2388 lr.default-reductions -> lr.default-reduction
2389 lr.keep-unreachable-states -> lr.keep-unreachable-state
2390 namespace -> api.namespace
2391 stype -> api.value.type
2393 ** Semantic predicates
2395 Contributed by Paul Hilfinger.
2397 The new, experimental, semantic-predicate feature allows actions of the
2398 form "%?{ BOOLEAN-EXPRESSION }", which cause syntax errors (as for
2399 YYERROR) if the expression evaluates to 0, and are evaluated immediately
2400 in GLR parsers, rather than being deferred. The result is that they allow
2401 the programmer to prune possible parses based on the values of run-time
2404 ** The directive %expect-rr is now an error in non GLR mode
2406 It used to be an error only if used in non GLR mode, _and_ if there are
2407 reduce/reduce conflicts.
2409 ** Tokens are numbered in their order of appearance
2411 Contributed by Valentin Tolmer.
2413 With '%token A B', A had a number less than the one of B. However,
2414 precedence declarations used to generate a reversed order. This is now
2415 fixed, and introducing tokens with any of %token, %left, %right,
2416 %precedence, or %nonassoc yields the same result.
2418 When mixing declarations of tokens with a literal character (e.g., 'a') or
2419 with an identifier (e.g., B) in a precedence declaration, Bison numbered
2420 the literal characters first. For example
2424 would lead to the tokens declared in this order: 'c' 'd' A B. Again, the
2425 input order is now preserved.
2427 These changes were made so that one can remove useless precedence and
2428 associativity declarations (i.e., map %nonassoc, %left or %right to
2429 %precedence, or to %token) and get exactly the same output.
2431 ** Useless precedence and associativity
2433 Contributed by Valentin Tolmer.
2435 When developing and maintaining a grammar, useless associativity and
2436 precedence directives are common. They can be a nuisance: new ambiguities
2437 arising are sometimes masked because their conflicts are resolved due to
2438 the extra precedence or associativity information. Furthermore, it can
2439 hinder the comprehension of a new grammar: one will wonder about the role
2440 of a precedence, where in fact it is useless. The following changes aim
2441 at detecting and reporting these extra directives.
2443 *** Precedence warning category
2445 A new category of warning, -Wprecedence, was introduced. It flags the
2446 useless precedence and associativity directives.
2448 *** Useless associativity
2450 Bison now warns about symbols with a declared associativity that is never
2451 used to resolve conflicts. In that case, using %precedence is sufficient;
2452 the parsing tables will remain unchanged. Solving these warnings may raise
2453 useless precedence warnings, as the symbols no longer have associativity.
2467 warning: useless associativity for '+', use %precedence [-Wprecedence]
2471 *** Useless precedence
2473 Bison now warns about symbols with a declared precedence and no declared
2474 associativity (i.e., declared with %precedence), and whose precedence is
2475 never used. In that case, the symbol can be safely declared with %token
2476 instead, without modifying the parsing tables. For example:
2480 exp: "var" '=' "number";
2484 warning: useless precedence for '=' [-Wprecedence]
2488 *** Useless precedence and associativity
2490 In case of both useless precedence and associativity, the issue is flagged
2495 exp: "var" '=' "number";
2499 warning: useless precedence and associativity for '=' [-Wprecedence]
2505 With help from Joel E. Denny and Gabriel Rassoul.
2507 Empty rules (i.e., with an empty right-hand side) can now be explicitly
2508 marked by the new %empty directive. Using %empty on a non-empty rule is
2509 an error. The new -Wempty-rule warning reports empty rules without
2510 %empty. On the following grammar:
2520 3.4-5: warning: empty rule without %empty [-Wempty-rule]
2523 5.8-13: error: %empty on non-empty rule
2527 ** Java skeleton improvements
2529 The constants for token names were moved to the Lexer interface. Also, it
2530 is possible to add code to the parser's constructors using "%code init"
2531 and "%define init_throws".
2532 Contributed by Paolo Bonzini.
2534 The Java skeleton now supports push parsing.
2535 Contributed by Dennis Heimbigner.
2537 ** C++ skeletons improvements
2539 *** The parser header is no longer mandatory (lalr1.cc, glr.cc)
2541 Using %defines is now optional. Without it, the needed support classes
2542 are defined in the generated parser, instead of additional files (such as
2543 location.hh, position.hh and stack.hh).
2545 *** Locations are no longer mandatory (lalr1.cc, glr.cc)
2547 Both lalr1.cc and glr.cc no longer require %location.
2549 *** syntax_error exception (lalr1.cc)
2551 The C++ parser features a syntax_error exception, which can be
2552 thrown from the scanner or from user rules to raise syntax errors.
2553 This facilitates reporting errors caught in sub-functions (e.g.,
2554 rejecting too large integral literals from a conversion function
2555 used by the scanner, or rejecting invalid combinations from a
2556 factory invoked by the user actions).
2558 *** %define api.value.type variant
2560 This is based on a submission from Michiel De Wilde. With help
2561 from Théophile Ranquet.
2563 In this mode, complex C++ objects can be used as semantic values. For
2566 %token <::std::string> TEXT;
2567 %token <int> NUMBER;
2568 %token SEMICOLON ";"
2569 %type <::std::string> item;
2570 %type <::std::list<std::string>> list;
2573 list { std::cout << $1 << std::endl; }
2577 %empty { /* Generates an empty string list. */ }
2578 | list item ";" { std::swap ($$, $1); $$.push_back ($2); }
2582 TEXT { std::swap ($$, $1); }
2583 | NUMBER { $$ = string_cast ($1); }
2586 *** %define api.token.constructor
2588 When variants are enabled, Bison can generate functions to build the
2589 tokens. This guarantees that the token type (e.g., NUMBER) is consistent
2590 with the semantic value (e.g., int):
2592 parser::symbol_type yylex ()
2594 parser::location_type loc = ...;
2596 return parser::make_TEXT ("Hello, world!", loc);
2598 return parser::make_NUMBER (42, loc);
2600 return parser::make_SEMICOLON (loc);
2606 There are operator- and operator-= for 'location'. Negative line/column
2607 increments can no longer underflow the resulting value.
2610 * Noteworthy changes in release 2.7.1 (2013-04-15) [stable]
2614 *** Fix compiler attribute portability (yacc.c)
2616 With locations enabled, __attribute__ was used unprotected.
2618 *** Fix some compiler warnings (lalr1.cc)
2621 * Noteworthy changes in release 2.7 (2012-12-12) [stable]
2625 Warnings about uninitialized yylloc in yyparse have been fixed.
2627 Restored C90 compliance (yet no report was ever made).
2629 ** Diagnostics are improved
2631 Contributed by Théophile Ranquet.
2633 *** Changes in the format of error messages
2635 This used to be the format of many error reports:
2637 input.y:2.7-12: %type redeclaration for exp
2638 input.y:1.7-12: previous declaration
2642 input.y:2.7-12: error: %type redeclaration for exp
2643 input.y:1.7-12: previous declaration
2645 *** New format for error reports: carets
2647 Caret errors have been added to Bison:
2649 input.y:2.7-12: error: %type redeclaration for exp
2652 input.y:1.7-12: previous declaration
2658 input.y:3.20-23: error: ambiguous reference: '$exp'
2659 exp: exp '+' exp { $exp = $1 + $3; };
2661 input.y:3.1-3: refers to: $exp at $$
2662 exp: exp '+' exp { $exp = $1 + $3; };
2664 input.y:3.6-8: refers to: $exp at $1
2665 exp: exp '+' exp { $exp = $1 + $3; };
2667 input.y:3.14-16: refers to: $exp at $3
2668 exp: exp '+' exp { $exp = $1 + $3; };
2671 The default behavior for now is still not to display these unless
2672 explicitly asked with -fcaret (or -fall). However, in a later release, it
2673 will be made the default behavior (but may still be deactivated with
2676 ** New value for %define variable: api.pure full
2678 The %define variable api.pure requests a pure (reentrant) parser. However,
2679 for historical reasons, using it in a location-tracking Yacc parser
2680 resulted in a yyerror function that did not take a location as a
2681 parameter. With this new value, the user may request a better pure parser,
2682 where yyerror does take a location as a parameter (in location-tracking
2685 The use of "%define api.pure true" is deprecated in favor of this new
2686 "%define api.pure full".
2688 ** New %define variable: api.location.type (glr.cc, lalr1.cc, lalr1.java)
2690 The %define variable api.location.type defines the name of the type to use
2691 for locations. When defined, Bison no longer generates the position.hh
2692 and location.hh files, nor does the parser will include them: the user is
2693 then responsible to define her type.
2695 This can be used in programs with several parsers to factor their location
2696 and position files: let one of them generate them, and the others just use
2699 This feature was actually introduced, but not documented, in Bison 2.5,
2700 under the name "location_type" (which is maintained for backward
2703 For consistency, lalr1.java's %define variables location_type and
2704 position_type are deprecated in favor of api.location.type and
2707 ** Exception safety (lalr1.cc)
2709 The parse function now catches exceptions, uses the %destructors to
2710 release memory (the lookahead symbol and the symbols pushed on the stack)
2711 before re-throwing the exception.
2713 This feature is somewhat experimental. User feedback would be
2716 ** Graph improvements in DOT and XSLT
2718 Contributed by Théophile Ranquet.
2720 The graphical presentation of the states is more readable: their shape is
2721 now rectangular, the state number is clearly displayed, and the items are
2722 numbered and left-justified.
2724 The reductions are now explicitly represented as transitions to other
2725 diamond shaped nodes.
2727 These changes are present in both --graph output and xml2dot.xsl XSLT
2728 processing, with minor (documented) differences.
2730 ** %language is no longer an experimental feature.
2732 The introduction of this feature, in 2.4, was four years ago. The
2733 --language option and the %language directive are no longer experimental.
2737 The sections about shift/reduce and reduce/reduce conflicts resolution
2738 have been fixed and extended.
2740 Although introduced more than four years ago, XML and Graphviz reports
2741 were not properly documented.
2743 The translation of midrule actions is now described.
2746 * Noteworthy changes in release 2.6.5 (2012-11-07) [stable]
2748 We consider compiler warnings about Bison generated parsers to be bugs.
2749 Rather than working around them in your own project, please consider
2750 reporting them to us.
2754 Warnings about uninitialized yylval and/or yylloc for push parsers with a
2755 pure interface have been fixed for GCC 4.0 up to 4.8, and Clang 2.9 to
2758 Other issues in the test suite have been addressed.
2760 Null characters are correctly displayed in error messages.
2762 When possible, yylloc is correctly initialized before calling yylex. It
2763 is no longer necessary to initialize it in the %initial-action.
2766 * Noteworthy changes in release 2.6.4 (2012-10-23) [stable]
2768 Bison 2.6.3's --version was incorrect. This release fixes this issue.
2771 * Noteworthy changes in release 2.6.3 (2012-10-22) [stable]
2775 Bugs and portability issues in the test suite have been fixed.
2777 Some errors in translations have been addressed, and --help now directs
2778 users to the appropriate place to report them.
2780 Stray Info files shipped by accident are removed.
2782 Incorrect definitions of YY_, issued by yacc.c when no parser header is
2783 generated, are removed.
2785 All the generated headers are self-contained.
2787 ** Header guards (yacc.c, glr.c, glr.cc)
2789 In order to avoid collisions, the header guards are now
2790 YY_<PREFIX>_<FILE>_INCLUDED, instead of merely <PREFIX>_<FILE>.
2791 For instance the header generated from
2793 %define api.prefix "calc"
2794 %defines "lib/parse.h"
2796 will use YY_CALC_LIB_PARSE_H_INCLUDED as guard.
2798 ** Fix compiler warnings in the generated parser (yacc.c, glr.c)
2800 The compilation of pure parsers (%define api.pure) can trigger GCC
2803 input.c: In function 'yyparse':
2804 input.c:1503:12: warning: 'yylval' may be used uninitialized in this
2805 function [-Wmaybe-uninitialized]
2809 This is now fixed; pragmas to avoid these warnings are no longer needed.
2811 Warnings from clang ("equality comparison with extraneous parentheses" and
2812 "function declared 'noreturn' should not return") have also been
2816 * Noteworthy changes in release 2.6.2 (2012-08-03) [stable]
2820 Buffer overruns, complaints from Flex, and portability issues in the test
2821 suite have been fixed.
2823 ** Spaces in %lex- and %parse-param (lalr1.cc, glr.cc)
2825 Trailing end-of-lines in %parse-param or %lex-param would result in
2826 invalid C++. This is fixed.
2828 ** Spurious spaces and end-of-lines
2830 The generated files no longer end (nor start) with empty lines.
2833 * Noteworthy changes in release 2.6.1 (2012-07-30) [stable]
2835 Bison no longer executes user-specified M4 code when processing a grammar.
2839 In addition to the removal of the features announced in Bison 2.6, the
2840 next major release will remove the "Temporary hack for adding a semicolon
2841 to the user action", as announced in the release 2.5. Instead of:
2843 exp: exp "+" exp { $$ = $1 + $3 };
2847 exp: exp "+" exp { $$ = $1 + $3; };
2851 *** Type names are now properly escaped.
2853 *** glr.cc: set_debug_level and debug_level work as expected.
2855 *** Stray @ or $ in actions
2857 While Bison used to warn about stray $ or @ in action rules, it did not
2858 for other actions such as printers, destructors, or initial actions. It
2861 ** Type names in actions
2863 For consistency with rule actions, it is now possible to qualify $$ by a
2864 type-name in destructors, printers, and initial actions. For instance:
2866 %printer { fprintf (yyo, "(%d, %f)", $<ival>$, $<fval>$); } <*> <>;
2868 will display two values for each typed and untyped symbol (provided
2869 that YYSTYPE has both "ival" and "fval" fields).
2872 * Noteworthy changes in release 2.6 (2012-07-19) [stable]
2876 The next major release of Bison will drop support for the following
2877 deprecated features. Please report disagreements to bug-bison@gnu.org.
2881 Support for generating parsers in K&R C will be removed. Parsers
2882 generated for C support ISO C90, and are tested with ISO C99 and ISO C11
2885 *** Features deprecated since Bison 1.875
2887 The definitions of yystype and yyltype will be removed; use YYSTYPE and
2890 YYPARSE_PARAM and YYLEX_PARAM, deprecated in favor of %parse-param and
2891 %lex-param, will no longer be supported.
2893 Support for the preprocessor symbol YYERROR_VERBOSE will be removed, use
2896 *** The generated header will be included (yacc.c)
2898 Instead of duplicating the content of the generated header (definition of
2899 YYSTYPE, yyparse declaration etc.), the generated parser will include it,
2900 as is already the case for GLR or C++ parsers. This change is deferred
2901 because existing versions of ylwrap (e.g., Automake 1.12.1) do not support
2904 ** Generated Parser Headers
2906 *** Guards (yacc.c, glr.c, glr.cc)
2908 The generated headers are now guarded, as is already the case for C++
2909 parsers (lalr1.cc). For instance, with --defines=foo.h:
2914 #endif /* !YY_FOO_H */
2916 *** New declarations (yacc.c, glr.c)
2918 The generated header now declares yydebug and yyparse. Both honor
2919 --name-prefix=bar_, and yield
2921 int bar_parse (void);
2925 #define yyparse bar_parse
2928 in order to facilitate the inclusion of several parser headers inside a
2929 single compilation unit.
2931 *** Exported symbols in C++
2933 The symbols YYTOKEN_TABLE and YYERROR_VERBOSE, which were defined in the
2934 header, are removed, as they prevent the possibility of including several
2935 generated headers from a single compilation unit.
2939 For the same reasons, the undocumented and unused macro YYLSP_NEEDED is no
2942 ** New %define variable: api.prefix
2944 Now that the generated headers are more complete and properly protected
2945 against multiple inclusions, constant names, such as YYSTYPE are a
2946 problem. While yyparse and others are properly renamed by %name-prefix,
2947 YYSTYPE, YYDEBUG and others have never been affected by it. Because it
2948 would introduce backward compatibility issues in projects not expecting
2949 YYSTYPE to be renamed, instead of changing the behavior of %name-prefix,
2950 it is deprecated in favor of a new %define variable: api.prefix.
2952 The following examples compares both:
2954 %name-prefix "bar_" | %define api.prefix "bar_"
2955 %token <ival> FOO %token <ival> FOO
2956 %union { int ival; } %union { int ival; }
2962 #ifndef BAR_FOO_H #ifndef BAR_FOO_H
2963 # define BAR_FOO_H # define BAR_FOO_H
2965 /* Enabling traces. */ /* Enabling traces. */
2966 # ifndef YYDEBUG | # ifndef BAR_DEBUG
2967 > # if defined YYDEBUG
2969 > # define BAR_DEBUG 1
2971 > # define BAR_DEBUG 0
2974 # define YYDEBUG 0 | # define BAR_DEBUG 0
2978 # if YYDEBUG | # if BAR_DEBUG
2979 extern int bar_debug; extern int bar_debug;
2982 /* Tokens. */ /* Tokens. */
2983 # ifndef YYTOKENTYPE | # ifndef BAR_TOKENTYPE
2984 # define YYTOKENTYPE | # define BAR_TOKENTYPE
2985 enum yytokentype { | enum bar_tokentype {
2990 #if ! defined YYSTYPE \ | #if ! defined BAR_STYPE \
2991 && ! defined YYSTYPE_IS_DECLARED | && ! defined BAR_STYPE_IS_DECLARED
2992 typedef union YYSTYPE | typedef union BAR_STYPE
2995 } YYSTYPE; | } BAR_STYPE;
2996 # define YYSTYPE_IS_DECLARED 1 | # define BAR_STYPE_IS_DECLARED 1
2999 extern YYSTYPE bar_lval; | extern BAR_STYPE bar_lval;
3001 int bar_parse (void); int bar_parse (void);
3003 #endif /* !BAR_FOO_H */ #endif /* !BAR_FOO_H */
3006 * Noteworthy changes in release 2.5.1 (2012-06-05) [stable]
3010 The next major release will drop support for generating parsers in K&R C.
3012 ** yacc.c: YYBACKUP works as expected.
3014 ** glr.c improvements:
3016 *** Location support is eliminated when not requested:
3018 GLR parsers used to include location-related code even when locations were
3019 not requested, and therefore not even usable.
3021 *** __attribute__ is preserved:
3023 __attribute__ is no longer disabled when __STRICT_ANSI__ is defined (i.e.,
3024 when -std is passed to GCC).
3026 ** lalr1.java: several fixes:
3028 The Java parser no longer throws ArrayIndexOutOfBoundsException if the
3029 first token leads to a syntax error. Some minor clean ups.
3033 *** C++11 compatibility:
3035 C and C++ parsers use "nullptr" instead of "0" when __cplusplus is 201103L
3040 The header files such as "parser.hh", "location.hh", etc. used a constant
3041 name for preprocessor guards, for instance:
3043 #ifndef BISON_LOCATION_HH
3044 # define BISON_LOCATION_HH
3046 #endif // !BISON_LOCATION_HH
3048 The inclusion guard is now computed from "PREFIX/FILE-NAME", where lower
3049 case characters are converted to upper case, and series of
3050 non-alphanumerical characters are converted to an underscore.
3052 With "bison -o lang++/parser.cc", "location.hh" would now include:
3054 #ifndef YY_LANG_LOCATION_HH
3055 # define YY_LANG_LOCATION_HH
3057 #endif // !YY_LANG_LOCATION_HH
3061 The position and location constructors (and their initialize methods)
3062 accept new arguments for line and column. Several issues in the
3063 documentation were fixed.
3065 ** liby is no longer asking for "rpl_fprintf" on some platforms.
3067 ** Changes in the manual:
3069 *** %printer is documented
3071 The "%printer" directive, supported since at least Bison 1.50, is finally
3072 documented. The "mfcalc" example is extended to demonstrate it.
3074 For consistency with the C skeletons, the C++ parsers now also support
3075 "yyoutput" (as an alias to "debug_stream ()").
3077 *** Several improvements have been made:
3079 The layout for grammar excerpts was changed to a more compact scheme.
3080 Named references are motivated. The description of the automaton
3081 description file (*.output) is updated to the current format. Incorrect
3082 index entries were fixed. Some other errors were fixed.
3086 *** Conflicting prototypes with recent/modified Flex.
3088 Fixed build problems with the current, unreleased, version of Flex, and
3089 some modified versions of 2.5.35, which have modified function prototypes.
3091 *** Warnings during the build procedure have been eliminated.
3093 *** Several portability problems in the test suite have been fixed:
3095 This includes warnings with some compilers, unexpected behavior of tools
3096 such as diff, warning messages from the test suite itself, etc.
3098 *** The install-pdf target works properly:
3100 Running "make install-pdf" (or -dvi, -html, -info, and -ps) no longer
3101 halts in the middle of its course.
3104 * Noteworthy changes in release 2.5 (2011-05-14)
3106 ** Grammar symbol names can now contain non-initial dashes:
3108 Consistently with directives (such as %error-verbose) and with
3109 %define variables (e.g. push-pull), grammar symbol names may contain
3110 dashes in any position except the beginning. This is a GNU
3111 extension over POSIX Yacc. Thus, use of this extension is reported
3112 by -Wyacc and rejected in Yacc mode (--yacc).
3114 ** Named references:
3116 Historically, Yacc and Bison have supported positional references
3117 ($n, $$) to allow access to symbol values from inside of semantic
3120 Starting from this version, Bison can also accept named references.
3121 When no ambiguity is possible, original symbol names may be used
3122 as named references:
3124 if_stmt : "if" cond_expr "then" then_stmt ';'
3125 { $if_stmt = mk_if_stmt($cond_expr, $then_stmt); }
3127 In the more common case, explicit names may be declared:
3129 stmt[res] : "if" expr[cond] "then" stmt[then] "else" stmt[else] ';'
3130 { $res = mk_if_stmt($cond, $then, $else); }
3132 Location information is also accessible using @name syntax. When
3133 accessing symbol names containing dots or dashes, explicit bracketing
3134 ($[sym.1]) must be used.
3136 These features are experimental in this version. More user feedback
3137 will help to stabilize them.
3138 Contributed by Alex Rozenman.
3140 ** IELR(1) and canonical LR(1):
3142 IELR(1) is a minimal LR(1) parser table generation algorithm. That
3143 is, given any context-free grammar, IELR(1) generates parser tables
3144 with the full language-recognition power of canonical LR(1) but with
3145 nearly the same number of parser states as LALR(1). This reduction
3146 in parser states is often an order of magnitude. More importantly,
3147 because canonical LR(1)'s extra parser states may contain duplicate
3148 conflicts in the case of non-LR(1) grammars, the number of conflicts
3149 for IELR(1) is often an order of magnitude less as well. This can
3150 significantly reduce the complexity of developing of a grammar.
3152 Bison can now generate IELR(1) and canonical LR(1) parser tables in
3153 place of its traditional LALR(1) parser tables, which remain the
3154 default. You can specify the type of parser tables in the grammar
3155 file with these directives:
3157 %define lr.type lalr
3158 %define lr.type ielr
3159 %define lr.type canonical-lr
3161 The default-reduction optimization in the parser tables can also be
3162 adjusted using "%define lr.default-reductions". For details on both
3163 of these features, see the new section "Tuning LR" in the Bison
3166 These features are experimental. More user feedback will help to
3169 ** LAC (Lookahead Correction) for syntax error handling
3171 Contributed by Joel E. Denny.
3173 Canonical LR, IELR, and LALR can suffer from a couple of problems
3174 upon encountering a syntax error. First, the parser might perform
3175 additional parser stack reductions before discovering the syntax
3176 error. Such reductions can perform user semantic actions that are
3177 unexpected because they are based on an invalid token, and they
3178 cause error recovery to begin in a different syntactic context than
3179 the one in which the invalid token was encountered. Second, when
3180 verbose error messages are enabled (with %error-verbose or the
3181 obsolete "#define YYERROR_VERBOSE"), the expected token list in the
3182 syntax error message can both contain invalid tokens and omit valid
3185 The culprits for the above problems are %nonassoc, default
3186 reductions in inconsistent states, and parser state merging. Thus,
3187 IELR and LALR suffer the most. Canonical LR can suffer only if
3188 %nonassoc is used or if default reductions are enabled for
3189 inconsistent states.
3191 LAC is a new mechanism within the parsing algorithm that solves
3192 these problems for canonical LR, IELR, and LALR without sacrificing
3193 %nonassoc, default reductions, or state merging. When LAC is in
3194 use, canonical LR and IELR behave almost exactly the same for both
3195 syntactically acceptable and syntactically unacceptable input.
3196 While LALR still does not support the full language-recognition
3197 power of canonical LR and IELR, LAC at least enables LALR's syntax
3198 error handling to correctly reflect LALR's language-recognition
3201 Currently, LAC is only supported for deterministic parsers in C.
3202 You can enable LAC with the following directive:
3204 %define parse.lac full
3206 See the new section "LAC" in the Bison manual for additional
3207 details including a few caveats.
3209 LAC is an experimental feature. More user feedback will help to
3212 ** %define improvements:
3214 *** Can now be invoked via the command line:
3216 Each of these command-line options
3219 --define=NAME[=VALUE]
3222 --force-define=NAME[=VALUE]
3224 is equivalent to this grammar file declaration
3226 %define NAME ["VALUE"]
3228 except that the manner in which Bison processes multiple definitions
3229 for the same NAME differs. Most importantly, -F and --force-define
3230 quietly override %define, but -D and --define do not. For further
3231 details, see the section "Bison Options" in the Bison manual.
3233 *** Variables renamed:
3235 The following %define variables
3238 lr.keep_unreachable_states
3240 have been renamed to
3243 lr.keep-unreachable-states
3245 The old names are now deprecated but will be maintained indefinitely
3246 for backward compatibility.
3248 *** Values no longer need to be quoted in the grammar file:
3250 If a %define value is an identifier, it no longer needs to be placed
3251 within quotations marks. For example,
3253 %define api.push-pull "push"
3257 %define api.push-pull push
3259 *** Unrecognized variables are now errors not warnings.
3261 *** Multiple invocations for any variable is now an error not a warning.
3263 ** Unrecognized %code qualifiers are now errors not warnings.
3265 ** Character literals not of length one:
3267 Previously, Bison quietly converted all character literals to length
3268 one. For example, without warning, Bison interpreted the operators in
3269 the following grammar to be the same token:
3275 Bison now warns when a character literal is not of length one. In
3276 some future release, Bison will start reporting an error instead.
3278 ** Destructor calls fixed for lookaheads altered in semantic actions:
3280 Previously for deterministic parsers in C, if a user semantic action
3281 altered yychar, the parser in some cases used the old yychar value to
3282 determine which destructor to call for the lookahead upon a syntax
3283 error or upon parser return. This bug has been fixed.
3285 ** C++ parsers use YYRHSLOC:
3287 Similarly to the C parsers, the C++ parsers now define the YYRHSLOC
3288 macro and use it in the default YYLLOC_DEFAULT. You are encouraged
3289 to use it. If, for instance, your location structure has "first"
3290 and "last" members, instead of
3292 # define YYLLOC_DEFAULT(Current, Rhs, N) \
3296 (Current).first = (Rhs)[1].location.first; \
3297 (Current).last = (Rhs)[N].location.last; \
3301 (Current).first = (Current).last = (Rhs)[0].location.last; \
3307 # define YYLLOC_DEFAULT(Current, Rhs, N) \
3311 (Current).first = YYRHSLOC (Rhs, 1).first; \
3312 (Current).last = YYRHSLOC (Rhs, N).last; \
3316 (Current).first = (Current).last = YYRHSLOC (Rhs, 0).last; \
3320 ** YYLLOC_DEFAULT in C++:
3322 The default implementation of YYLLOC_DEFAULT used to be issued in
3323 the header file. It is now output in the implementation file, after
3324 the user %code sections so that its #ifndef guard does not try to
3325 override the user's YYLLOC_DEFAULT if provided.
3327 ** YYFAIL now produces warnings and Java parsers no longer implement it:
3329 YYFAIL has existed for many years as an undocumented feature of
3330 deterministic parsers in C generated by Bison. More recently, it was
3331 a documented feature of Bison's experimental Java parsers. As
3332 promised in Bison 2.4.2's NEWS entry, any appearance of YYFAIL in a
3333 semantic action now produces a deprecation warning, and Java parsers
3334 no longer implement YYFAIL at all. For further details, including a
3335 discussion of how to suppress C preprocessor warnings about YYFAIL
3336 being unused, see the Bison 2.4.2 NEWS entry.
3338 ** Temporary hack for adding a semicolon to the user action:
3340 Previously, Bison appended a semicolon to every user action for
3341 reductions when the output language defaulted to C (specifically, when
3342 neither %yacc, %language, %skeleton, or equivalent command-line
3343 options were specified). This allowed actions such as
3345 exp: exp "+" exp { $$ = $1 + $3 };
3349 exp: exp "+" exp { $$ = $1 + $3; };
3351 As a first step in removing this misfeature, Bison now issues a
3352 warning when it appends a semicolon. Moreover, in cases where Bison
3353 cannot easily determine whether a semicolon is needed (for example, an
3354 action ending with a cpp directive or a braced compound initializer),
3355 it no longer appends one. Thus, the C compiler might now complain
3356 about a missing semicolon where it did not before. Future releases of
3357 Bison will cease to append semicolons entirely.
3359 ** Verbose syntax error message fixes:
3361 When %error-verbose or the obsolete "#define YYERROR_VERBOSE" is
3362 specified, syntax error messages produced by the generated parser
3363 include the unexpected token as well as a list of expected tokens.
3364 The effect of %nonassoc on these verbose messages has been corrected
3365 in two ways, but a more complete fix requires LAC, described above:
3367 *** When %nonassoc is used, there can exist parser states that accept no
3368 tokens, and so the parser does not always require a lookahead token
3369 in order to detect a syntax error. Because no unexpected token or
3370 expected tokens can then be reported, the verbose syntax error
3371 message described above is suppressed, and the parser instead
3372 reports the simpler message, "syntax error". Previously, this
3373 suppression was sometimes erroneously triggered by %nonassoc when a
3374 lookahead was actually required. Now verbose messages are
3375 suppressed only when all previous lookaheads have already been
3376 shifted or discarded.
3378 *** Previously, the list of expected tokens erroneously included tokens
3379 that would actually induce a syntax error because conflicts for them
3380 were resolved with %nonassoc in the current parser state. Such
3381 tokens are now properly omitted from the list.
3383 *** Expected token lists are still often wrong due to state merging
3384 (from LALR or IELR) and default reductions, which can both add
3385 invalid tokens and subtract valid tokens. Canonical LR almost
3386 completely fixes this problem by eliminating state merging and
3387 default reductions. However, there is one minor problem left even
3388 when using canonical LR and even after the fixes above. That is,
3389 if the resolution of a conflict with %nonassoc appears in a later
3390 parser state than the one at which some syntax error is
3391 discovered, the conflicted token is still erroneously included in
3392 the expected token list. Bison's new LAC implementation,
3393 described above, eliminates this problem and the need for
3394 canonical LR. However, LAC is still experimental and is disabled
3397 ** Java skeleton fixes:
3399 *** A location handling bug has been fixed.
3401 *** The top element of each of the value stack and location stack is now
3402 cleared when popped so that it can be garbage collected.
3404 *** Parser traces now print the top element of the stack.
3406 ** -W/--warnings fixes:
3408 *** Bison now properly recognizes the "no-" versions of categories:
3410 For example, given the following command line, Bison now enables all
3411 warnings except warnings for incompatibilities with POSIX Yacc:
3413 bison -Wall,no-yacc gram.y
3415 *** Bison now treats S/R and R/R conflicts like other warnings:
3417 Previously, conflict reports were independent of Bison's normal
3418 warning system. Now, Bison recognizes the warning categories
3419 "conflicts-sr" and "conflicts-rr". This change has important
3420 consequences for the -W and --warnings command-line options. For
3423 bison -Wno-conflicts-sr gram.y # S/R conflicts not reported
3424 bison -Wno-conflicts-rr gram.y # R/R conflicts not reported
3425 bison -Wnone gram.y # no conflicts are reported
3426 bison -Werror gram.y # any conflict is an error
3428 However, as before, if the %expect or %expect-rr directive is
3429 specified, an unexpected number of conflicts is an error, and an
3430 expected number of conflicts is not reported, so -W and --warning
3431 then have no effect on the conflict report.
3433 *** The "none" category no longer disables a preceding "error":
3435 For example, for the following command line, Bison now reports
3436 errors instead of warnings for incompatibilities with POSIX Yacc:
3438 bison -Werror,none,yacc gram.y
3440 *** The "none" category now disables all Bison warnings:
3442 Previously, the "none" category disabled only Bison warnings for
3443 which there existed a specific -W/--warning category. However,
3444 given the following command line, Bison is now guaranteed to
3445 suppress all warnings:
3449 ** Precedence directives can now assign token number 0:
3451 Since Bison 2.3b, which restored the ability of precedence
3452 directives to assign token numbers, doing so for token number 0 has
3453 produced an assertion failure. For example:
3457 This bug has been fixed.
3460 * Noteworthy changes in release 2.4.3 (2010-08-05)
3462 ** Bison now obeys -Werror and --warnings=error for warnings about
3463 grammar rules that are useless in the parser due to conflicts.
3465 ** Problems with spawning M4 on at least FreeBSD 8 and FreeBSD 9 have
3468 ** Failures in the test suite for GCC 4.5 have been fixed.
3470 ** Failures in the test suite for some versions of Sun Studio C++ have
3473 ** Contrary to Bison 2.4.2's NEWS entry, it has been decided that
3474 warnings about undefined %prec identifiers will not be converted to
3475 errors in Bison 2.5. They will remain warnings, which should be
3476 sufficient for POSIX while avoiding backward compatibility issues.
3478 ** Minor documentation fixes.
3481 * Noteworthy changes in release 2.4.2 (2010-03-20)
3483 ** Some portability problems that resulted in failures and livelocks
3484 in the test suite on some versions of at least Solaris, AIX, HP-UX,
3485 RHEL4, and Tru64 have been addressed. As a result, fatal Bison
3486 errors should no longer cause M4 to report a broken pipe on the
3489 ** "%prec IDENTIFIER" requires IDENTIFIER to be defined separately.
3491 POSIX specifies that an error be reported for any identifier that does
3492 not appear on the LHS of a grammar rule and that is not defined by
3493 %token, %left, %right, or %nonassoc. Bison 2.3b and later lost this
3494 error report for the case when an identifier appears only after a
3495 %prec directive. It is now restored. However, for backward
3496 compatibility with recent Bison releases, it is only a warning for
3497 now. In Bison 2.5 and later, it will return to being an error.
3498 [Between the 2.4.2 and 2.4.3 releases, it was decided that this
3499 warning will not be converted to an error in Bison 2.5.]
3501 ** Detection of GNU M4 1.4.6 or newer during configure is improved.
3503 ** Warnings from gcc's -Wundef option about undefined YYENABLE_NLS,
3504 YYLTYPE_IS_TRIVIAL, and __STRICT_ANSI__ in C/C++ parsers are now
3507 ** %code is now a permanent feature.
3509 A traditional Yacc prologue directive is written in the form:
3513 To provide a more flexible alternative, Bison 2.3b introduced the
3514 %code directive with the following forms for C/C++:
3517 %code requires {CODE}
3518 %code provides {CODE}
3521 These forms are now considered permanent features of Bison. See the
3522 %code entries in the section "Bison Declaration Summary" in the Bison
3523 manual for a summary of their functionality. See the section
3524 "Prologue Alternatives" for a detailed discussion including the
3525 advantages of %code over the traditional Yacc prologue directive.
3527 Bison's Java feature as a whole including its current usage of %code
3528 is still considered experimental.
3530 ** YYFAIL is deprecated and will eventually be removed.
3532 YYFAIL has existed for many years as an undocumented feature of
3533 deterministic parsers in C generated by Bison. Previously, it was
3534 documented for Bison's experimental Java parsers. YYFAIL is no longer
3535 documented for Java parsers and is formally deprecated in both cases.
3536 Users are strongly encouraged to migrate to YYERROR, which is
3539 Like YYERROR, you can invoke YYFAIL from a semantic action in order to
3540 induce a syntax error. The most obvious difference from YYERROR is
3541 that YYFAIL will automatically invoke yyerror to report the syntax
3542 error so that you don't have to. However, there are several other
3543 subtle differences between YYERROR and YYFAIL, and YYFAIL suffers from
3544 inherent flaws when %error-verbose or "#define YYERROR_VERBOSE" is
3545 used. For a more detailed discussion, see:
3547 https://lists.gnu.org/r/bison-patches/2009-12/msg00024.html
3549 The upcoming Bison 2.5 will remove YYFAIL from Java parsers, but
3550 deterministic parsers in C will continue to implement it. However,
3551 because YYFAIL is already flawed, it seems futile to try to make new
3552 Bison features compatible with it. Thus, during parser generation,
3553 Bison 2.5 will produce a warning whenever it discovers YYFAIL in a
3554 rule action. In a later release, YYFAIL will be disabled for
3555 %error-verbose and "#define YYERROR_VERBOSE". Eventually, YYFAIL will
3556 be removed altogether.
3558 There exists at least one case where Bison 2.5's YYFAIL warning will
3559 be a false positive. Some projects add phony uses of YYFAIL and other
3560 Bison-defined macros for the sole purpose of suppressing C
3561 preprocessor warnings (from GCC cpp's -Wunused-macros, for example).
3562 To avoid Bison's future warning, such YYFAIL uses can be moved to the
3563 epilogue (that is, after the second "%%") in the Bison input file. In
3564 this release (2.4.2), Bison already generates its own code to suppress
3565 C preprocessor warnings for YYFAIL, so projects can remove their own
3566 phony uses of YYFAIL if compatibility with Bison releases prior to
3567 2.4.2 is not necessary.
3569 ** Internationalization.
3571 Fix a regression introduced in Bison 2.4: Under some circumstances,
3572 message translations were not installed although supported by the
3576 * Noteworthy changes in release 2.4.1 (2008-12-11)
3578 ** In the GLR defines file, unexpanded M4 macros in the yylval and yylloc
3579 declarations have been fixed.
3581 ** Temporary hack for adding a semicolon to the user action.
3583 Bison used to prepend a trailing semicolon at the end of the user
3584 action for reductions. This allowed actions such as
3586 exp: exp "+" exp { $$ = $1 + $3 };
3590 exp: exp "+" exp { $$ = $1 + $3; };
3592 Some grammars still depend on this "feature". Bison 2.4.1 restores
3593 the previous behavior in the case of C output (specifically, when
3594 neither %language or %skeleton or equivalent command-line options
3595 are used) to leave more time for grammars depending on the old
3596 behavior to be adjusted. Future releases of Bison will disable this
3599 ** A few minor improvements to the Bison manual.
3602 * Noteworthy changes in release 2.4 (2008-11-02)
3604 ** %language is an experimental feature.
3606 We first introduced this feature in test release 2.3b as a cleaner
3607 alternative to %skeleton. Since then, we have discussed the possibility of
3608 modifying its effect on Bison's output file names. Thus, in this release,
3609 we consider %language to be an experimental feature that will likely evolve
3612 ** Forward compatibility with GNU M4 has been improved.
3614 ** Several bugs in the C++ skeleton and the experimental Java skeleton have been
3618 * Noteworthy changes in release 2.3b (2008-05-27)
3620 ** The quotes around NAME that used to be required in the following directive
3623 %define NAME "VALUE"
3625 ** The directive "%pure-parser" is now deprecated in favor of:
3629 which has the same effect except that Bison is more careful to warn about
3630 unreasonable usage in the latter case.
3634 Bison can now generate an LALR(1) parser in C with a push interface. That
3635 is, instead of invoking "yyparse", which pulls tokens from "yylex", you can
3636 push one token at a time to the parser using "yypush_parse", which will
3637 return to the caller after processing each token. By default, the push
3638 interface is disabled. Either of the following directives will enable it:
3640 %define api.push_pull "push" // Just push; does not require yylex.
3641 %define api.push_pull "both" // Push and pull; requires yylex.
3643 See the new section "A Push Parser" in the Bison manual for details.
3645 The current push parsing interface is experimental and may evolve. More user
3646 feedback will help to stabilize it.
3648 ** The -g and --graph options now output graphs in Graphviz DOT format,
3649 not VCG format. Like --graph, -g now also takes an optional FILE argument
3650 and thus cannot be bundled with other short options.
3654 Bison can now generate an LALR(1) parser in Java. The skeleton is
3655 "data/lalr1.java". Consider using the new %language directive instead of
3656 %skeleton to select it.
3658 See the new section "Java Parsers" in the Bison manual for details.
3660 The current Java interface is experimental and may evolve. More user
3661 feedback will help to stabilize it.
3662 Contributed by Paolo Bonzini.
3666 This new directive specifies the programming language of the generated
3667 parser, which can be C (the default), C++, or Java. Besides the skeleton
3668 that Bison uses, the directive affects the names of the generated files if
3669 the grammar file's name ends in ".y".
3671 ** XML Automaton Report
3673 Bison can now generate an XML report of the LALR(1) automaton using the new
3674 "--xml" option. The current XML schema is experimental and may evolve. More
3675 user feedback will help to stabilize it.
3676 Contributed by Wojciech Polak.
3678 ** The grammar file may now specify the name of the parser header file using
3679 %defines. For example:
3683 ** When reporting useless rules, useless nonterminals, and unused terminals,
3684 Bison now employs the terms "useless in grammar" instead of "useless",
3685 "useless in parser" instead of "never reduced", and "unused in grammar"
3686 instead of "unused".
3688 ** Unreachable State Removal
3690 Previously, Bison sometimes generated parser tables containing unreachable
3691 states. A state can become unreachable during conflict resolution if Bison
3692 disables a shift action leading to it from a predecessor state. Bison now:
3694 1. Removes unreachable states.
3696 2. Does not report any conflicts that appeared in unreachable states.
3697 WARNING: As a result, you may need to update %expect and %expect-rr
3698 directives in existing grammar files.
3700 3. For any rule used only in such states, Bison now reports the rule as
3701 "useless in parser due to conflicts".
3703 This feature can be disabled with the following directive:
3705 %define lr.keep_unreachable_states
3707 See the %define entry in the "Bison Declaration Summary" in the Bison manual
3708 for further discussion.
3710 ** Lookahead Set Correction in the ".output" Report
3712 When instructed to generate a ".output" file including lookahead sets
3713 (using "--report=lookahead", for example), Bison now prints each reduction's
3714 lookahead set only next to the associated state's one item that (1) is
3715 associated with the same rule as the reduction and (2) has its dot at the end
3716 of its RHS. Previously, Bison also erroneously printed the lookahead set
3717 next to all of the state's other items associated with the same rule. This
3718 bug affected only the ".output" file and not the generated parser source
3721 ** --report-file=FILE is a new option to override the default ".output" file
3724 ** The "=" that used to be required in the following directives is now
3727 %file-prefix "parser"
3731 ** An Alternative to "%{...%}" -- "%code QUALIFIER {CODE}"
3733 Bison 2.3a provided a new set of directives as a more flexible alternative to
3734 the traditional Yacc prologue blocks. Those have now been consolidated into
3735 a single %code directive with an optional qualifier field, which identifies
3736 the purpose of the code and thus the location(s) where Bison should generate
3739 1. "%code {CODE}" replaces "%after-header {CODE}"
3740 2. "%code requires {CODE}" replaces "%start-header {CODE}"
3741 3. "%code provides {CODE}" replaces "%end-header {CODE}"
3742 4. "%code top {CODE}" replaces "%before-header {CODE}"
3744 See the %code entries in section "Bison Declaration Summary" in the Bison
3745 manual for a summary of the new functionality. See the new section "Prologue
3746 Alternatives" for a detailed discussion including the advantages of %code
3747 over the traditional Yacc prologues.
3749 The prologue alternatives are experimental. More user feedback will help to
3750 determine whether they should become permanent features.
3752 ** Revised warning: unset or unused midrule values
3754 Since Bison 2.2, Bison has warned about midrule values that are set but not
3755 used within any of the actions of the parent rule. For example, Bison warns
3758 exp: '1' { $$ = 1; } '+' exp { $$ = $1 + $4; };
3760 Now, Bison also warns about midrule values that are used but not set. For
3761 example, Bison warns about unset $$ in the midrule action in:
3763 exp: '1' { $1 = 1; } '+' exp { $$ = $2 + $4; };
3765 However, Bison now disables both of these warnings by default since they
3766 sometimes prove to be false alarms in existing grammars employing the Yacc
3767 constructs $0 or $-N (where N is some positive integer).
3769 To enable these warnings, specify the option "--warnings=midrule-values" or
3770 "-W", which is a synonym for "--warnings=all".
3772 ** Default %destructor or %printer with "<*>" or "<>"
3774 Bison now recognizes two separate kinds of default %destructor's and
3777 1. Place "<*>" in a %destructor/%printer symbol list to define a default
3778 %destructor/%printer for all grammar symbols for which you have formally
3779 declared semantic type tags.
3781 2. Place "<>" in a %destructor/%printer symbol list to define a default
3782 %destructor/%printer for all grammar symbols without declared semantic
3785 Bison no longer supports the "%symbol-default" notation from Bison 2.3a.
3786 "<*>" and "<>" combined achieve the same effect with one exception: Bison no
3787 longer applies any %destructor to a midrule value if that midrule value is
3788 not actually ever referenced using either $$ or $n in a semantic action.
3790 The default %destructor's and %printer's are experimental. More user
3791 feedback will help to determine whether they should become permanent
3794 See the section "Freeing Discarded Symbols" in the Bison manual for further
3797 ** %left, %right, and %nonassoc can now declare token numbers. This is required
3798 by POSIX. However, see the end of section "Operator Precedence" in the Bison
3799 manual for a caveat concerning the treatment of literal strings.
3801 ** The nonfunctional --no-parser, -n, and %no-parser options have been
3802 completely removed from Bison.
3805 * Noteworthy changes in release 2.3a (2006-09-13)
3807 ** Instead of %union, you can define and use your own union type
3808 YYSTYPE if your grammar contains at least one <type> tag.
3809 Your YYSTYPE need not be a macro; it can be a typedef.
3810 This change is for compatibility with other Yacc implementations,
3811 and is required by POSIX.
3813 ** Locations columns and lines start at 1.
3814 In accordance with the GNU Coding Standards and Emacs.
3816 ** You may now declare per-type and default %destructor's and %printer's:
3820 %union { char *string; }
3821 %token <string> STRING1
3822 %token <string> STRING2
3823 %type <string> string1
3824 %type <string> string2
3825 %union { char character; }
3826 %token <character> CHR
3827 %type <character> chr
3828 %destructor { free ($$); } %symbol-default
3829 %destructor { free ($$); printf ("%d", @$.first_line); } STRING1 string1
3830 %destructor { } <character>
3832 guarantees that, when the parser discards any user-defined symbol that has a
3833 semantic type tag other than "<character>", it passes its semantic value to
3834 "free". However, when the parser discards a "STRING1" or a "string1", it
3835 also prints its line number to "stdout". It performs only the second
3836 "%destructor" in this case, so it invokes "free" only once.
3838 [Although we failed to mention this here in the 2.3a release, the default
3839 %destructor's and %printer's were experimental, and they were rewritten in
3842 ** Except for LALR(1) parsers in C with POSIX Yacc emulation enabled (with "-y",
3843 "--yacc", or "%yacc"), Bison no longer generates #define statements for
3844 associating token numbers with token names. Removing the #define statements
3845 helps to sanitize the global namespace during preprocessing, but POSIX Yacc
3846 requires them. Bison still generates an enum for token names in all cases.
3848 ** Handling of traditional Yacc prologue blocks is now more consistent but
3849 potentially incompatible with previous releases of Bison.
3851 As before, you declare prologue blocks in your grammar file with the
3852 "%{ ... %}" syntax. To generate the pre-prologue, Bison concatenates all
3853 prologue blocks that you've declared before the first %union. To generate
3854 the post-prologue, Bison concatenates all prologue blocks that you've
3855 declared after the first %union.
3857 Previous releases of Bison inserted the pre-prologue into both the header
3858 file and the code file in all cases except for LALR(1) parsers in C. In the
3859 latter case, Bison inserted it only into the code file. For parsers in C++,
3860 the point of insertion was before any token definitions (which associate
3861 token numbers with names). For parsers in C, the point of insertion was
3862 after the token definitions.
3864 Now, Bison never inserts the pre-prologue into the header file. In the code
3865 file, it always inserts it before the token definitions.
3867 ** Bison now provides a more flexible alternative to the traditional Yacc
3868 prologue blocks: %before-header, %start-header, %end-header, and
3871 For example, the following declaration order in the grammar file reflects the
3872 order in which Bison will output these code blocks. However, you are free to
3873 declare these code blocks in your grammar file in whatever order is most
3877 /* Bison treats this block like a pre-prologue block: it inserts it into
3878 * the code file before the contents of the header file. It does *not*
3879 * insert it into the header file. This is a good place to put
3880 * #include's that you want at the top of your code file. A common
3881 * example is '#include "system.h"'. */
3884 /* Bison inserts this block into both the header file and the code file.
3885 * In both files, the point of insertion is before any Bison-generated
3886 * token, semantic type, location type, and class definitions. This is a
3887 * good place to define %union dependencies, for example. */
3890 /* Unlike the traditional Yacc prologue blocks, the output order for the
3891 * new %*-header blocks is not affected by their declaration position
3892 * relative to any %union in the grammar file. */
3895 /* Bison inserts this block into both the header file and the code file.
3896 * In both files, the point of insertion is after the Bison-generated
3897 * definitions. This is a good place to declare or define public
3898 * functions or data structures that depend on the Bison-generated
3902 /* Bison treats this block like a post-prologue block: it inserts it into
3903 * the code file after the contents of the header file. It does *not*
3904 * insert it into the header file. This is a good place to declare or
3905 * define internal functions or data structures that depend on the
3906 * Bison-generated definitions. */
3909 If you have multiple occurrences of any one of the above declarations, Bison
3910 will concatenate the contents in declaration order.
3912 [Although we failed to mention this here in the 2.3a release, the prologue
3913 alternatives were experimental, and they were rewritten in future versions.]
3915 ** The option "--report=look-ahead" has been changed to "--report=lookahead".
3916 The old spelling still works, but is not documented and may be removed
3917 in a future release.
3920 * Noteworthy changes in release 2.3 (2006-06-05)
3922 ** GLR grammars should now use "YYRECOVERING ()" instead of "YYRECOVERING",
3923 for compatibility with LALR(1) grammars.
3925 ** It is now documented that any definition of YYSTYPE or YYLTYPE should
3926 be to a type name that does not contain parentheses or brackets.
3929 * Noteworthy changes in release 2.2 (2006-05-19)
3931 ** The distribution terms for all Bison-generated parsers now permit
3932 using the parsers in nonfree programs. Previously, this permission
3933 was granted only for Bison-generated LALR(1) parsers in C.
3935 ** %name-prefix changes the namespace name in C++ outputs.
3937 ** The C++ parsers export their token_type.
3939 ** Bison now allows multiple %union declarations, and concatenates
3940 their contents together.
3942 ** New warning: unused values
3943 Right-hand side symbols whose values are not used are reported,
3944 if the symbols have destructors. For instance:
3946 exp: exp "?" exp ":" exp { $1 ? $1 : $3; }
3950 will trigger a warning about $$ and $5 in the first rule, and $3 in
3951 the second ($1 is copied to $$ by the default rule). This example
3952 most likely contains three errors, and could be rewritten as:
3954 exp: exp "?" exp ":" exp
3955 { $$ = $1 ? $3 : $5; free ($1 ? $5 : $3); free ($1); }
3957 { $$ = $1 ? $1 : $3; if ($1) free ($3); }
3960 However, if the original actions were really intended, memory leaks
3961 and all, the warnings can be suppressed by letting Bison believe the
3962 values are used, e.g.:
3964 exp: exp "?" exp ":" exp { $1 ? $1 : $3; (void) ($$, $5); }
3965 | exp "+" exp { $$ = $1; (void) $3; }
3968 If there are midrule actions, the warning is issued if no action
3969 uses it. The following triggers no warning: $1 and $3 are used.
3971 exp: exp { push ($1); } '+' exp { push ($3); sum (); };
3973 The warning is intended to help catching lost values and memory leaks.
3974 If a value is ignored, its associated memory typically is not reclaimed.
3976 ** %destructor vs. YYABORT, YYACCEPT, and YYERROR.
3977 Destructors are now called when user code invokes YYABORT, YYACCEPT,
3978 and YYERROR, for all objects on the stack, other than objects
3979 corresponding to the right-hand side of the current rule.
3981 ** %expect, %expect-rr
3982 Incorrect numbers of expected conflicts are now actual errors,
3983 instead of warnings.
3985 ** GLR, YACC parsers.
3986 The %parse-params are available in the destructors (and the
3987 experimental printers) as per the documentation.
3989 ** Bison now warns if it finds a stray "$" or "@" in an action.
3991 ** %require "VERSION"
3992 This specifies that the grammar file depends on features implemented
3993 in Bison version VERSION or higher.
3995 ** lalr1.cc: The token and value types are now class members.
3996 The tokens were defined as free form enums and cpp macros. YYSTYPE
3997 was defined as a free form union. They are now class members:
3998 tokens are enumerations of the "yy::parser::token" struct, and the
3999 semantic values have the "yy::parser::semantic_type" type.
4001 If you do not want or can update to this scheme, the directive
4002 '%define "global_tokens_and_yystype" "1"' triggers the global
4003 definition of tokens and YYSTYPE. This change is suitable both
4004 for previous releases of Bison, and this one.
4006 If you wish to update, then make sure older version of Bison will
4007 fail using '%require "2.2"'.
4009 ** DJGPP support added.
4012 * Noteworthy changes in release 2.1 (2005-09-16)
4014 ** The C++ lalr1.cc skeleton supports %lex-param.
4016 ** Bison-generated parsers now support the translation of diagnostics like
4017 "syntax error" into languages other than English. The default
4018 language is still English. For details, please see the new
4019 Internationalization section of the Bison manual. Software
4020 distributors should also see the new PACKAGING file. Thanks to
4021 Bruno Haible for this new feature.
4023 ** Wording in the Bison-generated parsers has been changed slightly to
4024 simplify translation. In particular, the message "memory exhausted"
4025 has replaced "parser stack overflow", as the old message was not
4026 always accurate for modern Bison-generated parsers.
4028 ** Destructors are now called when the parser aborts, for all symbols left
4029 behind on the stack. Also, the start symbol is now destroyed after a
4030 successful parse. In both cases, the behavior was formerly inconsistent.
4032 ** When generating verbose diagnostics, Bison-generated parsers no longer
4033 quote the literal strings associated with tokens. For example, for
4034 a syntax error associated with '%token NUM "number"' they might
4035 print 'syntax error, unexpected number' instead of 'syntax error,
4036 unexpected "number"'.
4039 * Noteworthy changes in release 2.0 (2004-12-25)
4041 ** Possibly-incompatible changes
4043 - Bison-generated parsers no longer default to using the alloca function
4044 (when available) to extend the parser stack, due to widespread
4045 problems in unchecked stack-overflow detection. You can "#define
4046 YYSTACK_USE_ALLOCA 1" to require the use of alloca, but please read
4047 the manual to determine safe values for YYMAXDEPTH in that case.
4049 - Error token location.
4050 During error recovery, the location of the syntax error is updated
4051 to cover the whole sequence covered by the error token: it includes
4052 the shifted symbols thrown away during the first part of the error
4053 recovery, and the lookahead rejected during the second part.
4055 - Semicolon changes:
4056 . Stray semicolons are no longer allowed at the start of a grammar.
4057 . Semicolons are now required after in-grammar declarations.
4059 - Unescaped newlines are no longer allowed in character constants or
4060 string literals. They were never portable, and GCC 3.4.0 has
4061 dropped support for them. Better diagnostics are now generated if
4062 forget a closing quote.
4064 - NUL bytes are no longer allowed in Bison string literals, unfortunately.
4068 - GLR grammars now support locations.
4070 - New directive: %initial-action.
4071 This directive allows the user to run arbitrary code (including
4072 initializing @$) from yyparse before parsing starts.
4074 - A new directive "%expect-rr N" specifies the expected number of
4075 reduce/reduce conflicts in GLR parsers.
4077 - %token numbers can now be hexadecimal integers, e.g., "%token FOO 0x12d".
4078 This is a GNU extension.
4080 - The option "--report=lookahead" was changed to "--report=look-ahead".
4081 [However, this was changed back after 2.3.]
4083 - Experimental %destructor support has been added to lalr1.cc.
4085 - New configure option --disable-yacc, to disable installation of the
4086 yacc command and -ly library introduced in 1.875 for POSIX conformance.
4090 - For now, %expect-count violations are now just warnings, not errors.
4091 This is for compatibility with Bison 1.75 and earlier (when there are
4092 reduce/reduce conflicts) and with Bison 1.30 and earlier (when there
4093 are too many or too few shift/reduce conflicts). However, in future
4094 versions of Bison we plan to improve the %expect machinery so that
4095 these violations will become errors again.
4097 - Within Bison itself, numbers (e.g., goto numbers) are no longer
4098 arbitrarily limited to 16-bit counts.
4100 - Semicolons are now allowed before "|" in grammar rules, as POSIX requires.
4103 * Noteworthy changes in release 1.875 (2003-01-01)
4105 ** The documentation license has been upgraded to version 1.2
4106 of the GNU Free Documentation License.
4108 ** syntax error processing
4110 - In Yacc-style parsers YYLLOC_DEFAULT is now used to compute error
4111 locations too. This fixes bugs in error-location computation.
4114 It is now possible to reclaim the memory associated to symbols
4115 discarded during error recovery. This feature is still experimental.
4118 This new directive is preferred over YYERROR_VERBOSE.
4120 - #defining yyerror to steal internal variables is discouraged.
4121 It is not guaranteed to work forever.
4123 ** POSIX conformance
4125 - Semicolons are once again optional at the end of grammar rules.
4126 This reverts to the behavior of Bison 1.33 and earlier, and improves
4127 compatibility with Yacc.
4129 - "parse error" -> "syntax error"
4130 Bison now uniformly uses the term "syntax error"; formerly, the code
4131 and manual sometimes used the term "parse error" instead. POSIX
4132 requires "syntax error" in diagnostics, and it was thought better to
4135 - The documentation now emphasizes that yylex and yyerror must be
4136 declared before use. C99 requires this.
4138 - Bison now parses C99 lexical constructs like UCNs and
4139 backslash-newline within C escape sequences, as POSIX 1003.1-2001 requires.
4141 - File names are properly escaped in C output. E.g., foo\bar.y is
4142 output as "foo\\bar.y".
4144 - Yacc command and library now available
4145 The Bison distribution now installs a "yacc" command, as POSIX requires.
4146 Also, Bison now installs a small library liby.a containing
4147 implementations of Yacc-compatible yyerror and main functions.
4148 This library is normally not useful, but POSIX requires it.
4150 - Type clashes now generate warnings, not errors.
4152 - If the user does not define YYSTYPE as a macro, Bison now declares it
4153 using typedef instead of defining it as a macro.
4154 For consistency, YYLTYPE is also declared instead of defined.
4156 ** Other compatibility issues
4158 - %union directives can now have a tag before the "{", e.g., the
4159 directive "%union foo {...}" now generates the C code
4160 "typedef union foo { ... } YYSTYPE;"; this is for Yacc compatibility.
4161 The default union tag is "YYSTYPE", for compatibility with Solaris 9 Yacc.
4162 For consistency, YYLTYPE's struct tag is now "YYLTYPE" not "yyltype".
4163 This is for compatibility with both Yacc and Bison 1.35.
4165 - ";" is output before the terminating "}" of an action, for
4166 compatibility with Bison 1.35.
4168 - Bison now uses a Yacc-style format for conflict reports, e.g.,
4169 "conflicts: 2 shift/reduce, 1 reduce/reduce".
4171 - "yystype" and "yyltype" are now obsolescent macros instead of being
4172 typedefs or tags; they are no longer documented and are planned to be
4173 withdrawn in a future release.
4178 Users of Bison have to decide how they handle the portability of the
4181 - "parsing stack overflow..." -> "parser stack overflow"
4182 GLR parsers now report "parser stack overflow" as per the Bison manual.
4184 ** %parse-param and %lex-param
4185 The macros YYPARSE_PARAM and YYLEX_PARAM provide a means to pass
4186 additional context to yyparse and yylex. They suffer from several
4189 - a single argument only can be added,
4190 - their types are weak (void *),
4191 - this context is not passed to ancillary functions such as yyerror,
4192 - only yacc.c parsers support them.
4194 The new %parse-param/%lex-param directives provide a more precise control.
4197 %parse-param {int *nastiness}
4198 %lex-param {int *nastiness}
4199 %parse-param {int *randomness}
4201 results in the following signatures:
4203 int yylex (int *nastiness);
4204 int yyparse (int *nastiness, int *randomness);
4206 or, if both %pure-parser and %locations are used:
4208 int yylex (YYSTYPE *lvalp, YYLTYPE *llocp, int *nastiness);
4209 int yyparse (int *nastiness, int *randomness);
4211 ** Bison now warns if it detects conflicting outputs to the same file,
4212 e.g., it generates a warning for "bison -d -o foo.h foo.y" since
4213 that command outputs both code and header to foo.h.
4215 ** #line in output files
4216 - --no-line works properly.
4218 ** Bison can no longer be built by a K&R C compiler; it requires C89 or
4219 later to be built. This change originally took place a few versions
4220 ago, but nobody noticed until we recently asked someone to try
4221 building Bison with a K&R C compiler.
4224 * Noteworthy changes in release 1.75 (2002-10-14)
4226 ** Bison should now work on 64-bit hosts.
4228 ** Indonesian translation thanks to Tedi Heriyanto.
4231 Fix spurious parse errors.
4234 Some people redefine yyerror to steal yyparse' private variables.
4235 Reenable this trick until an official feature replaces it.
4238 In agreement with POSIX and with other Yaccs, leaving a default
4239 action is valid when $$ is untyped, and $1 typed:
4243 but the converse remains an error:
4247 ** Values of midrule actions
4250 foo: { ... } { $$ = $1; } ...
4252 was incorrectly rejected: $1 is defined in the second midrule
4253 action, and is equal to the $$ of the first midrule action.
4256 * Noteworthy changes in release 1.50 (2002-10-04)
4261 causes Bison to produce a Generalized LR (GLR) parser, capable of handling
4262 almost any context-free grammar, ambiguous or not. The new declarations
4263 %dprec and %merge on grammar rules allow parse-time resolution of
4264 ambiguities. Contributed by Paul Hilfinger.
4266 Unfortunately Bison 1.50 does not work properly on 64-bit hosts
4267 like the Alpha, so please stick to 32-bit hosts for now.
4270 When not in Yacc compatibility mode, when the output file was not
4271 specified, running "bison foo/bar.y" created "foo/bar.c". It
4272 now creates "bar.c".
4275 The undefined token was systematically mapped to 2 which prevented
4276 the use of 2 by the user. This is no longer the case.
4278 ** Unknown token numbers
4279 If yylex returned an out of range value, yyparse could die. This is
4283 According to POSIX, the error token must be 256.
4284 Bison extends this requirement by making it a preference: *if* the
4285 user specified that one of her tokens is numbered 256, then error
4286 will be mapped onto another number.
4288 ** Verbose error messages
4289 They no longer report "..., expecting error or..." for states where
4290 error recovery is possible.
4293 Defaults to "$end" instead of "$".
4295 ** Error recovery now conforms to documentation and to POSIX
4296 When a Bison-generated parser encounters a syntax error, it now pops
4297 the stack until it finds a state that allows shifting the error
4298 token. Formerly, it popped the stack until it found a state that
4299 allowed some non-error action other than a default reduction on the
4300 error token. The new behavior has long been the documented behavior,
4301 and has long been required by POSIX. For more details, please see
4302 Paul Eggert, "Reductions during Bison error handling" (2002-05-20)
4303 <https://lists.gnu.org/r/bug-bison/2002-05/msg00038.html>.
4306 Popped tokens and nonterminals are now reported.
4309 Larger grammars are now supported (larger token numbers, larger grammar
4310 size (= sum of the LHS and RHS lengths), larger LALR tables).
4311 Formerly, many of these numbers ran afoul of 16-bit limits;
4312 now these limits are 32 bits on most hosts.
4314 ** Explicit initial rule
4315 Bison used to play hacks with the initial rule, which the user does
4316 not write. It is now explicit, and visible in the reports and
4320 Before, Bison reported the useless rules, but, although not used,
4321 included them in the parsers. They are now actually removed.
4323 ** Useless rules, useless nonterminals
4324 They are now reported, as a warning, with their locations.
4326 ** Rules never reduced
4327 Rules that can never be reduced because of conflicts are now
4330 ** Incorrect "Token not used"
4331 On a grammar such as
4333 %token useless useful
4335 exp: '0' %prec useful;
4337 where a token was used to set the precedence of the last rule,
4338 bison reported both "useful" and "useless" as useless tokens.
4340 ** Revert the C++ namespace changes introduced in 1.31
4341 as they caused too many portability hassles.
4343 ** Default locations
4344 By an accident of design, the default computation of @$ was
4345 performed after another default computation was performed: @$ = @1.
4346 The latter is now removed: YYLLOC_DEFAULT is fully responsible of
4347 the computation of @$.
4349 ** Token end-of-file
4350 The token end of file may be specified by the user, in which case,
4351 the user symbol is used in the reports, the graphs, and the verbose
4352 error messages instead of "$end", which remains being the default.
4356 %token MYEOF 0 "end of file"
4359 This old option, which has been broken for ages, is removed.
4362 Brazilian Portuguese, thanks to Alexandre Folle de Menezes.
4363 Croatian, thanks to Denis Lackovic.
4365 ** Incorrect token definitions
4368 bison used to output
4371 ** Token definitions as enums
4372 Tokens are output both as the traditional #define's, and, provided
4373 the compiler supports ANSI C or is a C++ compiler, as enums.
4374 This lets debuggers display names instead of integers.
4377 In addition to --verbose, bison supports --report=THINGS, which
4378 produces additional information:
4380 complete the core item sets with their closure
4381 - lookahead [changed to "look-ahead" in 1.875e through 2.3, but changed back]
4382 explicitly associate lookahead tokens to items
4384 describe shift/reduce conflicts solving.
4385 Bison used to systematically output this information on top of
4386 the report. Solved conflicts are now attached to their states.
4389 Previous versions don't complain when there is a type clash on
4390 the default action if the rule has a midrule action, such as in:
4398 ** GNU M4 is now required when using Bison.
4401 * Noteworthy changes in release 1.35 (2002-03-25)
4404 Some projects use Bison's C parser with C++ compilers, and define
4405 YYSTYPE as a class. The recent adjustment of C parsers for data
4406 alignment and 64 bit architectures made this impossible.
4408 Because for the time being no real solution for C++ parser
4409 generation exists, kludges were implemented in the parser to
4410 maintain this use. In the future, when Bison has C++ parsers, this
4411 kludge will be disabled.
4413 This kludge also addresses some C++ problems when the stack was
4417 * Noteworthy changes in release 1.34 (2002-03-12)
4419 ** File name clashes are detected
4420 $ bison foo.y -d -o foo.x
4421 fatal error: header and parser would both be named "foo.x"
4423 ** A missing ";" at the end of a rule triggers a warning
4424 In accordance with POSIX, and in agreement with other
4425 Yacc implementations, Bison will mandate this semicolon in the near
4426 future. This eases the implementation of a Bison parser of Bison
4427 grammars by making this grammar LALR(1) instead of LR(2). To
4428 facilitate the transition, this release introduces a warning.
4430 ** Revert the C++ namespace changes introduced in 1.31, as they caused too
4431 many portability hassles.
4433 ** DJGPP support added.
4435 ** Fix test suite portability problems.
4438 * Noteworthy changes in release 1.33 (2002-02-07)
4441 Groff could not be compiled for the definition of size_t was lacking
4442 under some conditions.
4448 * Noteworthy changes in release 1.32 (2002-01-23)
4450 ** Fix Yacc output file names
4452 ** Portability fixes
4454 ** Italian, Dutch translations
4457 * Noteworthy changes in release 1.31 (2002-01-14)
4461 ** GNU Gettext and %expect
4462 GNU Gettext asserts 10 s/r conflicts, but there are 7. Now that
4463 Bison dies on incorrect %expectations, we fear there will be
4464 too many bug reports for Gettext, so _for the time being_, %expect
4465 does not trigger an error when the input file is named "plural.y".
4467 ** Use of alloca in parsers
4468 If YYSTACK_USE_ALLOCA is defined to 0, then the parsers will use
4469 malloc exclusively. Since 1.29, but was not NEWS'ed.
4471 alloca is used only when compiled with GCC, to avoid portability
4474 ** yyparse now returns 2 if memory is exhausted; formerly it dumped core.
4476 ** When the generated parser lacks debugging code, YYDEBUG is now 0
4477 (as POSIX requires) instead of being undefined.
4480 Bison has always permitted actions such as { $$ = $1 }: it adds the
4481 ending semicolon. Now if in Yacc compatibility mode, the semicolon
4482 is no longer output: one has to write { $$ = $1; }.
4484 ** Better C++ compliance
4485 The output parsers try to respect C++ namespaces.
4486 [This turned out to be a failed experiment, and it was reverted later.]
4489 Fixed bugs when reporting useless nonterminals.
4492 The parsers work properly on 64 bit hosts.
4495 Some calls to strerror resulted in scrambled or missing error messages.
4498 When the number of shift/reduce conflicts is correct, don't issue
4501 ** The verbose report includes the rule line numbers.
4503 ** Rule line numbers are fixed in traces.
4505 ** Swedish translation
4508 Verbose parse error messages from the parsers are better looking.
4509 Before: parse error: unexpected `'/'', expecting `"number"' or `'-'' or `'(''
4510 Now: parse error: unexpected '/', expecting "number" or '-' or '('
4512 ** Fixed parser memory leaks.
4513 When the generated parser was using malloc to extend its stacks, the
4514 previous allocations were not freed.
4516 ** Fixed verbose output file.
4517 Some newlines were missing.
4518 Some conflicts in state descriptions were missing.
4520 ** Fixed conflict report.
4521 Option -v was needed to get the result.
4525 Mismatches are errors, not warnings.
4527 ** Fixed incorrect processing of some invalid input.
4529 ** Fixed CPP guards: 9foo.h uses BISON_9FOO_H instead of 9FOO_H.
4531 ** Fixed some typos in the documentation.
4533 ** %token MY_EOF 0 is supported.
4534 Before, MY_EOF was silently renumbered as 257.
4536 ** doc/refcard.tex is updated.
4538 ** %output, %file-prefix, %name-prefix.
4542 New, aliasing "--output-file".
4545 * Noteworthy changes in release 1.30 (2001-10-26)
4547 ** "--defines" and "--graph" have now an optional argument which is the
4548 output file name. "-d" and "-g" do not change; they do not take any
4551 ** "%source_extension" and "%header_extension" are removed, failed
4554 ** Portability fixes.
4557 * Noteworthy changes in release 1.29 (2001-09-07)
4559 ** The output file does not define const, as this caused problems when used
4560 with common autoconfiguration schemes. If you still use ancient compilers
4561 that lack const, compile with the equivalent of the C compiler option
4562 "-Dconst=". Autoconf's AC_C_CONST macro provides one way to do this.
4564 ** Added "-g" and "--graph".
4566 ** The Bison manual is now distributed under the terms of the GNU FDL.
4568 ** The input and the output files has automatically a similar extension.
4570 ** Russian translation added.
4572 ** NLS support updated; should hopefully be less troublesome.
4574 ** Added the old Bison reference card.
4576 ** Added "--locations" and "%locations".
4578 ** Added "-S" and "--skeleton".
4580 ** "%raw", "-r", "--raw" is disabled.
4582 ** Special characters are escaped when output. This solves the problems
4583 of the #line lines with path names including backslashes.
4586 "%yacc", "%fixed_output_files", "%defines", "%no_parser", "%verbose",
4587 "%debug", "%source_extension" and "%header_extension".
4590 Automatic location tracking.
4593 * Noteworthy changes in release 1.28 (1999-07-06)
4595 ** Should compile better now with K&R compilers.
4599 ** Fixed a problem with escaping the double quote character.
4601 ** There is now a FAQ.
4604 * Noteworthy changes in release 1.27
4606 ** The make rule which prevented bison.simple from being created on
4607 some systems has been fixed.
4610 * Noteworthy changes in release 1.26
4612 ** Bison now uses Automake.
4614 ** New mailing lists: <bug-bison@gnu.org> and <help-bison@gnu.org>.
4616 ** Token numbers now start at 257 as previously documented, not 258.
4618 ** Bison honors the TMPDIR environment variable.
4620 ** A couple of buffer overruns have been fixed.
4622 ** Problems when closing files should now be reported.
4624 ** Generated parsers should now work even on operating systems which do
4625 not provide alloca().
4628 * Noteworthy changes in release 1.25 (1995-10-16)
4630 ** Errors in the input grammar are not fatal; Bison keeps reading
4631 the grammar file, and reports all the errors found in it.
4633 ** Tokens can now be specified as multiple-character strings: for
4634 example, you could use "<=" for a token which looks like <=, instead
4635 of choosing a name like LESSEQ.
4637 ** The %token_table declaration says to write a table of tokens (names
4638 and numbers) into the parser file. The yylex function can use this
4639 table to recognize multiple-character string tokens, or for other
4642 ** The %no_lines declaration says not to generate any #line preprocessor
4643 directives in the parser file.
4645 ** The %raw declaration says to use internal Bison token numbers, not
4646 Yacc-compatible token numbers, when token names are defined as macros.
4648 ** The --no-parser option produces the parser tables without including
4649 the parser engine; a project can now use its own parser engine.
4650 The actions go into a separate file called NAME.act, in the form of
4651 a switch statement body.
4654 * Noteworthy changes in release 1.23
4656 The user can define YYPARSE_PARAM as the name of an argument to be
4657 passed into yyparse. The argument should have type void *. It should
4658 actually point to an object. Grammar actions can access the variable
4659 by casting it to the proper pointer type.
4661 Line numbers in output file corrected.
4664 * Noteworthy changes in release 1.22
4666 --help option added.
4669 * Noteworthy changes in release 1.20
4671 Output file does not redefine const for C++.
4675 LocalWords: yacc YYBACKUP glr GCC lalr ArrayIndexOutOfBoundsException nullptr
4676 LocalWords: cplusplus liby rpl fprintf mfcalc Wyacc stmt cond expr mk sym lr
4677 LocalWords: IELR ielr Lookahead YYERROR nonassoc LALR's api lookaheads yychar
4678 LocalWords: destructor lookahead YYRHSLOC YYLLOC Rhs ifndef YYFAIL cpp sr rr
4679 LocalWords: preprocessor initializer Wno Wnone Werror FreeBSD prec livelocks
4680 LocalWords: Solaris AIX UX RHEL Tru LHS gcc's Wundef YYENABLE NLS YYLTYPE VCG
4681 LocalWords: yyerror cpp's Wunused yylval yylloc prepend yyparse yylex yypush
4682 LocalWords: Graphviz xml nonterminals midrule destructor's YYSTYPE typedef ly
4683 LocalWords: CHR chr printf stdout namespace preprocessing enum pre include's
4684 LocalWords: YYRECOVERING nonfree destructors YYABORT YYACCEPT params enums de
4685 LocalWords: struct yystype DJGPP lex param Haible NUM alloca YYSTACK NUL goto
4686 LocalWords: YYMAXDEPTH Unescaped UCNs YYLTYPE's yyltype typedefs inline Yaccs
4687 LocalWords: Heriyanto Reenable dprec Hilfinger Eggert MYEOF Folle Menezes EOF
4688 LocalWords: Lackovic define's itemset Groff Gettext malloc NEWS'ed YYDEBUG YY
4689 LocalWords: namespaces strerror const autoconfiguration Dconst Autoconf's FDL
4690 LocalWords: Automake TMPDIR LESSEQ ylwrap endif yydebug YYTOKEN YYLSP ival hh
4691 LocalWords: extern YYTOKENTYPE TOKENTYPE yytokentype tokentype STYPE lval pdf
4692 LocalWords: lang yyoutput dvi html ps POSIX lvalp llocp Wother nterm arg init
4693 LocalWords: TOK calc yyo fval Wconflicts parsers yystackp yyval yynerrs
4694 LocalWords: Théophile Ranquet Santet fno fnone stype associativity Tolmer
4695 LocalWords: Wprecedence Rassoul Wempty Paolo Bonzini parser's Michiel loc
4696 LocalWords: redeclaration sval fcaret reentrant XSLT xsl Wmaybe yyvsp Tedi
4697 LocalWords: pragmas noreturn untyped Rozenman unexpanded Wojciech Polak
4698 LocalWords: Alexandre MERCHANTABILITY yytype emplace ptr automove lvalues
4699 LocalWords: nonterminal yy args Pragma dereference yyformat rhs docdir bw
4700 LocalWords: Redeclarations rpcalc Autoconf YFLAGS Makefiles PROG DECL num
4701 LocalWords: Heimbigner AST src ast Makefile srcdir MinGW xxlex XXSTYPE CVE
4702 LocalWords: XXLTYPE strictfp IDEs ffixit fdiagnostics parseable fixits
4703 LocalWords: Wdeprecated yytext Variadic variadic yyrhs yyphrs RCS README
4704 LocalWords: noexcept constexpr ispell american deprecations backend Teoh
4705 LocalWords: YYPRINT Mangold Bonzini's Wdangling exVal baz checkable gcc
4706 LocalWords: fsanitize Vogelsgesang lis redeclared stdint automata yytname
4707 LocalWords: yysymbol yytnamerr yyreport ctx ARGMAX yysyntax stderr LPAREN
4708 LocalWords: symrec yypcontext TOKENMAX yyexpected YYEMPTY yypstate YYEOF
4709 LocalWords: autocompletion bistromathic submessages Cayuela lexcalc hoc
4710 LocalWords: yytoken YYUNDEF YYerror basename Automake's UTF ifdef ffile
4711 LocalWords: gotos readline Imbimbo Wcounterexamples Wcex Nonunifying rcex
4712 LocalWords: Vais xsltproc YYNOMEM YYLOCATION signedness YYBISON MITRE's
4713 LocalWords: libreadline YYMALLOC YYFREE MSVC redefinitions
4716 ispell-dictionary: "american"
4721 Copyright (C) 1995-2015, 2018-2021 Free Software Foundation, Inc.
4723 This file is part of Bison, the GNU Parser Generator.
4725 Permission is granted to copy, distribute and/or modify this document
4726 under the terms of the GNU Free Documentation License, Version 1.3 or
4727 any later version published by the Free Software Foundation; with no
4728 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
4729 Texts. A copy of the license is included in the "GNU Free
4730 Documentation License" file as part of this distribution.