3 * Noteworthy changes in release ?.? (????-??-??) [?]
6 * Noteworthy changes in release 3.7.90 (2021-08-13) [beta]
8 ** Backward incompatible changes
10 In conformance with the recommendations of the Graphviz team
11 (https://marc.info/?l=graphviz-devel&m=129418103126092), `-g`/`--graph`
12 now generates a *.gv file by default, instead of *.dot. A transition
15 To comply with the latest POSIX standard, in Yacc compatibility mode
16 (options `-y`/`--yacc`) Bison now generates prototypes for yyerror and
17 yylex. In some situations, this is breaking compatibility: if the user
18 has already declared these functions but with some differences (e.g., to
19 declare them as static, or to use specific attributes), the generated
20 parser will fail to compile. To disable these prototypes, #define yyerror
21 (to `yyerror`), and likewise for yylex.
23 ** Deprecated features
25 Support for the YYPRINT macro is removed. It worked only with yacc.c and
26 only for tokens. It was obsoleted by %printer, introduced in Bison 1.50
29 It has always been recommended to prefer `%define api.value.type foo` to
30 `#define YYSTYPE foo`. The latter is supported in C for compatibility
31 with Yacc, but not in C++. Warnings are now issued if `#define YYSTYPE`
32 is used in C++, and eventually support will be removed.
34 In C++ code, prefer value_type to semantic_type to denote the semantic
35 value type, which is specified by the `api.value.type` %define variable.
39 *** A skeleton for the D programming language
41 The "lalr1.d" skeleton is now officially part of Bison.
43 It was originally contributed by Oliver Mangold, based on Paolo Bonzini's
44 lalr1.java, and was improved by H. S. Teoh. Adela Vais then took over
45 maintenance and invested a lot of efforts to complete, test and document
48 It now supports all the bells and whistles of the other deterministic
49 parsers, which include: pull/push interfaces, verbose and custom error
50 messages, lookahead correction, token constructors, internationalization,
51 locations, printers, token and symbol prefixes, etc.
53 Two examples demonstrate the D parsers: a basic one (examples/d/simple),
54 and an advanced one (examples/d/calc).
56 *** Option -H, --header and directive %header
58 The option `-H`/`--header` supersedes the option `--defines`, and the
59 directive %header supersedes %defines. Both `--defines` and `%defines`
60 are, of course, maintained for backward compatibility.
64 Since version 2.4 Bison can be used to generate HTML reports. However it
65 was a two-step process: first bison must be invoked with option `--xml`,
66 and then xsltproc must be run to the convert the XML reports into HTML.
68 The new option `--html` combines these steps. The xsltproc program must
71 *** A C++ native GLR parser
73 A new version of the C++ GLR parser was added: "glr2.cc". It generates
74 "true C++11", instead of a C++ wrapper around a C parser as does the
75 existing "glr.cc" parser. As a first significant consequence, it supports
76 `%define api.value.type variant`, contrary to glr.cc.
78 It should be upward compatible in terms of interface, feature and
79 performance to "glr.cc". To try it out, simply use
83 It will eventually replace "glr.cc". However we need user feedback on
84 this skeleton. _Please_ report your results and comments about it.
88 Counterexamples now show the rule numbers, and always show ε for rules
89 with an empty right-hand side. For instance
101 *** Lookahead correction in Java
103 The Java skeleton (lalr1.java) now supports LAC, via the `parse.lac`
106 *** Abort parsing for memory exhaustion (C)
108 User actions may now use `YYNOMEM` (similar to `YYACCEPT` and `YYABORT`)
109 to abort the current parse with memory exhaustion.
111 *** Printing locations in debug traces (C)
113 The `YYLOCATION_PRINT(File, Loc)` macro prints a location. It is defined
114 when (i) locations are enabled, (ii) the default type for locations is
115 used, (iii) debug traces are enabled, and (iv) `YYLOCATION_PRINT` is not
118 Users may define `YYLOCATION_PRINT` to cover other cases.
122 There were no debug traces for deferred calls to user actions. They are
126 * Noteworthy changes in release 3.7.6 (2021-03-08) [stable]
130 *** Reused Push Parsers
132 When a push-parser state structure is used for multiple parses, it was
133 possible for some state to leak from one run into the following one.
135 *** Fix Table Generation
137 In some very rare conditions, when there are many useless tokens, it was
138 possible to generate incorrect parsers.
141 * Noteworthy changes in release 3.7.5 (2021-01-24) [stable]
145 *** Counterexample Generation
147 In some cases counterexample generation could crash. This is fixed.
149 *** Fix Table Generation
151 In some very rare conditions, when there are many useless tokens, it was
152 possible to generate incorrect parsers.
154 *** GLR parsers now support %merge together with api.value.type=union.
156 *** C++ parsers use noexcept in more places.
158 *** Generated parsers avoid some warnings about signedness issues.
160 *** C-language parsers now avoid warnings from pedantic clang.
162 *** C-language parsers now work around quirks of HP-UX 11.23 (2003).
165 * Noteworthy changes in release 3.7.4 (2020-11-14) [stable]
169 *** Bug fixes in yacc.c
171 In Yacc mode, all the tokens are defined twice: once as an enum, and then
172 as a macro. YYEMPTY was missing its macro.
174 *** Bug fixes in lalr1.cc
176 The lalr1.cc skeleton used to emit internal assertions (using YY_ASSERT)
177 even when the `parse.assert` %define variable is not enabled. It no
180 The private internal macro YY_ASSERT now obeys the `api.prefix` %define
183 When there is a very large number of tokens, some assertions could be long
184 enough to hit arbitrary limits in Visual C++. They have been rewritten to
185 work around this limitation.
189 The YYBISON macro in generated "regular C parsers" (from the "yacc.c"
190 skeleton) used to be defined to 1. It is now defined to the version of
191 Bison as an integer (e.g., 30704 for version 3.7.4).
194 * Noteworthy changes in release 3.7.3 (2020-10-13) [stable]
198 Fix concurrent build issues.
200 The bison executable is no longer linked uselessly against libreadline.
202 Fix incorrect use of yytname in glr.cc.
205 * Noteworthy changes in release 3.7.2 (2020-09-05) [stable]
207 This release of Bison fixes all known bugs reported for Bison in MITRE's
208 Common Vulnerabilities and Exposures (CVE) system. These vulnerabilities
209 are only about bison-the-program itself, not the generated code.
211 Although these bugs are typically irrelevant to how Bison is used, they
212 are worth fixing if only to give users peace of mind.
214 There is no known vulnerability in the generated parsers.
218 Fix concurrent build issues (introduced in Bison 3.5).
220 Push parsers always use YYMALLOC/YYFREE (no direct calls to malloc/free).
222 Fix portability issues of the test suite, and of bison itself.
224 Some unlikely crashes found by fuzzing have been fixed. This is only
225 about bison itself, not the generated parsers.
228 * Noteworthy changes in release 3.7.1 (2020-08-02) [stable]
232 Crash when a token alias contains a NUL byte.
234 Portability issues with libtextstyle.
236 Portability issues of Bison itself with MSVC.
240 Improvements and fixes in the documentation.
242 More precise location about symbol type redefinitions.
245 * Noteworthy changes in release 3.7 (2020-07-23) [stable]
247 ** Deprecated features
249 The YYPRINT macro, which works only with yacc.c and only for tokens, was
250 obsoleted long ago by %printer, introduced in Bison 1.50 (November 2002).
251 It is deprecated and its support will be removed eventually.
253 In conformance with the recommendations of the Graphviz team, in the next
254 version Bison the option `--graph` will generate a *.gv file by default,
255 instead of *.dot. A transition started in Bison 3.4.
259 *** Counterexample Generation
261 Contributed by Vincent Imbimbo.
263 When given `-Wcounterexamples`/`-Wcex`, bison will now output
264 counterexamples for conflicts.
266 **** Unifying Counterexamples
268 Unifying counterexamples are strings which can be parsed in two ways due
269 to the conflict. For example on a grammar that contains the usual
270 "dangling else" ambiguity:
273 else.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
274 else.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
277 else.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
278 else.y: warning: shift/reduce conflict on token "else" [-Wcounterexamples]
279 Example: "if" exp "then" "if" exp "then" exp • "else" exp
282 ↳ "if" exp "then" exp
283 ↳ "if" exp "then" exp • "else" exp
284 Example: "if" exp "then" "if" exp "then" exp • "else" exp
287 ↳ "if" exp "then" exp "else" exp
288 ↳ "if" exp "then" exp •
290 When text styling is enabled, colors are used in the examples and the
291 derivations to highlight the structure of both analyses. In this case,
293 "if" exp "then" [ "if" exp "then" exp • ] "else" exp
297 "if" exp "then" [ "if" exp "then" exp • "else" exp ]
300 The counterexamples are "focused", in two different ways. First, they do
301 not clutter the output with all the derivations from the start symbol,
302 rather they start on the "conflicted nonterminal". They go straight to the
303 point. Second, they don't "expand" nonterminal symbols uselessly.
305 **** Nonunifying Counterexamples
307 In the case of the dangling else, Bison found an example that can be
308 parsed in two ways (therefore proving that the grammar is ambiguous).
309 When it cannot find such an example, it instead generates two examples
310 that are the same up until the dot:
313 foo.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
314 foo.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
315 foo.y:4.4-7: warning: rule useless in parser due to conflicts [-Wother]
320 foo.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
321 foo.y: warning: shift/reduce conflict on token ID [-Wcounterexamples]
322 First example: expr • ID ',' ID $end
329 Second example: expr • ID $end
335 foo.y:4.4-7: warning: rule useless in parser due to conflicts [-Wother]
339 In these cases, the parser usually doesn't have enough lookahead to
340 differentiate the two given examples.
344 Counterexamples are also included in the report when given
345 `--report=counterexamples`/`-rcex` (or `--report=all`), with more
350 1 exp: "if" exp "then" exp • [$end, "then", "else"]
351 2 | "if" exp "then" exp • "else" exp
353 "else" shift, and go to state 8
355 "else" [reduce using rule 1 (exp)]
356 $default reduce using rule 1 (exp)
358 shift/reduce conflict on token "else":
359 1 exp: "if" exp "then" exp •
360 2 exp: "if" exp "then" exp • "else" exp
361 Example: "if" exp "then" "if" exp "then" exp • "else" exp
364 ↳ "if" exp "then" exp
365 ↳ "if" exp "then" exp • "else" exp
366 Example: "if" exp "then" "if" exp "then" exp • "else" exp
369 ↳ "if" exp "then" exp "else" exp
370 ↳ "if" exp "then" exp •
372 *** File prefix mapping
374 Contributed by Joshua Watt.
376 Bison learned a new argument, `--file-prefix-map OLD=NEW`. Any file path
377 in the output (specifically `#line` directives and `#ifdef` header guards)
378 that begins with the prefix OLD will have it replaced with the prefix NEW,
379 similar to the `-ffile-prefix-map` in GCC. This option can be used to
380 make bison output reproducible.
386 When text styling is enabled and the terminal supports it, the warnings
387 now include hyperlinks to the documentation.
389 *** Relocatable installation
391 When installed to be relocatable (via `configure --enable-relocatable`),
392 bison will now also look for a relocated m4.
396 The `filename_type` %define variable was renamed `api.filename.type`.
399 %define filename_type "symbol"
403 %define api.filename.type {symbol}
405 (Or let `bison --update` do it for you).
407 It now defaults to `const std::string` instead of `std::string`.
409 *** Deprecated %define variable names
411 The following variables have been renamed for consistency. Backward
412 compatibility is ensured, but upgrading is recommended.
414 filename_type -> api.filename.type
415 package -> api.package
417 *** Push parsers no longer clear their state when parsing is finished
419 Previously push-parsers cleared their state when parsing was finished (on
420 success and on failure). This made it impossible to check if there were
421 parse errors, since `yynerrs` was also reset. This can be especially
422 troublesome when used in autocompletion, since a parser with error
423 recovery would suggest (irrelevant) expected tokens even if there were
426 Now the parser state can be examined when parsing is finished. The parser
427 state is reset when starting a new parse.
433 The bistromathic demonstrates %param and how to quote sources in the error
437 1.5-7: syntax error: expected end of file or + or - or * or / or ^ before number
443 *** Include the generated header (yacc.c)
445 Historically, when --defines was used, bison generated a header and pasted
446 an exact copy of it into the generated parser implementation file. Since
447 Bison 3.4 it is possible to specify that the header should be `#include`d,
448 and how. For instance
450 %define api.header.include {"parse.h"}
454 %define api.header.include {<parser/parse.h>}
456 Now api.header.include defaults to `"header-basename"`, as was intended in
457 Bison 3.4, where `header-basename` is the basename of the generated
458 header. This is disabled when the generated header is `y.tab.h`, to
459 comply with Automake's ylwrap.
461 *** String aliases are faithfully propagated
463 Bison used to interpret user strings (i.e., decoding backslash escapes)
464 when reading them, and to escape them (i.e., issue non-printable
465 characters as backslash escapes, taking the locale into account) when
466 outputting them. As a consequence non-ASCII strings (say in UTF-8) ended
467 up "ciphered" as sequences of backslash escapes. This happened not only
468 in the generated sources (where the compiler will reinterpret them), but
469 also in all the generated reports (text, xml, html, dot, etc.). Reports
470 were therefore not readable when string aliases were not pure ASCII.
471 Worse yet: the output depended on the user's locale.
473 Now Bison faithfully treats the string aliases exactly the way the user
474 spelled them. This fixes all the aforementioned problems. However, now,
475 string aliases semantically equivalent but syntactically different (e.g.,
476 "A", "\x41", "\101") are considered to be different.
478 *** Crash when generating IELR
480 An old, well hidden, bug in the generation of IELR parsers was fixed.
483 * Noteworthy changes in release 3.6.4 (2020-06-15) [stable]
487 In glr.cc some internal macros leaked in the user's code, and could damage
488 access to the token kinds.
491 * Noteworthy changes in release 3.6.3 (2020-06-03) [stable]
495 Incorrect comments in the generated parsers.
497 Warnings in push parsers (yacc.c).
499 Incorrect display of gotos in LAC traces (lalr1.cc).
502 * Noteworthy changes in release 3.6.2 (2020-05-17) [stable]
506 Some tests were fixed.
508 When token aliases contain comment delimiters:
510 %token FOO "/* foo */"
512 bison used to emit "nested" comments, which is invalid C.
515 * Noteworthy changes in release 3.6.1 (2020-05-10) [stable]
519 Restored ANSI-C compliance in yacc.c.
521 GNU readline portability issues.
523 In C++, yy::parser::symbol_name is now a public member, as was intended.
527 In C++, yy::parser::symbol_type now has a public name() member function.
530 * Noteworthy changes in release 3.6 (2020-05-08) [stable]
532 ** Backward incompatible changes
534 TL;DR: replace "#define YYERROR_VERBOSE 1" by "%define parse.error verbose".
536 The YYERROR_VERBOSE macro is no longer supported; the parsers that still
537 depend on it will now produce Yacc-like error messages (just "syntax
538 error"). It was superseded by the "%error-verbose" directive in Bison
539 1.875 (2003-01-01). Bison 2.6 (2012-07-19) clearly announced that support
540 for YYERROR_VERBOSE would be removed. Note that since Bison 3.0
541 (2013-07-25), "%error-verbose" is deprecated in favor of "%define
542 parse.error verbose".
544 ** Deprecated features
546 The YYPRINT macro, which works only with yacc.c and only for tokens, was
547 obsoleted long ago by %printer, introduced in Bison 1.50 (November 2002).
548 It is deprecated and its support will be removed eventually.
552 *** Improved syntax error messages
554 Two new values for the %define parse.error variable offer more control to
555 the user. Available in all the skeletons (C, C++, Java).
557 **** %define parse.error detailed
559 The behavior of "%define parse.error detailed" is closely resembling that
560 of "%define parse.error verbose" with a few exceptions. First, it is safe
561 to use non-ASCII characters in token aliases (with 'verbose', the result
562 depends on the locale with which bison was run). Second, a yysymbol_name
563 function is exposed to the user, instead of the yytnamerr function and the
564 yytname table. Third, token internationalization is supported (see
567 **** %define parse.error custom
569 With this directive, the user forges and emits the syntax error message
570 herself by defining the yyreport_syntax_error function. A new type,
571 yypcontext_t, captures the circumstances of the error, and provides the
572 user with functions to get details, such as yypcontext_expected_tokens to
573 get the list of expected token kinds.
575 A possible implementation of yyreport_syntax_error is:
578 yyreport_syntax_error (const yypcontext_t *ctx)
581 YY_LOCATION_PRINT (stderr, *yypcontext_location (ctx));
582 fprintf (stderr, ": syntax error");
583 // Report the tokens expected at this point.
585 enum { TOKENMAX = 10 };
586 yysymbol_kind_t expected[TOKENMAX];
587 int n = yypcontext_expected_tokens (ctx, expected, TOKENMAX);
589 // Forward errors to yyparse.
592 for (int i = 0; i < n; ++i)
593 fprintf (stderr, "%s %s",
594 i == 0 ? ": expected" : " or", yysymbol_name (expected[i]));
596 // Report the unexpected token.
598 yysymbol_kind_t lookahead = yypcontext_token (ctx);
599 if (lookahead != YYSYMBOL_YYEMPTY)
600 fprintf (stderr, " before %s", yysymbol_name (lookahead));
602 fprintf (stderr, "\n");
606 **** Token aliases internationalization
608 When the %define variable parse.error is set to `custom` or `detailed`,
609 one may specify which token aliases are to be translated using _(). For
621 In that case the user must define _() and N_(), and yysymbol_name returns
622 the translated symbol (i.e., it returns '_("variable")' rather that
623 '"variable"'). In Java, the user must provide an i18n() function.
625 *** List of expected tokens (yacc.c)
627 Push parsers may invoke yypstate_expected_tokens at any point during
628 parsing (including even before submitting the first token) to get the list
629 of possible tokens. This feature can be used to propose autocompletion
630 (see below the "bistromathic" example).
632 It makes little sense to use this feature without enabling LAC (lookahead
635 *** Returning the error token
637 When the scanner returns an invalid token or the undefined token
638 (YYUNDEF), the parser generates an error message and enters error
639 recovery. Because of that error message, most scanners that find lexical
640 errors generate an error message, and then ignore the invalid input
641 without entering the error-recovery.
643 The scanners may now return YYerror, the error token, to enter the
644 error-recovery mode without triggering an additional error message. See
645 the bistromathic for an example.
647 *** Deep overhaul of the symbol and token kinds
649 To avoid the confusion with types in programming languages, we now refer
650 to token and symbol "kinds" instead of token and symbol "types". The
651 documentation and error messages have been revised.
653 All the skeletons have been updated to use dedicated enum types rather
654 than integral types. Special symbols are now regular citizens, instead of
655 being declared in ad hoc ways.
659 The "token kind" is what is returned by the scanner, e.g., PLUS, NUMBER,
660 LPAREN, etc. While backward compatibility is of course ensured, users are
661 nonetheless invited to replace their uses of "enum yytokentype" by
664 This type now also includes tokens that were previously hidden: YYEOF (end
665 of input), YYUNDEF (undefined token), and YYerror (error token). They
666 now have string aliases, internationalized when internationalization is
667 enabled. Therefore, by default, error messages now refer to "end of file"
668 (internationalized) rather than the cryptic "$end", or to "invalid token"
669 rather than "$undefined".
671 Therefore in most cases it is now useless to define the end-of-line token
674 %token T_EOF 0 "end of file"
676 Rather simply use "YYEOF" in your scanner.
680 The "symbol kinds" is what the parser actually uses. (Unless the
681 api.token.raw %define variable is used, the symbol kind of a terminal
682 differs from the corresponding token kind.)
684 They are now exposed as a enum, "yysymbol_kind_t".
686 This allows users to tailor the error messages the way they want, or to
687 process some symbols in a specific way in autocompletion (see the
688 bistromathic example below).
690 *** Modernize display of explanatory statements in diagnostics
692 Since Bison 2.7, output was indented four spaces for explanatory
693 statements. For example:
695 input.y:2.7-13: error: %type redeclaration for exp
696 input.y:1.7-11: previous declaration
698 Since the introduction of caret-diagnostics, it became less clear. This
699 indentation has been removed and submessages are displayed similarly as in
702 input.y:2.7-13: error: %type redeclaration for exp
703 2 | %type <float> exp
705 input.y:1.7-11: note: previous declaration
709 Contributed by Victor Morales Cayuela.
713 The token and symbol kinds are yy::parser::token_kind_type and
714 yy::parser::symbol_kind_type.
716 The symbol_type::kind() member function allows to get the kind of a
717 symbol. This can be used to write unit tests for scanners, e.g.,
719 yy::parser::symbol_type t = make_NUMBER ("123");
720 assert (t.kind () == yy::parser::symbol_kind::S_NUMBER);
721 assert (t.value.as<int> () == 123);
727 In order to avoid ambiguities with "type" as in "typing", we now refer to
728 the "token kind" (e.g., `PLUS`, `NUMBER`, etc.) rather than the "token
729 type". We now also refer to the "symbol type" (e.g., `PLUS`, `expr`,
734 There are now examples/java: a very simple calculator, and a more complete
735 one (push-parser, location tracking, and debug traces).
737 The lexcalc example (a simple example in C based on Flex and Bison) now
738 also demonstrates location tracking.
741 A new C example, bistromathic, is a fully featured interactive calculator
742 using many Bison features: pure interface, push parser, autocompletion
743 based on the current parser state (using yypstate_expected_tokens),
744 location tracking, internationalized custom error messages, lookahead
745 correction, rich debug traces, etc.
747 It shows how to depend on the symbol kinds to tailor autocompletion. For
748 instance it recognizes the symbol kind "VARIABLE" to propose
749 autocompletion on the existing variables, rather than of the word
753 * Noteworthy changes in release 3.5.4 (2020-04-05) [stable]
755 ** WARNING: Future backward-incompatibilities!
757 TL;DR: replace "#define YYERROR_VERBOSE 1" by "%define parse.error verbose".
759 Bison 3.6 will no longer support the YYERROR_VERBOSE macro; the parsers
760 that still depend on it will produce Yacc-like error messages (just
761 "syntax error"). It was superseded by the "%error-verbose" directive in
762 Bison 1.875 (2003-01-01). Bison 2.6 (2012-07-19) clearly announced that
763 support for YYERROR_VERBOSE would be removed. Note that since Bison 3.0
764 (2013-07-25), "%error-verbose" is deprecated in favor of "%define
765 parse.error verbose".
769 Fix portability issues of the package itself on old compilers.
771 Fix api.token.raw support in Java.
774 * Noteworthy changes in release 3.5.3 (2020-03-08) [stable]
778 Error messages could quote lines containing zero-width characters (such as
779 \005) with incorrect styling. Fixes for similar issues with unexpectedly
780 short lines (e.g., the file was changed between parsing and diagnosing).
782 Some unlikely crashes found by fuzzing have been fixed. This is only
783 about bison itself, not the generated parsers.
786 * Noteworthy changes in release 3.5.2 (2020-02-13) [stable]
790 Portability issues and minor cosmetic issues.
792 The lalr1.cc skeleton properly rejects unsupported values for parse.lac
796 * Noteworthy changes in release 3.5.1 (2020-01-19) [stable]
802 Fix compiler warnings.
805 * Noteworthy changes in release 3.5 (2019-12-11) [stable]
807 ** Backward incompatible changes
809 Lone carriage-return characters (aka \r or ^M) in the grammar files are no
810 longer treated as end-of-lines. This changes the diagnostics, and in
811 particular their locations.
813 In C++, line numbers and columns are now represented as 'int' not
814 'unsigned', so that integer overflow on positions is easily checkable via
815 'gcc -fsanitize=undefined' and the like. This affects the API for
816 positions. The default position and location classes now expose
817 'counter_type' (int), used to define line and column numbers.
819 ** Deprecated features
821 The YYPRINT macro, which works only with yacc.c and only for tokens, was
822 obsoleted long ago by %printer, introduced in Bison 1.50 (November 2002).
823 It is deprecated and its support will be removed eventually.
827 *** Lookahead correction in C++
829 Contributed by Adrian Vogelsgesang.
831 The C++ deterministic skeleton (lalr1.cc) now supports LAC, via the
832 %define variable parse.lac.
834 *** Variable api.token.raw: Optimized token numbers (all skeletons)
836 In the generated parsers, tokens have two numbers: the "external" token
837 number as returned by yylex (which starts at 257), and the "internal"
838 symbol number (which starts at 3). Each time yylex is called, a table
839 lookup maps the external token number to the internal symbol number.
841 When the %define variable api.token.raw is set, tokens are assigned their
842 internal number, which saves one table lookup per token, and also saves
843 the generation of the mapping table.
845 The gain is typically moderate, but in extreme cases (very simple user
846 actions), a 10% improvement can be observed.
848 *** Generated parsers use better types for states
850 Stacks now use the best integral type for state numbers, instead of always
851 using 15 bits. As a result "small" parsers now have a smaller memory
852 footprint (they use 8 bits), and there is support for large automata (16
853 bits), and extra large (using int, i.e., typically 31 bits).
855 *** Generated parsers prefer signed integer types
857 Bison skeletons now prefer signed to unsigned integer types when either
858 will do, as the signed types are less error-prone and allow for better
859 checking with 'gcc -fsanitize=undefined'. Also, the types chosen are now
860 portable to unusual machines where char, short and int are all the same
861 width. On non-GNU platforms this may entail including <limits.h> and (if
862 available) <stdint.h> to define integer types and constants.
864 *** A skeleton for the D programming language
866 For the last few releases, Bison has shipped a stealth experimental
867 skeleton: lalr1.d. It was first contributed by Oliver Mangold, based on
868 Paolo Bonzini's lalr1.java, and was cleaned and improved thanks to
871 However, because nobody has committed to improving, testing, and
872 documenting this skeleton, it is not clear that it will be supported in
875 The lalr1.d skeleton *is functional*, and works well, as demonstrated in
876 examples/d/calc.d. Please try it, enjoy it, and... commit to support it.
878 *** Debug traces in Java
880 The Java backend no longer emits code and data for parser tracing if the
881 %define variable parse.trace is not defined.
885 *** New diagnostic: -Wdangling-alias
887 String literals, which allow for better error messages, are (too)
888 liberally accepted by Bison, which might result in silent errors. For
891 %type <exVal> cond "condition"
893 does not define "condition" as a string alias to 'cond' (nonterminal
894 symbols do not have string aliases). It is rather equivalent to
897 %token <exVal> "condition"
899 i.e., it gives the type 'exVal' to the "condition" token, which was
900 clearly not the intention.
902 Also, because string aliases need not be defined, typos such as "baz"
903 instead of "bar" will be not reported.
905 The option `-Wdangling-alias` catches these situations. On
908 %type <ival> foo "foo"
912 bison -Wdangling-alias reports
914 warning: string literal not attached to a symbol
915 | %type <ival> foo "foo"
917 warning: string literal not attached to a symbol
921 The `-Wall` option does not (yet?) include `-Wdangling-alias`.
923 *** Better POSIX Yacc compatibility diagnostics
925 POSIX Yacc restricts %type to nonterminals. This is now diagnosed by
929 %type <ival> TOKEN1 TOKEN2 't'
936 input.y:2.15-20: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
937 2 | %type <ival> TOKEN1 TOKEN2 't'
939 input.y:2.29-31: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
940 2 | %type <ival> TOKEN1 TOKEN2 't'
942 input.y:2.22-27: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
943 2 | %type <ival> TOKEN1 TOKEN2 't'
946 *** Diagnostics with insertion
948 The diagnostics now display the suggestion below the underlined source.
949 Replacement for undeclared symbols are now also suggested.
956 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'?
960 foo.y:2.16: warning: empty rule without %empty [-Wempty-rule]
964 foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
966 *** Diagnostics about long lines
968 Quoted sources may now be truncated to fit the screen. For instance, on a
969 30-column wide terminal:
976 foo.y:1.34-36: warning: symbol FOO redeclared [-Wother]
979 foo.y:1.8-10: previous declaration
982 foo.y:1.62-64: warning: symbol FOO redeclared [-Wother]
985 foo.y:1.8-10: previous declaration
991 *** Debugging glr.c and glr.cc
993 The glr.c skeleton always had asserts to check its own behavior (not the
994 user's). These assertions are now under the control of the parse.assert
995 %define variable (disabled by default).
999 Several new compiler warnings in the generated output have been avoided.
1000 Some unused features are no longer emitted. Cleaner generated code in
1005 Portability issues in the test suite.
1007 In theory, parsers using %nonassoc could crash when reporting verbose
1008 error messages. This unlikely bug has been fixed.
1010 In Java, %define api.prefix was ignored. It now behaves as expected.
1013 * Noteworthy changes in release 3.4.2 (2019-09-12) [stable]
1017 In some cases, when warnings are disabled, bison could emit tons of white
1018 spaces as diagnostics.
1020 When running out of memory, bison could crash (found by fuzzing).
1022 When defining twice the EOF token, bison would crash.
1024 New warnings from recent compilers have been addressed in the generated
1025 parsers (yacc.c, glr.c, glr.cc).
1027 When lone carriage-return characters appeared in the input file,
1028 diagnostics could hang forever.
1031 * Noteworthy changes in release 3.4.1 (2019-05-22) [stable]
1038 * Noteworthy changes in release 3.4 (2019-05-19) [stable]
1040 ** Deprecated features
1042 The %pure-parser directive is deprecated in favor of '%define api.pure'
1043 since Bison 2.3b (2008-05-27), but no warning was issued; there is one
1044 now. Note that since Bison 2.7 you are strongly encouraged to use
1045 '%define api.pure full' instead of '%define api.pure'.
1049 *** Colored diagnostics
1051 As an experimental feature, diagnostics are now colored, controlled by the
1052 new options --color and --style.
1054 To use them, install the libtextstyle library before configuring Bison.
1055 It is available from
1057 https://alpha.gnu.org/gnu/gettext/
1061 https://alpha.gnu.org/gnu/gettext/libtextstyle-0.8.tar.gz
1063 The option --color supports the following arguments:
1064 - always, yes: Enable colors.
1065 - never, no: Disable colors.
1066 - auto, tty (default): Enable colors if the output device is a tty.
1068 To customize the styles, create a CSS file similar to
1072 .error { font-weight: 800; text-decoration: underline; }
1075 then invoke bison with --style=bison-bw.css, or set the BISON_STYLE
1076 environment variable to "bison-bw.css".
1078 *** Disabling output
1080 When given -fsyntax-only, the diagnostics are reported, but no output is
1083 The name of this option is somewhat misleading as bison does more than
1084 just checking the syntax: every stage is run (including checking for
1085 conflicts for instance), except the generation of the output files.
1087 *** Include the generated header (yacc.c)
1089 Before, when --defines is used, bison generated a header, and pasted an
1090 exact copy of it into the generated parser implementation file. If the
1091 header name is not "y.tab.h", it is now #included instead of being
1094 To use an '#include' even if the header name is "y.tab.h" (which is what
1095 happens with --yacc, or when using the Autotools' ylwrap), define
1096 api.header.include to the exact argument to pass to #include. For
1099 %define api.header.include {"parse.h"}
1103 %define api.header.include {<parser/parse.h>}
1105 *** api.location.type is now supported in C (yacc.c, glr.c)
1107 The %define variable api.location.type defines the name of the type to use
1108 for locations. When defined, Bison no longer defines YYLTYPE.
1110 This can be used in programs with several parsers to factor their
1111 definition of locations: let one of them generate them, and the others
1118 In conformance with the recommendations of the Graphviz team, if %require
1119 "3.4" (or better) is specified, the option --graph generates a *.gv file
1120 by default, instead of *.dot.
1122 *** Diagnostics overhaul
1124 Column numbers were wrong with multibyte characters, which would also
1125 result in skewed diagnostics with carets. Beside, because we were
1126 indenting the quoted source with a single space, lines with tab characters
1127 were incorrectly underlined.
1129 To address these issues, and to be clearer, Bison now issues diagnostics
1130 as GCC9 does. For instance it used to display (there's a tab before the
1133 foo.y:3.37-38: error: $2 of ‘expr’ has no declared type
1134 expr: expr '+' "number" { $$ = $1 + $2; }
1138 foo.y:3.37-38: error: $2 of ‘expr’ has no declared type
1139 3 | expr: expr '+' "number" { $$ = $1 + $2; }
1142 Other constructs now also have better locations, resulting in more precise
1145 *** Fix-it hints for %empty
1147 Running Bison with -Wempty-rules and --update will remove incorrect %empty
1148 annotations, and add the missing ones.
1150 *** Generated reports
1152 The format of the reports (parse.output) was improved for readability.
1154 *** Better support for --no-line.
1156 When --no-line is used, the generated files are now cleaner: no lines are
1157 generated instead of empty lines. Together with using api.header.include,
1158 that should help people saving the generated files into version control
1159 systems get smaller diffs.
1163 A new example in C shows an simple infix calculator with a hand-written
1164 scanner (examples/c/calc).
1166 A new example in C shows a reentrant parser (capable of recursive calls)
1167 built with Flex and Bison (examples/c/reccalc).
1169 There is a new section about the history of Yaccs and Bison.
1173 A few obscure bugs were fixed, including the second oldest (known) bug in
1174 Bison: it was there when Bison was entered in the RCS version control
1175 system, in December 1987. See the NEWS of Bison 3.3 for the previous
1179 * Noteworthy changes in release 3.3.2 (2019-02-03) [stable]
1183 Bison 3.3 failed to generate parsers for grammars with unused nonterminal
1187 * Noteworthy changes in release 3.3.1 (2019-01-27) [stable]
1191 The option -y/--yacc used to imply -Werror=yacc, which turns uses of Bison
1192 extensions into errors. It now makes them simple warnings (-Wyacc).
1195 * Noteworthy changes in release 3.3 (2019-01-26) [stable]
1197 A new mailing list was created, Bison Announce. It is low traffic, and is
1198 only about announcing new releases and important messages (e.g., polls
1199 about major decisions to make).
1201 https://lists.gnu.org/mailman/listinfo/bison-announce
1203 ** Backward incompatible changes
1205 Support for DJGPP, which has been unmaintained and untested for years, is
1208 ** Deprecated features
1210 A new feature, --update (see below) helps adjusting existing grammars to
1213 *** Deprecated directives
1215 The %error-verbose directive is deprecated in favor of '%define
1216 parse.error verbose' since Bison 3.0, but no warning was issued.
1218 The '%name-prefix "xx"' directive is deprecated in favor of '%define
1219 api.prefix {xx}' since Bison 3.0, but no warning was issued. These
1220 directives are slightly different, you might need to adjust your code.
1221 %name-prefix renames only symbols with external linkage, while api.prefix
1222 also renames types and macros, including YYDEBUG, YYTOKENTYPE,
1223 yytokentype, YYSTYPE, YYLTYPE, etc.
1225 Users of Flex that move from '%name-prefix "xx"' to '%define api.prefix
1226 {xx}' will typically have to update YY_DECL from
1228 #define YY_DECL int xxlex (YYSTYPE *yylval, YYLTYPE *yylloc)
1232 #define YY_DECL int xxlex (XXSTYPE *yylval, XXLTYPE *yylloc)
1234 *** Deprecated %define variable names
1236 The following variables, mostly related to parsers in Java, have been
1237 renamed for consistency. Backward compatibility is ensured, but upgrading
1240 abstract -> api.parser.abstract
1241 annotations -> api.parser.annotations
1242 extends -> api.parser.extends
1243 final -> api.parser.final
1244 implements -> api.parser.implements
1245 parser_class_name -> api.parser.class
1246 public -> api.parser.public
1247 strictfp -> api.parser.strictfp
1251 *** Generation of fix-its for IDEs/Editors
1253 When given the new option -ffixit (aka -fdiagnostics-parseable-fixits),
1254 bison now generates machine readable editing instructions to fix some
1255 issues. Currently, this is mostly limited to updating deprecated
1256 directives and removing duplicates. For instance:
1260 %define parser_class_name "Parser"
1261 %define api.parser.class "Parser"
1265 See the "fix-it:" lines below:
1267 $ bison -ffixit foo.y
1268 foo.y:1.1-14: warning: deprecated directive, use '%define parse.error verbose' [-Wdeprecated]
1271 fix-it:"foo.y":{1:1-1:15}:"%define parse.error verbose"
1272 foo.y:2.1-34: warning: deprecated directive, use '%define api.parser.class {Parser}' [-Wdeprecated]
1273 %define parser_class_name "Parser"
1274 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1275 fix-it:"foo.y":{2:1-2:35}:"%define api.parser.class {Parser}"
1276 foo.y:3.1-33: error: %define variable 'api.parser.class' redefined
1277 %define api.parser.class "Parser"
1278 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1279 foo.y:2.1-34: previous definition
1280 %define parser_class_name "Parser"
1281 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1282 fix-it:"foo.y":{3:1-3:34}:""
1283 foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
1285 This uses the same output format as GCC and Clang.
1287 *** Updating grammar files
1289 Fixes can be applied on the fly. The previous example ends with the
1290 suggestion to re-run bison with the option -u/--update, which results in a
1291 cleaner grammar file.
1293 $ bison --update foo.y
1295 bison: file 'foo.y' was updated (backup: 'foo.y~')
1298 %define parse.error verbose
1299 %define api.parser.class {Parser}
1303 *** Bison is now relocatable
1305 If you pass '--enable-relocatable' to 'configure', Bison is relocatable.
1307 A relocatable program can be moved or copied to a different location on
1308 the file system. It can also be used through mount points for network
1309 sharing. It is possible to make symbolic links to the installed and moved
1310 programs, and invoke them through the symbolic link.
1312 *** %expect and %expect-rr modifiers on individual rules
1314 One can now document (and check) which rules participate in shift/reduce
1315 and reduce/reduce conflicts. This is particularly important GLR parsers,
1316 where conflicts are a normal occurrence. For example,
1332 | argument_list ',' expression
1337 Looking at the output from -v, one can see that the shift/reduce conflict
1338 here is due to the fact that the parser does not know whether to reduce
1339 arguments to argument_list until it sees the token _after_ the following
1340 ','. By marking the rule with %expect 1 (because there is a conflict in
1341 one state), we document the source of the 1 overall shift/reduce conflict.
1343 In GLR parsers, we can use %expect-rr in a rule for reduce/reduce
1344 conflicts. In this case, we mark each of the conflicting rules. For
1353 target_list '=' expr ';'
1359 | target ',' target_list
1368 | expr ',' expr_list
1376 In a statement such as
1380 the parser must reduce x to a target or an expr, but does not know which
1381 until it sees the '='. So we notate the two possible reductions to
1382 indicate that each conflicts in one rule.
1384 This feature needs user feedback, and might evolve in the future.
1386 *** C++: Actual token constructors
1388 When variants and token constructors are enabled, in addition to the
1389 type-safe named token constructors (make_ID, make_INT, etc.), we now
1390 generate genuine constructors for symbol_type.
1392 For instance with these declarations
1398 you may use these constructors:
1400 symbol_type (int token, const std::string&);
1401 symbol_type (int token, const int&);
1402 symbol_type (int token);
1404 Correct matching between token types and value types is checked via
1405 'assert'; for instance, 'symbol_type (ID, 42)' would abort. Named
1406 constructors are preferable, as they offer better type safety (for
1407 instance 'make_ID (42)' would not even compile), but symbol_type
1408 constructors may help when token types are discovered at run-time, e.g.,
1411 if (auto i = lookup_keyword (yytext))
1412 return yy::parser::symbol_type (i);
1414 return yy::parser::make_ID (yytext);
1417 *** C++: Variadic emplace
1419 If your application requires C++11 and you don't use symbol constructors,
1420 you may now use a variadic emplace for semantic values:
1422 %define api.value.type variant
1423 %token <std::pair<int, int>> PAIR
1427 int yylex (parser::semantic_type *lvalp)
1429 lvalp->emplace <std::pair<int, int>> (1, 2);
1430 return parser::token::PAIR;
1433 *** C++: Syntax error exceptions in GLR
1435 The glr.cc skeleton now supports syntax_error exceptions thrown from user
1436 actions, or from the scanner.
1438 *** More POSIX Yacc compatibility warnings
1440 More Bison specific directives are now reported with -y or -Wyacc. This
1441 change was ready since the release of Bison 3.0 in September 2015. It was
1442 delayed because Autoconf used to define YACC as `bison -y`, which resulted
1443 in numerous warnings for Bison users that use the GNU Build System.
1445 If you still experience that problem, either redefine YACC as `bison -o
1446 y.tab.c`, or pass -Wno-yacc to Bison.
1448 *** The tables yyrhs and yyphrs are back
1450 Because no Bison skeleton uses them, these tables were removed (no longer
1451 passed to the skeletons, not even computed) in 2008. However, some users
1452 have expressed interest in being able to use them in their own skeletons.
1456 *** Incorrect number of reduce/reduce conflicts
1458 On a grammar such as
1460 exp: "num" | "num" | "num"
1462 bison used to report a single RR conflict, instead of two. This is now
1463 fixed. This was the oldest (known) bug in Bison: it was there when Bison
1464 was entered in the RCS version control system, in December 1987.
1466 Some grammar files might have to adjust their %expect-rr.
1468 *** Parser directives that were not careful enough
1470 Passing invalid arguments to %nterm, for instance character literals, used
1471 to result in unclear error messages.
1475 The examples/ directory (installed in .../share/doc/bison/examples) has
1476 been restructured per language for clarity. The examples come with a
1477 README and a Makefile. Not only can they be used to toy with Bison, they
1478 can also be starting points for your own grammars.
1480 There is now a Java example, and a simple example in C based on Flex and
1481 Bison (examples/c/lexcalc/).
1487 They now use noexcept and constexpr. Please, report missing annotations.
1489 *** Symbol Declarations
1491 The syntax of the variation directives to declare symbols was overhauled
1492 for more consistency, and also better POSIX Yacc compliance (which, for
1493 instance, allows "%type" without actually providing a type). The %nterm
1494 directive, supported by Bison since its inception, is now documented and
1495 officially supported.
1497 The syntax is now as follows:
1499 %token TAG? ( ID NUMBER? STRING? )+ ( TAG ( ID NUMBER? STRING? )+ )*
1500 %left TAG? ( ID NUMBER? )+ ( TAG ( ID NUMBER? )+ )*
1501 %type TAG? ( ID | CHAR | STRING )+ ( TAG ( ID | CHAR | STRING )+ )*
1502 %nterm TAG? ID+ ( TAG ID+ )*
1504 where TAG denotes a type tag such as ‘<ival>’, ID denotes an identifier
1505 such as ‘NUM’, NUMBER a decimal or hexadecimal integer such as ‘300’ or
1506 ‘0x12d’, CHAR a character literal such as ‘'+'’, and STRING a string
1507 literal such as ‘"number"’. The post-fix quantifiers are ‘?’ (zero or
1508 one), ‘*’ (zero or more) and ‘+’ (one or more).
1511 * Noteworthy changes in release 3.2.4 (2018-12-24) [stable]
1515 Fix the move constructor of symbol_type.
1517 Always provide a copy constructor for symbol_type, even in modern C++.
1520 * Noteworthy changes in release 3.2.3 (2018-12-18) [stable]
1524 Properly support token constructors in C++ with types that include commas
1525 (e.g., std::pair<int, int>). A regression introduced in Bison 3.2.
1528 * Noteworthy changes in release 3.2.2 (2018-11-21) [stable]
1532 C++ portability issues.
1535 * Noteworthy changes in release 3.2.1 (2018-11-09) [stable]
1539 Several portability issues have been fixed in the build system, in the
1540 test suite, and in the generated parsers in C++.
1543 * Noteworthy changes in release 3.2 (2018-10-29) [stable]
1545 ** Backward incompatible changes
1547 Support for DJGPP, which has been unmaintained and untested for years, is
1548 obsolete. Unless there is activity to revive it, it will be removed.
1552 %printers should use yyo rather than yyoutput to denote the output stream.
1554 Variant-based symbols in C++ should use emplace() rather than build().
1556 In C++ parsers, parser::operator() is now a synonym for the parser::parse.
1560 A new section, "A Simple C++ Example", is a tutorial for parsers in C++.
1562 A comment in the generated code now emphasizes that users should not
1563 depend upon non-documented implementation details, such as macros starting
1568 *** C++: Support for move semantics (lalr1.cc)
1570 The lalr1.cc skeleton now fully supports C++ move semantics, while
1571 maintaining compatibility with C++98. You may now store move-only types
1572 when using Bison's variants. For instance:
1579 %skeleton "lalr1.cc"
1580 %define api.value.type variant
1584 %token <int> INT "int";
1585 %type <std::unique_ptr<int>> int;
1586 %type <std::vector<std::unique_ptr<int>>> list;
1590 | list int { $$ = std::move($1); $$.emplace_back(std::move($2)); }
1592 int: "int" { $$ = std::make_unique<int>($1); }
1594 *** C++: Implicit move of right-hand side values (lalr1.cc)
1596 In modern C++ (C++11 and later), you should always use 'std::move' with
1597 the values of the right-hand side symbols ($1, $2, etc.), as they will be
1598 popped from the stack anyway. Using 'std::move' is mandatory for
1599 move-only types such as unique_ptr, and it provides a significant speedup
1600 for large types such as std::string, or std::vector, etc.
1602 If '%define api.value.automove' is set, every occurrence '$n' is replaced
1603 by 'std::move ($n)'. The second rule in the previous grammar can be
1606 list: list int { $$ = $1; $$.emplace_back($2); }
1608 With automove enabled, the semantic values are no longer lvalues, so do
1609 not use the swap idiom:
1611 list: list int { std::swap($$, $1); $$.emplace_back($2); }
1613 This idiom is anyway obsolete: it is preferable to move than to swap.
1615 A warning is issued when automove is enabled, and a value is used several
1618 input.yy:16.31-32: warning: multiple occurrences of $2 with api.value.automove enabled [-Wother]
1619 exp: "twice" exp { $$ = $2 + $2; }
1622 Enabling api.value.automove does not require support for modern C++. The
1623 generated code is valid C++98/03, but will use copies instead of moves.
1625 The new examples/c++/variant-11.yy shows these features in action.
1627 *** C++: The implicit default semantic action is always run
1629 When variants are enabled, the default action was not run, so
1637 It now behaves like in all the other cases, as
1639 exp: "number" { $$ = $1; }
1641 possibly using std::move if automove is enabled.
1643 We do not expect backward compatibility issues. However, beware of
1644 forward compatibility issues: if you rely on default actions with
1645 variants, be sure to '%require "3.2"' to avoid older versions of Bison to
1646 generate incorrect parsers.
1648 *** C++: Renaming location.hh
1650 When both %defines and %locations are enabled, Bison generates a
1651 location.hh file. If you don't use locations outside of the parser, you
1652 may avoid its creation with:
1654 %define api.location.file none
1656 However this file is useful if, for instance, your parser builds an AST
1657 decorated with locations: you may use Bison's location independently of
1658 Bison's parser. You can now give it another name, for instance:
1660 %define api.location.file "my-location.hh"
1662 This name can have directory components, and even be absolute. The name
1663 under which the location file is included is controlled by
1664 api.location.include.
1666 This way it is possible to have several parsers share the same location
1669 For instance, in src/foo/parser.hh, generate the include/ast/loc.hh file:
1672 %define api.namespace {foo}
1673 %define api.location.file "include/ast/loc.hh"
1674 %define api.location.include {<ast/loc.hh>}
1676 and use it in src/bar/parser.hh:
1679 %define api.namespace {bar}
1680 %code requires {#include <ast/loc.hh>}
1681 %define api.location.type {bar::location}
1683 Absolute file names are supported, so in your Makefile, passing the flag
1684 -Dapi.location.file='"$(top_srcdir)/include/ast/location.hh"' to bison is
1687 *** C++: stack.hh and position.hh are deprecated
1689 When asked to generate a header file (%defines), the lalr1.cc skeleton
1690 generates a stack.hh file. This file had no interest for users; it is now
1691 made useless: its content is included in the parser definition. It is
1692 still generated for backward compatibility.
1694 When in addition to %defines, location support is requested (%locations),
1695 the file position.hh is also generated. It is now also useless: its
1696 content is now included in location.hh.
1698 These files are no longer generated when your grammar file requires at
1699 least Bison 3.2 (%require "3.2").
1703 Portability issues on MinGW and VS2015.
1705 Portability issues in the test suite.
1707 Portability/warning issues with Flex.
1710 * Noteworthy changes in release 3.1 (2018-08-27) [stable]
1712 ** Backward incompatible changes
1714 Compiling Bison now requires a C99 compiler---as announced during the
1715 release of Bison 3.0, five years ago. Generated parsers do not require a
1718 Support for DJGPP, which has been unmaintained and untested for years, is
1719 obsolete. Unless there is activity to revive it, the next release of Bison
1720 will have it removed.
1724 *** Typed midrule actions
1726 Because their type is unknown to Bison, the values of midrule actions are
1727 not treated like the others: they don't have %printer and %destructor
1728 support. It also prevents C++ (Bison) variants to handle them properly.
1730 Typed midrule actions address these issues. Instead of:
1732 exp: { $<ival>$ = 1; } { $<ival>$ = 2; } { $$ = $<ival>1 + $<ival>2; }
1736 exp: <ival>{ $$ = 1; } <ival>{ $$ = 2; } { $$ = $1 + $2; }
1738 *** Reports include the type of the symbols
1740 The sections about terminal and nonterminal symbols of the '*.output' file
1741 now specify their declared type. For instance, for:
1745 the report now shows '<ival>':
1747 Terminals, with rules where they appear
1751 *** Diagnostics about useless rules
1753 In the following grammar, the 'exp' nonterminal is trivially useless. So,
1754 of course, its rules are useless too.
1758 exp: exp '+' exp | exp '-' exp | '(' exp ')'
1760 Previously all the useless rules were reported, including those whose
1761 left-hand side is the 'exp' nonterminal:
1763 warning: 1 nonterminal useless in grammar [-Wother]
1764 warning: 4 rules useless in grammar [-Wother]
1765 2.14-16: warning: nonterminal useless in grammar: exp [-Wother]
1768 2.14-16: warning: rule useless in grammar [-Wother]
1771 3.6-16: warning: rule useless in grammar [-Wother]
1772 exp: exp '+' exp | exp '-' exp | '(' exp ')'
1774 3.20-30: warning: rule useless in grammar [-Wother]
1775 exp: exp '+' exp | exp '-' exp | '(' exp ')'
1777 3.34-44: warning: rule useless in grammar [-Wother]
1778 exp: exp '+' exp | exp '-' exp | '(' exp ')'
1781 Now, rules whose left-hand side symbol is useless are no longer reported
1782 as useless. The locations of the errors have also been adjusted to point
1783 to the first use of the nonterminal as a left-hand side of a rule:
1785 warning: 1 nonterminal useless in grammar [-Wother]
1786 warning: 4 rules useless in grammar [-Wother]
1787 3.1-3: warning: nonterminal useless in grammar: exp [-Wother]
1788 exp: exp '+' exp | exp '-' exp | '(' exp ')'
1790 2.14-16: warning: rule useless in grammar [-Wother]
1794 *** C++: Generated parsers can be compiled with -fno-exceptions (lalr1.cc)
1796 When compiled with exceptions disabled, the generated parsers no longer
1797 uses try/catch clauses.
1799 Currently only GCC and Clang are supported.
1803 *** A demonstration of variants
1805 A new example was added (installed in .../share/doc/bison/examples),
1806 'variant.yy', which shows how to use (Bison) variants in C++.
1808 The other examples were made nicer to read.
1810 *** Some features are no longer 'experimental'
1812 The following features, mature enough, are no longer flagged as
1813 experimental in the documentation: push parsers, default %printer and
1814 %destructor (typed: <*> and untyped: <>), %define api.value.type union and
1815 variant, Java parsers, XML output, LR family (lr, ielr, lalr), and
1816 semantic predicates (%?).
1820 *** GLR: Predicates support broken by #line directives
1822 Predicates (%?) in GLR such as
1825 %? {new_syntax} 'w' id new_args
1826 | %?{!new_syntax} 'w' id old_args
1828 were issued with #lines in the middle of C code.
1830 *** Printer and destructor with broken #line directives
1832 The #line directives were not properly escaped when emitting the code for
1833 %printer/%destructor, which resulted in compiler errors if there are
1834 backslashes or double-quotes in the grammar file name.
1836 *** Portability on ICC
1838 The Intel compiler claims compatibility with GCC, yet rejects its _Pragma.
1839 Generated parsers now work around this.
1843 There were several small fixes in the test suite and in the build system,
1844 many warnings in bison and in the generated parsers were eliminated. The
1845 documentation also received its share of minor improvements.
1847 Useless code was removed from C++ parsers, and some of the generated
1848 constructors are more 'natural'.
1851 * Noteworthy changes in release 3.0.5 (2018-05-27) [stable]
1855 *** C++: Fix support of 'syntax_error'
1857 One incorrect 'inline' resulted in linking errors about the constructor of
1858 the syntax_error exception.
1860 *** C++: Fix warnings
1862 GCC 7.3 (with -O1 or -O2 but not -O0 or -O3) issued null-dereference
1863 warnings about yyformat being possibly null. It also warned about the
1864 deprecated implicit definition of copy constructors when there's a
1865 user-defined (copy) assignment operator.
1867 *** Location of errors
1869 In C++ parsers, out-of-bounds errors can happen when a rule with an empty
1870 ride-hand side raises a syntax error. The behavior of the default parser
1871 (yacc.c) in such a condition was undefined.
1873 Now all the parsers match the behavior of glr.c: @$ is used as the
1874 location of the error. This handles gracefully rules with and without
1877 *** Portability fixes in the test suite
1879 On some platforms, some Java and/or C++ tests were failing.
1882 * Noteworthy changes in release 3.0.4 (2015-01-23) [stable]
1886 *** C++ with Variants (lalr1.cc)
1888 Fix a compiler warning when no %destructor use $$.
1892 Several portability issues in tests were fixed.
1895 * Noteworthy changes in release 3.0.3 (2015-01-15) [stable]
1899 *** C++ with Variants (lalr1.cc)
1901 Problems with %destructor and '%define parse.assert' have been fixed.
1903 *** Named %union support (yacc.c, glr.c)
1905 Bison 3.0 introduced a regression on named %union such as
1907 %union foo { int ival; };
1909 The possibility to use a name was introduced "for Yacc compatibility".
1910 It is however not required by POSIX Yacc, and its usefulness is not clear.
1912 *** %define api.value.type union with %defines (yacc.c, glr.c)
1914 The C parsers were broken when %defines was used together with "%define
1915 api.value.type union".
1917 *** Redeclarations are reported in proper order
1925 bison used to report:
1927 foo.yy:2.10-11: error: %printer redeclaration for FOO
1930 foo.yy:3.10-11: previous declaration
1934 Now, the "previous" declaration is always the first one.
1939 Bison now installs various files in its docdir (which defaults to
1940 '/usr/local/share/doc/bison'), including the three fully blown examples
1941 extracted from the documentation:
1944 Reverse Polish Calculator, a simple introductory example.
1946 Multi-function Calc, a calculator with memory and functions and located
1949 a calculator in C++ using variant support and token constructors.
1952 * Noteworthy changes in release 3.0.2 (2013-12-05) [stable]
1956 *** Generated source files when errors are reported
1958 When warnings are issued and -Werror is set, bison would still generate
1959 the source files (*.c, *.h...). As a consequence, some runs of "make"
1960 could fail the first time, but not the second (as the files were generated
1963 This is fixed: bison no longer generates this source files, but, of
1964 course, still produces the various reports (*.output, *.xml, etc.).
1966 *** %empty is used in reports
1968 Empty right-hand sides are denoted by '%empty' in all the reports (text,
1969 dot, XML and formats derived from it).
1971 *** YYERROR and variants
1973 When C++ variant support is enabled, an error triggered via YYERROR, but
1974 not caught via error recovery, resulted in a double deletion.
1977 * Noteworthy changes in release 3.0.1 (2013-11-12) [stable]
1981 *** Errors in caret diagnostics
1983 On some platforms, some errors could result in endless diagnostics.
1985 *** Fixes of the -Werror option
1987 Options such as "-Werror -Wno-error=foo" were still turning "foo"
1988 diagnostics into errors instead of warnings. This is fixed.
1990 Actually, for consistency with GCC, "-Wno-error=foo -Werror" now also
1991 leaves "foo" diagnostics as warnings. Similarly, with "-Werror=foo
1992 -Wno-error", "foo" diagnostics are now errors.
1996 As demonstrated in the documentation, one can now leave spaces between
2001 The yacc.1 man page is no longer installed if --disable-yacc was
2004 *** Fixes in the test suite
2006 Bugs and portability issues.
2009 * Noteworthy changes in release 3.0 (2013-07-25) [stable]
2011 ** WARNING: Future backward-incompatibilities!
2013 Like other GNU packages, Bison will start using some of the C99 features
2014 for its own code, especially the definition of variables after statements.
2015 The generated C parsers still aim at C90.
2017 ** Backward incompatible changes
2019 *** Obsolete features
2021 Support for YYFAIL is removed (deprecated in Bison 2.4.2): use YYERROR.
2023 Support for yystype and yyltype is removed (deprecated in Bison 1.875):
2024 use YYSTYPE and YYLTYPE.
2026 Support for YYLEX_PARAM and YYPARSE_PARAM is removed (deprecated in Bison
2027 1.875): use %lex-param, %parse-param, or %param.
2029 Missing semicolons at the end of actions are no longer added (as announced
2030 in the release 2.5).
2032 *** Use of YACC='bison -y'
2034 TL;DR: With Autoconf <= 2.69, pass -Wno-yacc to (AM_)YFLAGS if you use
2037 Traditional Yacc generates 'y.tab.c' whatever the name of the input file.
2038 Therefore Makefiles written for Yacc expect 'y.tab.c' (and possibly
2039 'y.tab.h' and 'y.output') to be generated from 'foo.y'.
2041 To this end, for ages, AC_PROG_YACC, Autoconf's macro to look for an
2042 implementation of Yacc, was using Bison as 'bison -y'. While it does
2043 ensure compatible output file names, it also enables warnings for
2044 incompatibilities with POSIX Yacc. In other words, 'bison -y' triggers
2045 warnings for Bison extensions.
2047 Autoconf 2.70+ fixes this incompatibility by using YACC='bison -o y.tab.c'
2048 (which also generates 'y.tab.h' and 'y.output' when needed).
2049 Alternatively, disable Yacc warnings by passing '-Wno-yacc' to your Yacc
2050 flags (YFLAGS, or AM_YFLAGS with Automake).
2054 *** The epilogue is no longer affected by internal #defines (glr.c)
2056 The glr.c skeleton uses defines such as #define yylval (yystackp->yyval) in
2057 generated code. These weren't properly undefined before the inclusion of
2058 the user epilogue, so functions such as the following were butchered by the
2059 preprocessor expansion:
2061 int yylex (YYSTYPE *yylval);
2063 This is fixed: yylval, yynerrs, yychar, and yylloc are now valid
2064 identifiers for user-provided variables.
2066 *** stdio.h is no longer needed when locations are enabled (yacc.c)
2068 Changes in Bison 2.7 introduced a dependency on FILE and fprintf when
2069 locations are enabled. This is fixed.
2071 *** Warnings about useless %pure-parser/%define api.pure are restored
2073 ** Diagnostics reported by Bison
2075 Most of these features were contributed by Théophile Ranquet and Victor
2080 Version 2.7 introduced caret errors, for a prettier output. These are now
2081 activated by default. The old format can still be used by invoking Bison
2082 with -fno-caret (or -fnone).
2084 Some error messages that reproduced excerpts of the grammar are now using
2085 the caret information only. For instance on:
2092 in.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
2093 in.y:2.12-14: warning: rule useless in parser due to conflicts: exp: 'a' [-Wother]
2097 in.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
2098 in.y:2.12-14: warning: rule useless in parser due to conflicts [-Wother]
2102 and "bison -fno-caret" reports:
2104 in.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
2105 in.y:2.12-14: warning: rule useless in parser due to conflicts [-Wother]
2107 *** Enhancements of the -Werror option
2109 The -Werror=CATEGORY option is now recognized, and will treat specified
2110 warnings as errors. The warnings need not have been explicitly activated
2111 using the -W option, this is similar to what GCC 4.7 does.
2113 For example, given the following command line, Bison will treat both
2114 warnings related to POSIX Yacc incompatibilities and S/R conflicts as
2115 errors (and only those):
2117 $ bison -Werror=yacc,error=conflicts-sr input.y
2119 If no categories are specified, -Werror will make all active warnings into
2120 errors. For example, the following line does the same the previous example:
2122 $ bison -Werror -Wnone -Wyacc -Wconflicts-sr input.y
2124 (By default -Wconflicts-sr,conflicts-rr,deprecated,other is enabled.)
2126 Note that the categories in this -Werror option may not be prefixed with
2127 "no-". However, -Wno-error[=CATEGORY] is valid.
2129 Note that -y enables -Werror=yacc. Therefore it is now possible to require
2130 Yacc-like behavior (e.g., always generate y.tab.c), but to report
2131 incompatibilities as warnings: "-y -Wno-error=yacc".
2133 *** The display of warnings is now richer
2135 The option that controls a given warning is now displayed:
2137 foo.y:4.6: warning: type clash on default action: <foo> != <bar> [-Wother]
2139 In the case of warnings treated as errors, the prefix is changed from
2140 "warning: " to "error: ", and the suffix is displayed, in a manner similar
2141 to GCC, as [-Werror=CATEGORY].
2143 For instance, where the previous version of Bison would report (and exit
2146 bison: warnings being treated as errors
2147 input.y:1.1: warning: stray ',' treated as white space
2151 input.y:1.1: error: stray ',' treated as white space [-Werror=other]
2153 *** Deprecated constructs
2155 The new 'deprecated' warning category flags obsolete constructs whose
2156 support will be discontinued. It is enabled by default. These warnings
2157 used to be reported as 'other' warnings.
2159 *** Useless semantic types
2161 Bison now warns about useless (uninhabited) semantic types. Since
2162 semantic types are not declared to Bison (they are defined in the opaque
2163 %union structure), it is %printer/%destructor directives about useless
2164 types that trigger the warning:
2168 %printer {} <type1> <type3>
2169 %destructor {} <type2> <type4>
2171 nterm: term { $$ = $1; };
2173 3.28-34: warning: type <type3> is used, but is not associated to any symbol
2174 4.28-34: warning: type <type4> is used, but is not associated to any symbol
2176 *** Undefined but unused symbols
2178 Bison used to raise an error for undefined symbols that are not used in
2179 the grammar. This is now only a warning.
2182 %destructor {} symbol2
2183 %type <type> symbol3
2187 *** Useless destructors or printers
2189 Bison now warns about useless destructors or printers. In the following
2190 example, the printer for <type1>, and the destructor for <type2> are
2191 useless: all symbols of <type1> (token1) already have a printer, and all
2192 symbols of type <type2> (token2) already have a destructor.
2194 %token <type1> token1
2198 %printer {} token1 <type1> <type3>
2199 %destructor {} token2 <type2> <type4>
2203 The warnings and error messages about shift/reduce and reduce/reduce
2204 conflicts have been normalized. For instance on the following foo.y file:
2208 exp: exp '+' exp | '0' | '0';
2210 compare the previous version of bison:
2213 foo.y: conflicts: 1 shift/reduce, 2 reduce/reduce
2214 $ bison -Werror foo.y
2215 bison: warnings being treated as errors
2216 foo.y: conflicts: 1 shift/reduce, 2 reduce/reduce
2218 with the new behavior:
2221 foo.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
2222 foo.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
2223 $ bison -Werror foo.y
2224 foo.y: error: 1 shift/reduce conflict [-Werror=conflicts-sr]
2225 foo.y: error: 2 reduce/reduce conflicts [-Werror=conflicts-rr]
2227 When %expect or %expect-rr is used, such as with bar.y:
2232 exp: exp '+' exp | '0' | '0';
2237 bar.y: conflicts: 1 shift/reduce, 2 reduce/reduce
2238 bar.y: expected 0 shift/reduce conflicts
2239 bar.y: expected 0 reduce/reduce conflicts
2244 bar.y: error: shift/reduce conflicts: 1 found, 0 expected
2245 bar.y: error: reduce/reduce conflicts: 2 found, 0 expected
2247 ** Incompatibilities with POSIX Yacc
2249 The 'yacc' category is no longer part of '-Wall', enable it explicitly
2252 ** Additional yylex/yyparse arguments
2254 The new directive %param declares additional arguments to both yylex and
2255 yyparse. The %lex-param, %parse-param, and %param directives support one
2256 or more arguments. Instead of
2258 %lex-param {arg1_type *arg1}
2259 %lex-param {arg2_type *arg2}
2260 %parse-param {arg1_type *arg1}
2261 %parse-param {arg2_type *arg2}
2265 %param {arg1_type *arg1} {arg2_type *arg2}
2267 ** Types of values for %define variables
2269 Bison used to make no difference between '%define foo bar' and '%define
2270 foo "bar"'. The former is now called a 'keyword value', and the latter a
2271 'string value'. A third kind was added: 'code values', such as '%define
2274 Keyword variables are used for fixed value sets, e.g.,
2276 %define lr.type lalr
2278 Code variables are used for value in the target language, e.g.,
2280 %define api.value.type {struct semantic_type}
2282 String variables are used remaining cases, e.g. file names.
2284 ** Variable api.token.prefix
2286 The variable api.token.prefix changes the way tokens are identified in
2287 the generated files. This is especially useful to avoid collisions
2288 with identifiers in the target language. For instance
2290 %token FILE for ERROR
2291 %define api.token.prefix {TOK_}
2293 start: FILE for ERROR;
2295 will generate the definition of the symbols TOK_FILE, TOK_for, and
2296 TOK_ERROR in the generated sources. In particular, the scanner must
2297 use these prefixed token names, although the grammar itself still
2298 uses the short names (as in the sample rule given above).
2300 ** Variable api.value.type
2302 This new %define variable supersedes the #define macro YYSTYPE. The use
2303 of YYSTYPE is discouraged. In particular, #defining YYSTYPE *and* either
2304 using %union or %defining api.value.type results in undefined behavior.
2306 Either define api.value.type, or use "%union":
2313 %token <ival> INT "integer"
2314 %token <sval> STRING "string"
2315 %printer { fprintf (yyo, "%d", $$); } <ival>
2316 %destructor { free ($$); } <sval>
2319 yylval.ival = 42; return INT;
2320 yylval.sval = "42"; return STRING;
2322 The %define variable api.value.type supports both keyword and code values.
2324 The keyword value 'union' means that the user provides genuine types, not
2325 union member names such as "ival" and "sval" above (WARNING: will fail if
2326 -y/--yacc/%yacc is enabled).
2328 %define api.value.type union
2329 %token <int> INT "integer"
2330 %token <char *> STRING "string"
2331 %printer { fprintf (yyo, "%d", $$); } <int>
2332 %destructor { free ($$); } <char *>
2335 yylval.INT = 42; return INT;
2336 yylval.STRING = "42"; return STRING;
2338 The keyword value variant is somewhat equivalent, but for C++ special
2339 provision is made to allow classes to be used (more about this below).
2341 %define api.value.type variant
2342 %token <int> INT "integer"
2343 %token <std::string> STRING "string"
2345 Code values (in braces) denote user defined types. This is where YYSTYPE
2363 %define api.value.type {struct my_value}
2364 %token <u.ival> INT "integer"
2365 %token <u.sval> STRING "string"
2366 %printer { fprintf (yyo, "%d", $$); } <u.ival>
2367 %destructor { free ($$); } <u.sval>
2370 yylval.u.ival = 42; return INT;
2371 yylval.u.sval = "42"; return STRING;
2373 ** Variable parse.error
2375 This variable controls the verbosity of error messages. The use of the
2376 %error-verbose directive is deprecated in favor of "%define parse.error
2379 ** Deprecated %define variable names
2381 The following variables have been renamed for consistency. Backward
2382 compatibility is ensured, but upgrading is recommended.
2384 lr.default-reductions -> lr.default-reduction
2385 lr.keep-unreachable-states -> lr.keep-unreachable-state
2386 namespace -> api.namespace
2387 stype -> api.value.type
2389 ** Semantic predicates
2391 Contributed by Paul Hilfinger.
2393 The new, experimental, semantic-predicate feature allows actions of the
2394 form "%?{ BOOLEAN-EXPRESSION }", which cause syntax errors (as for
2395 YYERROR) if the expression evaluates to 0, and are evaluated immediately
2396 in GLR parsers, rather than being deferred. The result is that they allow
2397 the programmer to prune possible parses based on the values of run-time
2400 ** The directive %expect-rr is now an error in non GLR mode
2402 It used to be an error only if used in non GLR mode, _and_ if there are
2403 reduce/reduce conflicts.
2405 ** Tokens are numbered in their order of appearance
2407 Contributed by Valentin Tolmer.
2409 With '%token A B', A had a number less than the one of B. However,
2410 precedence declarations used to generate a reversed order. This is now
2411 fixed, and introducing tokens with any of %token, %left, %right,
2412 %precedence, or %nonassoc yields the same result.
2414 When mixing declarations of tokens with a literal character (e.g., 'a') or
2415 with an identifier (e.g., B) in a precedence declaration, Bison numbered
2416 the literal characters first. For example
2420 would lead to the tokens declared in this order: 'c' 'd' A B. Again, the
2421 input order is now preserved.
2423 These changes were made so that one can remove useless precedence and
2424 associativity declarations (i.e., map %nonassoc, %left or %right to
2425 %precedence, or to %token) and get exactly the same output.
2427 ** Useless precedence and associativity
2429 Contributed by Valentin Tolmer.
2431 When developing and maintaining a grammar, useless associativity and
2432 precedence directives are common. They can be a nuisance: new ambiguities
2433 arising are sometimes masked because their conflicts are resolved due to
2434 the extra precedence or associativity information. Furthermore, it can
2435 hinder the comprehension of a new grammar: one will wonder about the role
2436 of a precedence, where in fact it is useless. The following changes aim
2437 at detecting and reporting these extra directives.
2439 *** Precedence warning category
2441 A new category of warning, -Wprecedence, was introduced. It flags the
2442 useless precedence and associativity directives.
2444 *** Useless associativity
2446 Bison now warns about symbols with a declared associativity that is never
2447 used to resolve conflicts. In that case, using %precedence is sufficient;
2448 the parsing tables will remain unchanged. Solving these warnings may raise
2449 useless precedence warnings, as the symbols no longer have associativity.
2463 warning: useless associativity for '+', use %precedence [-Wprecedence]
2467 *** Useless precedence
2469 Bison now warns about symbols with a declared precedence and no declared
2470 associativity (i.e., declared with %precedence), and whose precedence is
2471 never used. In that case, the symbol can be safely declared with %token
2472 instead, without modifying the parsing tables. For example:
2476 exp: "var" '=' "number";
2480 warning: useless precedence for '=' [-Wprecedence]
2484 *** Useless precedence and associativity
2486 In case of both useless precedence and associativity, the issue is flagged
2491 exp: "var" '=' "number";
2495 warning: useless precedence and associativity for '=' [-Wprecedence]
2501 With help from Joel E. Denny and Gabriel Rassoul.
2503 Empty rules (i.e., with an empty right-hand side) can now be explicitly
2504 marked by the new %empty directive. Using %empty on a non-empty rule is
2505 an error. The new -Wempty-rule warning reports empty rules without
2506 %empty. On the following grammar:
2516 3.4-5: warning: empty rule without %empty [-Wempty-rule]
2519 5.8-13: error: %empty on non-empty rule
2523 ** Java skeleton improvements
2525 The constants for token names were moved to the Lexer interface. Also, it
2526 is possible to add code to the parser's constructors using "%code init"
2527 and "%define init_throws".
2528 Contributed by Paolo Bonzini.
2530 The Java skeleton now supports push parsing.
2531 Contributed by Dennis Heimbigner.
2533 ** C++ skeletons improvements
2535 *** The parser header is no longer mandatory (lalr1.cc, glr.cc)
2537 Using %defines is now optional. Without it, the needed support classes
2538 are defined in the generated parser, instead of additional files (such as
2539 location.hh, position.hh and stack.hh).
2541 *** Locations are no longer mandatory (lalr1.cc, glr.cc)
2543 Both lalr1.cc and glr.cc no longer require %location.
2545 *** syntax_error exception (lalr1.cc)
2547 The C++ parser features a syntax_error exception, which can be
2548 thrown from the scanner or from user rules to raise syntax errors.
2549 This facilitates reporting errors caught in sub-functions (e.g.,
2550 rejecting too large integral literals from a conversion function
2551 used by the scanner, or rejecting invalid combinations from a
2552 factory invoked by the user actions).
2554 *** %define api.value.type variant
2556 This is based on a submission from Michiel De Wilde. With help
2557 from Théophile Ranquet.
2559 In this mode, complex C++ objects can be used as semantic values. For
2562 %token <::std::string> TEXT;
2563 %token <int> NUMBER;
2564 %token SEMICOLON ";"
2565 %type <::std::string> item;
2566 %type <::std::list<std::string>> list;
2569 list { std::cout << $1 << std::endl; }
2573 %empty { /* Generates an empty string list. */ }
2574 | list item ";" { std::swap ($$, $1); $$.push_back ($2); }
2578 TEXT { std::swap ($$, $1); }
2579 | NUMBER { $$ = string_cast ($1); }
2582 *** %define api.token.constructor
2584 When variants are enabled, Bison can generate functions to build the
2585 tokens. This guarantees that the token type (e.g., NUMBER) is consistent
2586 with the semantic value (e.g., int):
2588 parser::symbol_type yylex ()
2590 parser::location_type loc = ...;
2592 return parser::make_TEXT ("Hello, world!", loc);
2594 return parser::make_NUMBER (42, loc);
2596 return parser::make_SEMICOLON (loc);
2602 There are operator- and operator-= for 'location'. Negative line/column
2603 increments can no longer underflow the resulting value.
2606 * Noteworthy changes in release 2.7.1 (2013-04-15) [stable]
2610 *** Fix compiler attribute portability (yacc.c)
2612 With locations enabled, __attribute__ was used unprotected.
2614 *** Fix some compiler warnings (lalr1.cc)
2617 * Noteworthy changes in release 2.7 (2012-12-12) [stable]
2621 Warnings about uninitialized yylloc in yyparse have been fixed.
2623 Restored C90 compliance (yet no report was ever made).
2625 ** Diagnostics are improved
2627 Contributed by Théophile Ranquet.
2629 *** Changes in the format of error messages
2631 This used to be the format of many error reports:
2633 input.y:2.7-12: %type redeclaration for exp
2634 input.y:1.7-12: previous declaration
2638 input.y:2.7-12: error: %type redeclaration for exp
2639 input.y:1.7-12: previous declaration
2641 *** New format for error reports: carets
2643 Caret errors have been added to Bison:
2645 input.y:2.7-12: error: %type redeclaration for exp
2648 input.y:1.7-12: previous declaration
2654 input.y:3.20-23: error: ambiguous reference: '$exp'
2655 exp: exp '+' exp { $exp = $1 + $3; };
2657 input.y:3.1-3: refers to: $exp at $$
2658 exp: exp '+' exp { $exp = $1 + $3; };
2660 input.y:3.6-8: refers to: $exp at $1
2661 exp: exp '+' exp { $exp = $1 + $3; };
2663 input.y:3.14-16: refers to: $exp at $3
2664 exp: exp '+' exp { $exp = $1 + $3; };
2667 The default behavior for now is still not to display these unless
2668 explicitly asked with -fcaret (or -fall). However, in a later release, it
2669 will be made the default behavior (but may still be deactivated with
2672 ** New value for %define variable: api.pure full
2674 The %define variable api.pure requests a pure (reentrant) parser. However,
2675 for historical reasons, using it in a location-tracking Yacc parser
2676 resulted in a yyerror function that did not take a location as a
2677 parameter. With this new value, the user may request a better pure parser,
2678 where yyerror does take a location as a parameter (in location-tracking
2681 The use of "%define api.pure true" is deprecated in favor of this new
2682 "%define api.pure full".
2684 ** New %define variable: api.location.type (glr.cc, lalr1.cc, lalr1.java)
2686 The %define variable api.location.type defines the name of the type to use
2687 for locations. When defined, Bison no longer generates the position.hh
2688 and location.hh files, nor does the parser will include them: the user is
2689 then responsible to define her type.
2691 This can be used in programs with several parsers to factor their location
2692 and position files: let one of them generate them, and the others just use
2695 This feature was actually introduced, but not documented, in Bison 2.5,
2696 under the name "location_type" (which is maintained for backward
2699 For consistency, lalr1.java's %define variables location_type and
2700 position_type are deprecated in favor of api.location.type and
2703 ** Exception safety (lalr1.cc)
2705 The parse function now catches exceptions, uses the %destructors to
2706 release memory (the lookahead symbol and the symbols pushed on the stack)
2707 before re-throwing the exception.
2709 This feature is somewhat experimental. User feedback would be
2712 ** Graph improvements in DOT and XSLT
2714 Contributed by Théophile Ranquet.
2716 The graphical presentation of the states is more readable: their shape is
2717 now rectangular, the state number is clearly displayed, and the items are
2718 numbered and left-justified.
2720 The reductions are now explicitly represented as transitions to other
2721 diamond shaped nodes.
2723 These changes are present in both --graph output and xml2dot.xsl XSLT
2724 processing, with minor (documented) differences.
2726 ** %language is no longer an experimental feature.
2728 The introduction of this feature, in 2.4, was four years ago. The
2729 --language option and the %language directive are no longer experimental.
2733 The sections about shift/reduce and reduce/reduce conflicts resolution
2734 have been fixed and extended.
2736 Although introduced more than four years ago, XML and Graphviz reports
2737 were not properly documented.
2739 The translation of midrule actions is now described.
2742 * Noteworthy changes in release 2.6.5 (2012-11-07) [stable]
2744 We consider compiler warnings about Bison generated parsers to be bugs.
2745 Rather than working around them in your own project, please consider
2746 reporting them to us.
2750 Warnings about uninitialized yylval and/or yylloc for push parsers with a
2751 pure interface have been fixed for GCC 4.0 up to 4.8, and Clang 2.9 to
2754 Other issues in the test suite have been addressed.
2756 Null characters are correctly displayed in error messages.
2758 When possible, yylloc is correctly initialized before calling yylex. It
2759 is no longer necessary to initialize it in the %initial-action.
2762 * Noteworthy changes in release 2.6.4 (2012-10-23) [stable]
2764 Bison 2.6.3's --version was incorrect. This release fixes this issue.
2767 * Noteworthy changes in release 2.6.3 (2012-10-22) [stable]
2771 Bugs and portability issues in the test suite have been fixed.
2773 Some errors in translations have been addressed, and --help now directs
2774 users to the appropriate place to report them.
2776 Stray Info files shipped by accident are removed.
2778 Incorrect definitions of YY_, issued by yacc.c when no parser header is
2779 generated, are removed.
2781 All the generated headers are self-contained.
2783 ** Header guards (yacc.c, glr.c, glr.cc)
2785 In order to avoid collisions, the header guards are now
2786 YY_<PREFIX>_<FILE>_INCLUDED, instead of merely <PREFIX>_<FILE>.
2787 For instance the header generated from
2789 %define api.prefix "calc"
2790 %defines "lib/parse.h"
2792 will use YY_CALC_LIB_PARSE_H_INCLUDED as guard.
2794 ** Fix compiler warnings in the generated parser (yacc.c, glr.c)
2796 The compilation of pure parsers (%define api.pure) can trigger GCC
2799 input.c: In function 'yyparse':
2800 input.c:1503:12: warning: 'yylval' may be used uninitialized in this
2801 function [-Wmaybe-uninitialized]
2805 This is now fixed; pragmas to avoid these warnings are no longer needed.
2807 Warnings from clang ("equality comparison with extraneous parentheses" and
2808 "function declared 'noreturn' should not return") have also been
2812 * Noteworthy changes in release 2.6.2 (2012-08-03) [stable]
2816 Buffer overruns, complaints from Flex, and portability issues in the test
2817 suite have been fixed.
2819 ** Spaces in %lex- and %parse-param (lalr1.cc, glr.cc)
2821 Trailing end-of-lines in %parse-param or %lex-param would result in
2822 invalid C++. This is fixed.
2824 ** Spurious spaces and end-of-lines
2826 The generated files no longer end (nor start) with empty lines.
2829 * Noteworthy changes in release 2.6.1 (2012-07-30) [stable]
2831 Bison no longer executes user-specified M4 code when processing a grammar.
2835 In addition to the removal of the features announced in Bison 2.6, the
2836 next major release will remove the "Temporary hack for adding a semicolon
2837 to the user action", as announced in the release 2.5. Instead of:
2839 exp: exp "+" exp { $$ = $1 + $3 };
2843 exp: exp "+" exp { $$ = $1 + $3; };
2847 *** Type names are now properly escaped.
2849 *** glr.cc: set_debug_level and debug_level work as expected.
2851 *** Stray @ or $ in actions
2853 While Bison used to warn about stray $ or @ in action rules, it did not
2854 for other actions such as printers, destructors, or initial actions. It
2857 ** Type names in actions
2859 For consistency with rule actions, it is now possible to qualify $$ by a
2860 type-name in destructors, printers, and initial actions. For instance:
2862 %printer { fprintf (yyo, "(%d, %f)", $<ival>$, $<fval>$); } <*> <>;
2864 will display two values for each typed and untyped symbol (provided
2865 that YYSTYPE has both "ival" and "fval" fields).
2868 * Noteworthy changes in release 2.6 (2012-07-19) [stable]
2872 The next major release of Bison will drop support for the following
2873 deprecated features. Please report disagreements to bug-bison@gnu.org.
2877 Support for generating parsers in K&R C will be removed. Parsers
2878 generated for C support ISO C90, and are tested with ISO C99 and ISO C11
2881 *** Features deprecated since Bison 1.875
2883 The definitions of yystype and yyltype will be removed; use YYSTYPE and
2886 YYPARSE_PARAM and YYLEX_PARAM, deprecated in favor of %parse-param and
2887 %lex-param, will no longer be supported.
2889 Support for the preprocessor symbol YYERROR_VERBOSE will be removed, use
2892 *** The generated header will be included (yacc.c)
2894 Instead of duplicating the content of the generated header (definition of
2895 YYSTYPE, yyparse declaration etc.), the generated parser will include it,
2896 as is already the case for GLR or C++ parsers. This change is deferred
2897 because existing versions of ylwrap (e.g., Automake 1.12.1) do not support
2900 ** Generated Parser Headers
2902 *** Guards (yacc.c, glr.c, glr.cc)
2904 The generated headers are now guarded, as is already the case for C++
2905 parsers (lalr1.cc). For instance, with --defines=foo.h:
2910 #endif /* !YY_FOO_H */
2912 *** New declarations (yacc.c, glr.c)
2914 The generated header now declares yydebug and yyparse. Both honor
2915 --name-prefix=bar_, and yield
2917 int bar_parse (void);
2921 #define yyparse bar_parse
2924 in order to facilitate the inclusion of several parser headers inside a
2925 single compilation unit.
2927 *** Exported symbols in C++
2929 The symbols YYTOKEN_TABLE and YYERROR_VERBOSE, which were defined in the
2930 header, are removed, as they prevent the possibility of including several
2931 generated headers from a single compilation unit.
2935 For the same reasons, the undocumented and unused macro YYLSP_NEEDED is no
2938 ** New %define variable: api.prefix
2940 Now that the generated headers are more complete and properly protected
2941 against multiple inclusions, constant names, such as YYSTYPE are a
2942 problem. While yyparse and others are properly renamed by %name-prefix,
2943 YYSTYPE, YYDEBUG and others have never been affected by it. Because it
2944 would introduce backward compatibility issues in projects not expecting
2945 YYSTYPE to be renamed, instead of changing the behavior of %name-prefix,
2946 it is deprecated in favor of a new %define variable: api.prefix.
2948 The following examples compares both:
2950 %name-prefix "bar_" | %define api.prefix "bar_"
2951 %token <ival> FOO %token <ival> FOO
2952 %union { int ival; } %union { int ival; }
2958 #ifndef BAR_FOO_H #ifndef BAR_FOO_H
2959 # define BAR_FOO_H # define BAR_FOO_H
2961 /* Enabling traces. */ /* Enabling traces. */
2962 # ifndef YYDEBUG | # ifndef BAR_DEBUG
2963 > # if defined YYDEBUG
2965 > # define BAR_DEBUG 1
2967 > # define BAR_DEBUG 0
2970 # define YYDEBUG 0 | # define BAR_DEBUG 0
2974 # if YYDEBUG | # if BAR_DEBUG
2975 extern int bar_debug; extern int bar_debug;
2978 /* Tokens. */ /* Tokens. */
2979 # ifndef YYTOKENTYPE | # ifndef BAR_TOKENTYPE
2980 # define YYTOKENTYPE | # define BAR_TOKENTYPE
2981 enum yytokentype { | enum bar_tokentype {
2986 #if ! defined YYSTYPE \ | #if ! defined BAR_STYPE \
2987 && ! defined YYSTYPE_IS_DECLARED | && ! defined BAR_STYPE_IS_DECLARED
2988 typedef union YYSTYPE | typedef union BAR_STYPE
2991 } YYSTYPE; | } BAR_STYPE;
2992 # define YYSTYPE_IS_DECLARED 1 | # define BAR_STYPE_IS_DECLARED 1
2995 extern YYSTYPE bar_lval; | extern BAR_STYPE bar_lval;
2997 int bar_parse (void); int bar_parse (void);
2999 #endif /* !BAR_FOO_H */ #endif /* !BAR_FOO_H */
3002 * Noteworthy changes in release 2.5.1 (2012-06-05) [stable]
3006 The next major release will drop support for generating parsers in K&R C.
3008 ** yacc.c: YYBACKUP works as expected.
3010 ** glr.c improvements:
3012 *** Location support is eliminated when not requested:
3014 GLR parsers used to include location-related code even when locations were
3015 not requested, and therefore not even usable.
3017 *** __attribute__ is preserved:
3019 __attribute__ is no longer disabled when __STRICT_ANSI__ is defined (i.e.,
3020 when -std is passed to GCC).
3022 ** lalr1.java: several fixes:
3024 The Java parser no longer throws ArrayIndexOutOfBoundsException if the
3025 first token leads to a syntax error. Some minor clean ups.
3029 *** C++11 compatibility:
3031 C and C++ parsers use "nullptr" instead of "0" when __cplusplus is 201103L
3036 The header files such as "parser.hh", "location.hh", etc. used a constant
3037 name for preprocessor guards, for instance:
3039 #ifndef BISON_LOCATION_HH
3040 # define BISON_LOCATION_HH
3042 #endif // !BISON_LOCATION_HH
3044 The inclusion guard is now computed from "PREFIX/FILE-NAME", where lower
3045 case characters are converted to upper case, and series of
3046 non-alphanumerical characters are converted to an underscore.
3048 With "bison -o lang++/parser.cc", "location.hh" would now include:
3050 #ifndef YY_LANG_LOCATION_HH
3051 # define YY_LANG_LOCATION_HH
3053 #endif // !YY_LANG_LOCATION_HH
3057 The position and location constructors (and their initialize methods)
3058 accept new arguments for line and column. Several issues in the
3059 documentation were fixed.
3061 ** liby is no longer asking for "rpl_fprintf" on some platforms.
3063 ** Changes in the manual:
3065 *** %printer is documented
3067 The "%printer" directive, supported since at least Bison 1.50, is finally
3068 documented. The "mfcalc" example is extended to demonstrate it.
3070 For consistency with the C skeletons, the C++ parsers now also support
3071 "yyoutput" (as an alias to "debug_stream ()").
3073 *** Several improvements have been made:
3075 The layout for grammar excerpts was changed to a more compact scheme.
3076 Named references are motivated. The description of the automaton
3077 description file (*.output) is updated to the current format. Incorrect
3078 index entries were fixed. Some other errors were fixed.
3082 *** Conflicting prototypes with recent/modified Flex.
3084 Fixed build problems with the current, unreleased, version of Flex, and
3085 some modified versions of 2.5.35, which have modified function prototypes.
3087 *** Warnings during the build procedure have been eliminated.
3089 *** Several portability problems in the test suite have been fixed:
3091 This includes warnings with some compilers, unexpected behavior of tools
3092 such as diff, warning messages from the test suite itself, etc.
3094 *** The install-pdf target works properly:
3096 Running "make install-pdf" (or -dvi, -html, -info, and -ps) no longer
3097 halts in the middle of its course.
3100 * Noteworthy changes in release 2.5 (2011-05-14)
3102 ** Grammar symbol names can now contain non-initial dashes:
3104 Consistently with directives (such as %error-verbose) and with
3105 %define variables (e.g. push-pull), grammar symbol names may contain
3106 dashes in any position except the beginning. This is a GNU
3107 extension over POSIX Yacc. Thus, use of this extension is reported
3108 by -Wyacc and rejected in Yacc mode (--yacc).
3110 ** Named references:
3112 Historically, Yacc and Bison have supported positional references
3113 ($n, $$) to allow access to symbol values from inside of semantic
3116 Starting from this version, Bison can also accept named references.
3117 When no ambiguity is possible, original symbol names may be used
3118 as named references:
3120 if_stmt : "if" cond_expr "then" then_stmt ';'
3121 { $if_stmt = mk_if_stmt($cond_expr, $then_stmt); }
3123 In the more common case, explicit names may be declared:
3125 stmt[res] : "if" expr[cond] "then" stmt[then] "else" stmt[else] ';'
3126 { $res = mk_if_stmt($cond, $then, $else); }
3128 Location information is also accessible using @name syntax. When
3129 accessing symbol names containing dots or dashes, explicit bracketing
3130 ($[sym.1]) must be used.
3132 These features are experimental in this version. More user feedback
3133 will help to stabilize them.
3134 Contributed by Alex Rozenman.
3136 ** IELR(1) and canonical LR(1):
3138 IELR(1) is a minimal LR(1) parser table generation algorithm. That
3139 is, given any context-free grammar, IELR(1) generates parser tables
3140 with the full language-recognition power of canonical LR(1) but with
3141 nearly the same number of parser states as LALR(1). This reduction
3142 in parser states is often an order of magnitude. More importantly,
3143 because canonical LR(1)'s extra parser states may contain duplicate
3144 conflicts in the case of non-LR(1) grammars, the number of conflicts
3145 for IELR(1) is often an order of magnitude less as well. This can
3146 significantly reduce the complexity of developing of a grammar.
3148 Bison can now generate IELR(1) and canonical LR(1) parser tables in
3149 place of its traditional LALR(1) parser tables, which remain the
3150 default. You can specify the type of parser tables in the grammar
3151 file with these directives:
3153 %define lr.type lalr
3154 %define lr.type ielr
3155 %define lr.type canonical-lr
3157 The default-reduction optimization in the parser tables can also be
3158 adjusted using "%define lr.default-reductions". For details on both
3159 of these features, see the new section "Tuning LR" in the Bison
3162 These features are experimental. More user feedback will help to
3165 ** LAC (Lookahead Correction) for syntax error handling
3167 Contributed by Joel E. Denny.
3169 Canonical LR, IELR, and LALR can suffer from a couple of problems
3170 upon encountering a syntax error. First, the parser might perform
3171 additional parser stack reductions before discovering the syntax
3172 error. Such reductions can perform user semantic actions that are
3173 unexpected because they are based on an invalid token, and they
3174 cause error recovery to begin in a different syntactic context than
3175 the one in which the invalid token was encountered. Second, when
3176 verbose error messages are enabled (with %error-verbose or the
3177 obsolete "#define YYERROR_VERBOSE"), the expected token list in the
3178 syntax error message can both contain invalid tokens and omit valid
3181 The culprits for the above problems are %nonassoc, default
3182 reductions in inconsistent states, and parser state merging. Thus,
3183 IELR and LALR suffer the most. Canonical LR can suffer only if
3184 %nonassoc is used or if default reductions are enabled for
3185 inconsistent states.
3187 LAC is a new mechanism within the parsing algorithm that solves
3188 these problems for canonical LR, IELR, and LALR without sacrificing
3189 %nonassoc, default reductions, or state merging. When LAC is in
3190 use, canonical LR and IELR behave almost exactly the same for both
3191 syntactically acceptable and syntactically unacceptable input.
3192 While LALR still does not support the full language-recognition
3193 power of canonical LR and IELR, LAC at least enables LALR's syntax
3194 error handling to correctly reflect LALR's language-recognition
3197 Currently, LAC is only supported for deterministic parsers in C.
3198 You can enable LAC with the following directive:
3200 %define parse.lac full
3202 See the new section "LAC" in the Bison manual for additional
3203 details including a few caveats.
3205 LAC is an experimental feature. More user feedback will help to
3208 ** %define improvements:
3210 *** Can now be invoked via the command line:
3212 Each of these command-line options
3215 --define=NAME[=VALUE]
3218 --force-define=NAME[=VALUE]
3220 is equivalent to this grammar file declaration
3222 %define NAME ["VALUE"]
3224 except that the manner in which Bison processes multiple definitions
3225 for the same NAME differs. Most importantly, -F and --force-define
3226 quietly override %define, but -D and --define do not. For further
3227 details, see the section "Bison Options" in the Bison manual.
3229 *** Variables renamed:
3231 The following %define variables
3234 lr.keep_unreachable_states
3236 have been renamed to
3239 lr.keep-unreachable-states
3241 The old names are now deprecated but will be maintained indefinitely
3242 for backward compatibility.
3244 *** Values no longer need to be quoted in the grammar file:
3246 If a %define value is an identifier, it no longer needs to be placed
3247 within quotations marks. For example,
3249 %define api.push-pull "push"
3253 %define api.push-pull push
3255 *** Unrecognized variables are now errors not warnings.
3257 *** Multiple invocations for any variable is now an error not a warning.
3259 ** Unrecognized %code qualifiers are now errors not warnings.
3261 ** Character literals not of length one:
3263 Previously, Bison quietly converted all character literals to length
3264 one. For example, without warning, Bison interpreted the operators in
3265 the following grammar to be the same token:
3271 Bison now warns when a character literal is not of length one. In
3272 some future release, Bison will start reporting an error instead.
3274 ** Destructor calls fixed for lookaheads altered in semantic actions:
3276 Previously for deterministic parsers in C, if a user semantic action
3277 altered yychar, the parser in some cases used the old yychar value to
3278 determine which destructor to call for the lookahead upon a syntax
3279 error or upon parser return. This bug has been fixed.
3281 ** C++ parsers use YYRHSLOC:
3283 Similarly to the C parsers, the C++ parsers now define the YYRHSLOC
3284 macro and use it in the default YYLLOC_DEFAULT. You are encouraged
3285 to use it. If, for instance, your location structure has "first"
3286 and "last" members, instead of
3288 # define YYLLOC_DEFAULT(Current, Rhs, N) \
3292 (Current).first = (Rhs)[1].location.first; \
3293 (Current).last = (Rhs)[N].location.last; \
3297 (Current).first = (Current).last = (Rhs)[0].location.last; \
3303 # define YYLLOC_DEFAULT(Current, Rhs, N) \
3307 (Current).first = YYRHSLOC (Rhs, 1).first; \
3308 (Current).last = YYRHSLOC (Rhs, N).last; \
3312 (Current).first = (Current).last = YYRHSLOC (Rhs, 0).last; \
3316 ** YYLLOC_DEFAULT in C++:
3318 The default implementation of YYLLOC_DEFAULT used to be issued in
3319 the header file. It is now output in the implementation file, after
3320 the user %code sections so that its #ifndef guard does not try to
3321 override the user's YYLLOC_DEFAULT if provided.
3323 ** YYFAIL now produces warnings and Java parsers no longer implement it:
3325 YYFAIL has existed for many years as an undocumented feature of
3326 deterministic parsers in C generated by Bison. More recently, it was
3327 a documented feature of Bison's experimental Java parsers. As
3328 promised in Bison 2.4.2's NEWS entry, any appearance of YYFAIL in a
3329 semantic action now produces a deprecation warning, and Java parsers
3330 no longer implement YYFAIL at all. For further details, including a
3331 discussion of how to suppress C preprocessor warnings about YYFAIL
3332 being unused, see the Bison 2.4.2 NEWS entry.
3334 ** Temporary hack for adding a semicolon to the user action:
3336 Previously, Bison appended a semicolon to every user action for
3337 reductions when the output language defaulted to C (specifically, when
3338 neither %yacc, %language, %skeleton, or equivalent command-line
3339 options were specified). This allowed actions such as
3341 exp: exp "+" exp { $$ = $1 + $3 };
3345 exp: exp "+" exp { $$ = $1 + $3; };
3347 As a first step in removing this misfeature, Bison now issues a
3348 warning when it appends a semicolon. Moreover, in cases where Bison
3349 cannot easily determine whether a semicolon is needed (for example, an
3350 action ending with a cpp directive or a braced compound initializer),
3351 it no longer appends one. Thus, the C compiler might now complain
3352 about a missing semicolon where it did not before. Future releases of
3353 Bison will cease to append semicolons entirely.
3355 ** Verbose syntax error message fixes:
3357 When %error-verbose or the obsolete "#define YYERROR_VERBOSE" is
3358 specified, syntax error messages produced by the generated parser
3359 include the unexpected token as well as a list of expected tokens.
3360 The effect of %nonassoc on these verbose messages has been corrected
3361 in two ways, but a more complete fix requires LAC, described above:
3363 *** When %nonassoc is used, there can exist parser states that accept no
3364 tokens, and so the parser does not always require a lookahead token
3365 in order to detect a syntax error. Because no unexpected token or
3366 expected tokens can then be reported, the verbose syntax error
3367 message described above is suppressed, and the parser instead
3368 reports the simpler message, "syntax error". Previously, this
3369 suppression was sometimes erroneously triggered by %nonassoc when a
3370 lookahead was actually required. Now verbose messages are
3371 suppressed only when all previous lookaheads have already been
3372 shifted or discarded.
3374 *** Previously, the list of expected tokens erroneously included tokens
3375 that would actually induce a syntax error because conflicts for them
3376 were resolved with %nonassoc in the current parser state. Such
3377 tokens are now properly omitted from the list.
3379 *** Expected token lists are still often wrong due to state merging
3380 (from LALR or IELR) and default reductions, which can both add
3381 invalid tokens and subtract valid tokens. Canonical LR almost
3382 completely fixes this problem by eliminating state merging and
3383 default reductions. However, there is one minor problem left even
3384 when using canonical LR and even after the fixes above. That is,
3385 if the resolution of a conflict with %nonassoc appears in a later
3386 parser state than the one at which some syntax error is
3387 discovered, the conflicted token is still erroneously included in
3388 the expected token list. Bison's new LAC implementation,
3389 described above, eliminates this problem and the need for
3390 canonical LR. However, LAC is still experimental and is disabled
3393 ** Java skeleton fixes:
3395 *** A location handling bug has been fixed.
3397 *** The top element of each of the value stack and location stack is now
3398 cleared when popped so that it can be garbage collected.
3400 *** Parser traces now print the top element of the stack.
3402 ** -W/--warnings fixes:
3404 *** Bison now properly recognizes the "no-" versions of categories:
3406 For example, given the following command line, Bison now enables all
3407 warnings except warnings for incompatibilities with POSIX Yacc:
3409 bison -Wall,no-yacc gram.y
3411 *** Bison now treats S/R and R/R conflicts like other warnings:
3413 Previously, conflict reports were independent of Bison's normal
3414 warning system. Now, Bison recognizes the warning categories
3415 "conflicts-sr" and "conflicts-rr". This change has important
3416 consequences for the -W and --warnings command-line options. For
3419 bison -Wno-conflicts-sr gram.y # S/R conflicts not reported
3420 bison -Wno-conflicts-rr gram.y # R/R conflicts not reported
3421 bison -Wnone gram.y # no conflicts are reported
3422 bison -Werror gram.y # any conflict is an error
3424 However, as before, if the %expect or %expect-rr directive is
3425 specified, an unexpected number of conflicts is an error, and an
3426 expected number of conflicts is not reported, so -W and --warning
3427 then have no effect on the conflict report.
3429 *** The "none" category no longer disables a preceding "error":
3431 For example, for the following command line, Bison now reports
3432 errors instead of warnings for incompatibilities with POSIX Yacc:
3434 bison -Werror,none,yacc gram.y
3436 *** The "none" category now disables all Bison warnings:
3438 Previously, the "none" category disabled only Bison warnings for
3439 which there existed a specific -W/--warning category. However,
3440 given the following command line, Bison is now guaranteed to
3441 suppress all warnings:
3445 ** Precedence directives can now assign token number 0:
3447 Since Bison 2.3b, which restored the ability of precedence
3448 directives to assign token numbers, doing so for token number 0 has
3449 produced an assertion failure. For example:
3453 This bug has been fixed.
3456 * Noteworthy changes in release 2.4.3 (2010-08-05)
3458 ** Bison now obeys -Werror and --warnings=error for warnings about
3459 grammar rules that are useless in the parser due to conflicts.
3461 ** Problems with spawning M4 on at least FreeBSD 8 and FreeBSD 9 have
3464 ** Failures in the test suite for GCC 4.5 have been fixed.
3466 ** Failures in the test suite for some versions of Sun Studio C++ have
3469 ** Contrary to Bison 2.4.2's NEWS entry, it has been decided that
3470 warnings about undefined %prec identifiers will not be converted to
3471 errors in Bison 2.5. They will remain warnings, which should be
3472 sufficient for POSIX while avoiding backward compatibility issues.
3474 ** Minor documentation fixes.
3477 * Noteworthy changes in release 2.4.2 (2010-03-20)
3479 ** Some portability problems that resulted in failures and livelocks
3480 in the test suite on some versions of at least Solaris, AIX, HP-UX,
3481 RHEL4, and Tru64 have been addressed. As a result, fatal Bison
3482 errors should no longer cause M4 to report a broken pipe on the
3485 ** "%prec IDENTIFIER" requires IDENTIFIER to be defined separately.
3487 POSIX specifies that an error be reported for any identifier that does
3488 not appear on the LHS of a grammar rule and that is not defined by
3489 %token, %left, %right, or %nonassoc. Bison 2.3b and later lost this
3490 error report for the case when an identifier appears only after a
3491 %prec directive. It is now restored. However, for backward
3492 compatibility with recent Bison releases, it is only a warning for
3493 now. In Bison 2.5 and later, it will return to being an error.
3494 [Between the 2.4.2 and 2.4.3 releases, it was decided that this
3495 warning will not be converted to an error in Bison 2.5.]
3497 ** Detection of GNU M4 1.4.6 or newer during configure is improved.
3499 ** Warnings from gcc's -Wundef option about undefined YYENABLE_NLS,
3500 YYLTYPE_IS_TRIVIAL, and __STRICT_ANSI__ in C/C++ parsers are now
3503 ** %code is now a permanent feature.
3505 A traditional Yacc prologue directive is written in the form:
3509 To provide a more flexible alternative, Bison 2.3b introduced the
3510 %code directive with the following forms for C/C++:
3513 %code requires {CODE}
3514 %code provides {CODE}
3517 These forms are now considered permanent features of Bison. See the
3518 %code entries in the section "Bison Declaration Summary" in the Bison
3519 manual for a summary of their functionality. See the section
3520 "Prologue Alternatives" for a detailed discussion including the
3521 advantages of %code over the traditional Yacc prologue directive.
3523 Bison's Java feature as a whole including its current usage of %code
3524 is still considered experimental.
3526 ** YYFAIL is deprecated and will eventually be removed.
3528 YYFAIL has existed for many years as an undocumented feature of
3529 deterministic parsers in C generated by Bison. Previously, it was
3530 documented for Bison's experimental Java parsers. YYFAIL is no longer
3531 documented for Java parsers and is formally deprecated in both cases.
3532 Users are strongly encouraged to migrate to YYERROR, which is
3535 Like YYERROR, you can invoke YYFAIL from a semantic action in order to
3536 induce a syntax error. The most obvious difference from YYERROR is
3537 that YYFAIL will automatically invoke yyerror to report the syntax
3538 error so that you don't have to. However, there are several other
3539 subtle differences between YYERROR and YYFAIL, and YYFAIL suffers from
3540 inherent flaws when %error-verbose or "#define YYERROR_VERBOSE" is
3541 used. For a more detailed discussion, see:
3543 https://lists.gnu.org/r/bison-patches/2009-12/msg00024.html
3545 The upcoming Bison 2.5 will remove YYFAIL from Java parsers, but
3546 deterministic parsers in C will continue to implement it. However,
3547 because YYFAIL is already flawed, it seems futile to try to make new
3548 Bison features compatible with it. Thus, during parser generation,
3549 Bison 2.5 will produce a warning whenever it discovers YYFAIL in a
3550 rule action. In a later release, YYFAIL will be disabled for
3551 %error-verbose and "#define YYERROR_VERBOSE". Eventually, YYFAIL will
3552 be removed altogether.
3554 There exists at least one case where Bison 2.5's YYFAIL warning will
3555 be a false positive. Some projects add phony uses of YYFAIL and other
3556 Bison-defined macros for the sole purpose of suppressing C
3557 preprocessor warnings (from GCC cpp's -Wunused-macros, for example).
3558 To avoid Bison's future warning, such YYFAIL uses can be moved to the
3559 epilogue (that is, after the second "%%") in the Bison input file. In
3560 this release (2.4.2), Bison already generates its own code to suppress
3561 C preprocessor warnings for YYFAIL, so projects can remove their own
3562 phony uses of YYFAIL if compatibility with Bison releases prior to
3563 2.4.2 is not necessary.
3565 ** Internationalization.
3567 Fix a regression introduced in Bison 2.4: Under some circumstances,
3568 message translations were not installed although supported by the
3572 * Noteworthy changes in release 2.4.1 (2008-12-11)
3574 ** In the GLR defines file, unexpanded M4 macros in the yylval and yylloc
3575 declarations have been fixed.
3577 ** Temporary hack for adding a semicolon to the user action.
3579 Bison used to prepend a trailing semicolon at the end of the user
3580 action for reductions. This allowed actions such as
3582 exp: exp "+" exp { $$ = $1 + $3 };
3586 exp: exp "+" exp { $$ = $1 + $3; };
3588 Some grammars still depend on this "feature". Bison 2.4.1 restores
3589 the previous behavior in the case of C output (specifically, when
3590 neither %language or %skeleton or equivalent command-line options
3591 are used) to leave more time for grammars depending on the old
3592 behavior to be adjusted. Future releases of Bison will disable this
3595 ** A few minor improvements to the Bison manual.
3598 * Noteworthy changes in release 2.4 (2008-11-02)
3600 ** %language is an experimental feature.
3602 We first introduced this feature in test release 2.3b as a cleaner
3603 alternative to %skeleton. Since then, we have discussed the possibility of
3604 modifying its effect on Bison's output file names. Thus, in this release,
3605 we consider %language to be an experimental feature that will likely evolve
3608 ** Forward compatibility with GNU M4 has been improved.
3610 ** Several bugs in the C++ skeleton and the experimental Java skeleton have been
3614 * Noteworthy changes in release 2.3b (2008-05-27)
3616 ** The quotes around NAME that used to be required in the following directive
3619 %define NAME "VALUE"
3621 ** The directive "%pure-parser" is now deprecated in favor of:
3625 which has the same effect except that Bison is more careful to warn about
3626 unreasonable usage in the latter case.
3630 Bison can now generate an LALR(1) parser in C with a push interface. That
3631 is, instead of invoking "yyparse", which pulls tokens from "yylex", you can
3632 push one token at a time to the parser using "yypush_parse", which will
3633 return to the caller after processing each token. By default, the push
3634 interface is disabled. Either of the following directives will enable it:
3636 %define api.push_pull "push" // Just push; does not require yylex.
3637 %define api.push_pull "both" // Push and pull; requires yylex.
3639 See the new section "A Push Parser" in the Bison manual for details.
3641 The current push parsing interface is experimental and may evolve. More user
3642 feedback will help to stabilize it.
3644 ** The -g and --graph options now output graphs in Graphviz DOT format,
3645 not VCG format. Like --graph, -g now also takes an optional FILE argument
3646 and thus cannot be bundled with other short options.
3650 Bison can now generate an LALR(1) parser in Java. The skeleton is
3651 "data/lalr1.java". Consider using the new %language directive instead of
3652 %skeleton to select it.
3654 See the new section "Java Parsers" in the Bison manual for details.
3656 The current Java interface is experimental and may evolve. More user
3657 feedback will help to stabilize it.
3658 Contributed by Paolo Bonzini.
3662 This new directive specifies the programming language of the generated
3663 parser, which can be C (the default), C++, or Java. Besides the skeleton
3664 that Bison uses, the directive affects the names of the generated files if
3665 the grammar file's name ends in ".y".
3667 ** XML Automaton Report
3669 Bison can now generate an XML report of the LALR(1) automaton using the new
3670 "--xml" option. The current XML schema is experimental and may evolve. More
3671 user feedback will help to stabilize it.
3672 Contributed by Wojciech Polak.
3674 ** The grammar file may now specify the name of the parser header file using
3675 %defines. For example:
3679 ** When reporting useless rules, useless nonterminals, and unused terminals,
3680 Bison now employs the terms "useless in grammar" instead of "useless",
3681 "useless in parser" instead of "never reduced", and "unused in grammar"
3682 instead of "unused".
3684 ** Unreachable State Removal
3686 Previously, Bison sometimes generated parser tables containing unreachable
3687 states. A state can become unreachable during conflict resolution if Bison
3688 disables a shift action leading to it from a predecessor state. Bison now:
3690 1. Removes unreachable states.
3692 2. Does not report any conflicts that appeared in unreachable states.
3693 WARNING: As a result, you may need to update %expect and %expect-rr
3694 directives in existing grammar files.
3696 3. For any rule used only in such states, Bison now reports the rule as
3697 "useless in parser due to conflicts".
3699 This feature can be disabled with the following directive:
3701 %define lr.keep_unreachable_states
3703 See the %define entry in the "Bison Declaration Summary" in the Bison manual
3704 for further discussion.
3706 ** Lookahead Set Correction in the ".output" Report
3708 When instructed to generate a ".output" file including lookahead sets
3709 (using "--report=lookahead", for example), Bison now prints each reduction's
3710 lookahead set only next to the associated state's one item that (1) is
3711 associated with the same rule as the reduction and (2) has its dot at the end
3712 of its RHS. Previously, Bison also erroneously printed the lookahead set
3713 next to all of the state's other items associated with the same rule. This
3714 bug affected only the ".output" file and not the generated parser source
3717 ** --report-file=FILE is a new option to override the default ".output" file
3720 ** The "=" that used to be required in the following directives is now
3723 %file-prefix "parser"
3727 ** An Alternative to "%{...%}" -- "%code QUALIFIER {CODE}"
3729 Bison 2.3a provided a new set of directives as a more flexible alternative to
3730 the traditional Yacc prologue blocks. Those have now been consolidated into
3731 a single %code directive with an optional qualifier field, which identifies
3732 the purpose of the code and thus the location(s) where Bison should generate
3735 1. "%code {CODE}" replaces "%after-header {CODE}"
3736 2. "%code requires {CODE}" replaces "%start-header {CODE}"
3737 3. "%code provides {CODE}" replaces "%end-header {CODE}"
3738 4. "%code top {CODE}" replaces "%before-header {CODE}"
3740 See the %code entries in section "Bison Declaration Summary" in the Bison
3741 manual for a summary of the new functionality. See the new section "Prologue
3742 Alternatives" for a detailed discussion including the advantages of %code
3743 over the traditional Yacc prologues.
3745 The prologue alternatives are experimental. More user feedback will help to
3746 determine whether they should become permanent features.
3748 ** Revised warning: unset or unused midrule values
3750 Since Bison 2.2, Bison has warned about midrule values that are set but not
3751 used within any of the actions of the parent rule. For example, Bison warns
3754 exp: '1' { $$ = 1; } '+' exp { $$ = $1 + $4; };
3756 Now, Bison also warns about midrule values that are used but not set. For
3757 example, Bison warns about unset $$ in the midrule action in:
3759 exp: '1' { $1 = 1; } '+' exp { $$ = $2 + $4; };
3761 However, Bison now disables both of these warnings by default since they
3762 sometimes prove to be false alarms in existing grammars employing the Yacc
3763 constructs $0 or $-N (where N is some positive integer).
3765 To enable these warnings, specify the option "--warnings=midrule-values" or
3766 "-W", which is a synonym for "--warnings=all".
3768 ** Default %destructor or %printer with "<*>" or "<>"
3770 Bison now recognizes two separate kinds of default %destructor's and
3773 1. Place "<*>" in a %destructor/%printer symbol list to define a default
3774 %destructor/%printer for all grammar symbols for which you have formally
3775 declared semantic type tags.
3777 2. Place "<>" in a %destructor/%printer symbol list to define a default
3778 %destructor/%printer for all grammar symbols without declared semantic
3781 Bison no longer supports the "%symbol-default" notation from Bison 2.3a.
3782 "<*>" and "<>" combined achieve the same effect with one exception: Bison no
3783 longer applies any %destructor to a midrule value if that midrule value is
3784 not actually ever referenced using either $$ or $n in a semantic action.
3786 The default %destructor's and %printer's are experimental. More user
3787 feedback will help to determine whether they should become permanent
3790 See the section "Freeing Discarded Symbols" in the Bison manual for further
3793 ** %left, %right, and %nonassoc can now declare token numbers. This is required
3794 by POSIX. However, see the end of section "Operator Precedence" in the Bison
3795 manual for a caveat concerning the treatment of literal strings.
3797 ** The nonfunctional --no-parser, -n, and %no-parser options have been
3798 completely removed from Bison.
3801 * Noteworthy changes in release 2.3a (2006-09-13)
3803 ** Instead of %union, you can define and use your own union type
3804 YYSTYPE if your grammar contains at least one <type> tag.
3805 Your YYSTYPE need not be a macro; it can be a typedef.
3806 This change is for compatibility with other Yacc implementations,
3807 and is required by POSIX.
3809 ** Locations columns and lines start at 1.
3810 In accordance with the GNU Coding Standards and Emacs.
3812 ** You may now declare per-type and default %destructor's and %printer's:
3816 %union { char *string; }
3817 %token <string> STRING1
3818 %token <string> STRING2
3819 %type <string> string1
3820 %type <string> string2
3821 %union { char character; }
3822 %token <character> CHR
3823 %type <character> chr
3824 %destructor { free ($$); } %symbol-default
3825 %destructor { free ($$); printf ("%d", @$.first_line); } STRING1 string1
3826 %destructor { } <character>
3828 guarantees that, when the parser discards any user-defined symbol that has a
3829 semantic type tag other than "<character>", it passes its semantic value to
3830 "free". However, when the parser discards a "STRING1" or a "string1", it
3831 also prints its line number to "stdout". It performs only the second
3832 "%destructor" in this case, so it invokes "free" only once.
3834 [Although we failed to mention this here in the 2.3a release, the default
3835 %destructor's and %printer's were experimental, and they were rewritten in
3838 ** Except for LALR(1) parsers in C with POSIX Yacc emulation enabled (with "-y",
3839 "--yacc", or "%yacc"), Bison no longer generates #define statements for
3840 associating token numbers with token names. Removing the #define statements
3841 helps to sanitize the global namespace during preprocessing, but POSIX Yacc
3842 requires them. Bison still generates an enum for token names in all cases.
3844 ** Handling of traditional Yacc prologue blocks is now more consistent but
3845 potentially incompatible with previous releases of Bison.
3847 As before, you declare prologue blocks in your grammar file with the
3848 "%{ ... %}" syntax. To generate the pre-prologue, Bison concatenates all
3849 prologue blocks that you've declared before the first %union. To generate
3850 the post-prologue, Bison concatenates all prologue blocks that you've
3851 declared after the first %union.
3853 Previous releases of Bison inserted the pre-prologue into both the header
3854 file and the code file in all cases except for LALR(1) parsers in C. In the
3855 latter case, Bison inserted it only into the code file. For parsers in C++,
3856 the point of insertion was before any token definitions (which associate
3857 token numbers with names). For parsers in C, the point of insertion was
3858 after the token definitions.
3860 Now, Bison never inserts the pre-prologue into the header file. In the code
3861 file, it always inserts it before the token definitions.
3863 ** Bison now provides a more flexible alternative to the traditional Yacc
3864 prologue blocks: %before-header, %start-header, %end-header, and
3867 For example, the following declaration order in the grammar file reflects the
3868 order in which Bison will output these code blocks. However, you are free to
3869 declare these code blocks in your grammar file in whatever order is most
3873 /* Bison treats this block like a pre-prologue block: it inserts it into
3874 * the code file before the contents of the header file. It does *not*
3875 * insert it into the header file. This is a good place to put
3876 * #include's that you want at the top of your code file. A common
3877 * example is '#include "system.h"'. */
3880 /* Bison inserts this block into both the header file and the code file.
3881 * In both files, the point of insertion is before any Bison-generated
3882 * token, semantic type, location type, and class definitions. This is a
3883 * good place to define %union dependencies, for example. */
3886 /* Unlike the traditional Yacc prologue blocks, the output order for the
3887 * new %*-header blocks is not affected by their declaration position
3888 * relative to any %union in the grammar file. */
3891 /* Bison inserts this block into both the header file and the code file.
3892 * In both files, the point of insertion is after the Bison-generated
3893 * definitions. This is a good place to declare or define public
3894 * functions or data structures that depend on the Bison-generated
3898 /* Bison treats this block like a post-prologue block: it inserts it into
3899 * the code file after the contents of the header file. It does *not*
3900 * insert it into the header file. This is a good place to declare or
3901 * define internal functions or data structures that depend on the
3902 * Bison-generated definitions. */
3905 If you have multiple occurrences of any one of the above declarations, Bison
3906 will concatenate the contents in declaration order.
3908 [Although we failed to mention this here in the 2.3a release, the prologue
3909 alternatives were experimental, and they were rewritten in future versions.]
3911 ** The option "--report=look-ahead" has been changed to "--report=lookahead".
3912 The old spelling still works, but is not documented and may be removed
3913 in a future release.
3916 * Noteworthy changes in release 2.3 (2006-06-05)
3918 ** GLR grammars should now use "YYRECOVERING ()" instead of "YYRECOVERING",
3919 for compatibility with LALR(1) grammars.
3921 ** It is now documented that any definition of YYSTYPE or YYLTYPE should
3922 be to a type name that does not contain parentheses or brackets.
3925 * Noteworthy changes in release 2.2 (2006-05-19)
3927 ** The distribution terms for all Bison-generated parsers now permit
3928 using the parsers in nonfree programs. Previously, this permission
3929 was granted only for Bison-generated LALR(1) parsers in C.
3931 ** %name-prefix changes the namespace name in C++ outputs.
3933 ** The C++ parsers export their token_type.
3935 ** Bison now allows multiple %union declarations, and concatenates
3936 their contents together.
3938 ** New warning: unused values
3939 Right-hand side symbols whose values are not used are reported,
3940 if the symbols have destructors. For instance:
3942 exp: exp "?" exp ":" exp { $1 ? $1 : $3; }
3946 will trigger a warning about $$ and $5 in the first rule, and $3 in
3947 the second ($1 is copied to $$ by the default rule). This example
3948 most likely contains three errors, and could be rewritten as:
3950 exp: exp "?" exp ":" exp
3951 { $$ = $1 ? $3 : $5; free ($1 ? $5 : $3); free ($1); }
3953 { $$ = $1 ? $1 : $3; if ($1) free ($3); }
3956 However, if the original actions were really intended, memory leaks
3957 and all, the warnings can be suppressed by letting Bison believe the
3958 values are used, e.g.:
3960 exp: exp "?" exp ":" exp { $1 ? $1 : $3; (void) ($$, $5); }
3961 | exp "+" exp { $$ = $1; (void) $3; }
3964 If there are midrule actions, the warning is issued if no action
3965 uses it. The following triggers no warning: $1 and $3 are used.
3967 exp: exp { push ($1); } '+' exp { push ($3); sum (); };
3969 The warning is intended to help catching lost values and memory leaks.
3970 If a value is ignored, its associated memory typically is not reclaimed.
3972 ** %destructor vs. YYABORT, YYACCEPT, and YYERROR.
3973 Destructors are now called when user code invokes YYABORT, YYACCEPT,
3974 and YYERROR, for all objects on the stack, other than objects
3975 corresponding to the right-hand side of the current rule.
3977 ** %expect, %expect-rr
3978 Incorrect numbers of expected conflicts are now actual errors,
3979 instead of warnings.
3981 ** GLR, YACC parsers.
3982 The %parse-params are available in the destructors (and the
3983 experimental printers) as per the documentation.
3985 ** Bison now warns if it finds a stray "$" or "@" in an action.
3987 ** %require "VERSION"
3988 This specifies that the grammar file depends on features implemented
3989 in Bison version VERSION or higher.
3991 ** lalr1.cc: The token and value types are now class members.
3992 The tokens were defined as free form enums and cpp macros. YYSTYPE
3993 was defined as a free form union. They are now class members:
3994 tokens are enumerations of the "yy::parser::token" struct, and the
3995 semantic values have the "yy::parser::semantic_type" type.
3997 If you do not want or can update to this scheme, the directive
3998 '%define "global_tokens_and_yystype" "1"' triggers the global
3999 definition of tokens and YYSTYPE. This change is suitable both
4000 for previous releases of Bison, and this one.
4002 If you wish to update, then make sure older version of Bison will
4003 fail using '%require "2.2"'.
4005 ** DJGPP support added.
4008 * Noteworthy changes in release 2.1 (2005-09-16)
4010 ** The C++ lalr1.cc skeleton supports %lex-param.
4012 ** Bison-generated parsers now support the translation of diagnostics like
4013 "syntax error" into languages other than English. The default
4014 language is still English. For details, please see the new
4015 Internationalization section of the Bison manual. Software
4016 distributors should also see the new PACKAGING file. Thanks to
4017 Bruno Haible for this new feature.
4019 ** Wording in the Bison-generated parsers has been changed slightly to
4020 simplify translation. In particular, the message "memory exhausted"
4021 has replaced "parser stack overflow", as the old message was not
4022 always accurate for modern Bison-generated parsers.
4024 ** Destructors are now called when the parser aborts, for all symbols left
4025 behind on the stack. Also, the start symbol is now destroyed after a
4026 successful parse. In both cases, the behavior was formerly inconsistent.
4028 ** When generating verbose diagnostics, Bison-generated parsers no longer
4029 quote the literal strings associated with tokens. For example, for
4030 a syntax error associated with '%token NUM "number"' they might
4031 print 'syntax error, unexpected number' instead of 'syntax error,
4032 unexpected "number"'.
4035 * Noteworthy changes in release 2.0 (2004-12-25)
4037 ** Possibly-incompatible changes
4039 - Bison-generated parsers no longer default to using the alloca function
4040 (when available) to extend the parser stack, due to widespread
4041 problems in unchecked stack-overflow detection. You can "#define
4042 YYSTACK_USE_ALLOCA 1" to require the use of alloca, but please read
4043 the manual to determine safe values for YYMAXDEPTH in that case.
4045 - Error token location.
4046 During error recovery, the location of the syntax error is updated
4047 to cover the whole sequence covered by the error token: it includes
4048 the shifted symbols thrown away during the first part of the error
4049 recovery, and the lookahead rejected during the second part.
4051 - Semicolon changes:
4052 . Stray semicolons are no longer allowed at the start of a grammar.
4053 . Semicolons are now required after in-grammar declarations.
4055 - Unescaped newlines are no longer allowed in character constants or
4056 string literals. They were never portable, and GCC 3.4.0 has
4057 dropped support for them. Better diagnostics are now generated if
4058 forget a closing quote.
4060 - NUL bytes are no longer allowed in Bison string literals, unfortunately.
4064 - GLR grammars now support locations.
4066 - New directive: %initial-action.
4067 This directive allows the user to run arbitrary code (including
4068 initializing @$) from yyparse before parsing starts.
4070 - A new directive "%expect-rr N" specifies the expected number of
4071 reduce/reduce conflicts in GLR parsers.
4073 - %token numbers can now be hexadecimal integers, e.g., "%token FOO 0x12d".
4074 This is a GNU extension.
4076 - The option "--report=lookahead" was changed to "--report=look-ahead".
4077 [However, this was changed back after 2.3.]
4079 - Experimental %destructor support has been added to lalr1.cc.
4081 - New configure option --disable-yacc, to disable installation of the
4082 yacc command and -ly library introduced in 1.875 for POSIX conformance.
4086 - For now, %expect-count violations are now just warnings, not errors.
4087 This is for compatibility with Bison 1.75 and earlier (when there are
4088 reduce/reduce conflicts) and with Bison 1.30 and earlier (when there
4089 are too many or too few shift/reduce conflicts). However, in future
4090 versions of Bison we plan to improve the %expect machinery so that
4091 these violations will become errors again.
4093 - Within Bison itself, numbers (e.g., goto numbers) are no longer
4094 arbitrarily limited to 16-bit counts.
4096 - Semicolons are now allowed before "|" in grammar rules, as POSIX requires.
4099 * Noteworthy changes in release 1.875 (2003-01-01)
4101 ** The documentation license has been upgraded to version 1.2
4102 of the GNU Free Documentation License.
4104 ** syntax error processing
4106 - In Yacc-style parsers YYLLOC_DEFAULT is now used to compute error
4107 locations too. This fixes bugs in error-location computation.
4110 It is now possible to reclaim the memory associated to symbols
4111 discarded during error recovery. This feature is still experimental.
4114 This new directive is preferred over YYERROR_VERBOSE.
4116 - #defining yyerror to steal internal variables is discouraged.
4117 It is not guaranteed to work forever.
4119 ** POSIX conformance
4121 - Semicolons are once again optional at the end of grammar rules.
4122 This reverts to the behavior of Bison 1.33 and earlier, and improves
4123 compatibility with Yacc.
4125 - "parse error" -> "syntax error"
4126 Bison now uniformly uses the term "syntax error"; formerly, the code
4127 and manual sometimes used the term "parse error" instead. POSIX
4128 requires "syntax error" in diagnostics, and it was thought better to
4131 - The documentation now emphasizes that yylex and yyerror must be
4132 declared before use. C99 requires this.
4134 - Bison now parses C99 lexical constructs like UCNs and
4135 backslash-newline within C escape sequences, as POSIX 1003.1-2001 requires.
4137 - File names are properly escaped in C output. E.g., foo\bar.y is
4138 output as "foo\\bar.y".
4140 - Yacc command and library now available
4141 The Bison distribution now installs a "yacc" command, as POSIX requires.
4142 Also, Bison now installs a small library liby.a containing
4143 implementations of Yacc-compatible yyerror and main functions.
4144 This library is normally not useful, but POSIX requires it.
4146 - Type clashes now generate warnings, not errors.
4148 - If the user does not define YYSTYPE as a macro, Bison now declares it
4149 using typedef instead of defining it as a macro.
4150 For consistency, YYLTYPE is also declared instead of defined.
4152 ** Other compatibility issues
4154 - %union directives can now have a tag before the "{", e.g., the
4155 directive "%union foo {...}" now generates the C code
4156 "typedef union foo { ... } YYSTYPE;"; this is for Yacc compatibility.
4157 The default union tag is "YYSTYPE", for compatibility with Solaris 9 Yacc.
4158 For consistency, YYLTYPE's struct tag is now "YYLTYPE" not "yyltype".
4159 This is for compatibility with both Yacc and Bison 1.35.
4161 - ";" is output before the terminating "}" of an action, for
4162 compatibility with Bison 1.35.
4164 - Bison now uses a Yacc-style format for conflict reports, e.g.,
4165 "conflicts: 2 shift/reduce, 1 reduce/reduce".
4167 - "yystype" and "yyltype" are now obsolescent macros instead of being
4168 typedefs or tags; they are no longer documented and are planned to be
4169 withdrawn in a future release.
4174 Users of Bison have to decide how they handle the portability of the
4177 - "parsing stack overflow..." -> "parser stack overflow"
4178 GLR parsers now report "parser stack overflow" as per the Bison manual.
4180 ** %parse-param and %lex-param
4181 The macros YYPARSE_PARAM and YYLEX_PARAM provide a means to pass
4182 additional context to yyparse and yylex. They suffer from several
4185 - a single argument only can be added,
4186 - their types are weak (void *),
4187 - this context is not passed to ancillary functions such as yyerror,
4188 - only yacc.c parsers support them.
4190 The new %parse-param/%lex-param directives provide a more precise control.
4193 %parse-param {int *nastiness}
4194 %lex-param {int *nastiness}
4195 %parse-param {int *randomness}
4197 results in the following signatures:
4199 int yylex (int *nastiness);
4200 int yyparse (int *nastiness, int *randomness);
4202 or, if both %pure-parser and %locations are used:
4204 int yylex (YYSTYPE *lvalp, YYLTYPE *llocp, int *nastiness);
4205 int yyparse (int *nastiness, int *randomness);
4207 ** Bison now warns if it detects conflicting outputs to the same file,
4208 e.g., it generates a warning for "bison -d -o foo.h foo.y" since
4209 that command outputs both code and header to foo.h.
4211 ** #line in output files
4212 - --no-line works properly.
4214 ** Bison can no longer be built by a K&R C compiler; it requires C89 or
4215 later to be built. This change originally took place a few versions
4216 ago, but nobody noticed until we recently asked someone to try
4217 building Bison with a K&R C compiler.
4220 * Noteworthy changes in release 1.75 (2002-10-14)
4222 ** Bison should now work on 64-bit hosts.
4224 ** Indonesian translation thanks to Tedi Heriyanto.
4227 Fix spurious parse errors.
4230 Some people redefine yyerror to steal yyparse' private variables.
4231 Reenable this trick until an official feature replaces it.
4234 In agreement with POSIX and with other Yaccs, leaving a default
4235 action is valid when $$ is untyped, and $1 typed:
4239 but the converse remains an error:
4243 ** Values of midrule actions
4246 foo: { ... } { $$ = $1; } ...
4248 was incorrectly rejected: $1 is defined in the second midrule
4249 action, and is equal to the $$ of the first midrule action.
4252 * Noteworthy changes in release 1.50 (2002-10-04)
4257 causes Bison to produce a Generalized LR (GLR) parser, capable of handling
4258 almost any context-free grammar, ambiguous or not. The new declarations
4259 %dprec and %merge on grammar rules allow parse-time resolution of
4260 ambiguities. Contributed by Paul Hilfinger.
4262 Unfortunately Bison 1.50 does not work properly on 64-bit hosts
4263 like the Alpha, so please stick to 32-bit hosts for now.
4266 When not in Yacc compatibility mode, when the output file was not
4267 specified, running "bison foo/bar.y" created "foo/bar.c". It
4268 now creates "bar.c".
4271 The undefined token was systematically mapped to 2 which prevented
4272 the use of 2 by the user. This is no longer the case.
4274 ** Unknown token numbers
4275 If yylex returned an out of range value, yyparse could die. This is
4279 According to POSIX, the error token must be 256.
4280 Bison extends this requirement by making it a preference: *if* the
4281 user specified that one of her tokens is numbered 256, then error
4282 will be mapped onto another number.
4284 ** Verbose error messages
4285 They no longer report "..., expecting error or..." for states where
4286 error recovery is possible.
4289 Defaults to "$end" instead of "$".
4291 ** Error recovery now conforms to documentation and to POSIX
4292 When a Bison-generated parser encounters a syntax error, it now pops
4293 the stack until it finds a state that allows shifting the error
4294 token. Formerly, it popped the stack until it found a state that
4295 allowed some non-error action other than a default reduction on the
4296 error token. The new behavior has long been the documented behavior,
4297 and has long been required by POSIX. For more details, please see
4298 Paul Eggert, "Reductions during Bison error handling" (2002-05-20)
4299 <https://lists.gnu.org/r/bug-bison/2002-05/msg00038.html>.
4302 Popped tokens and nonterminals are now reported.
4305 Larger grammars are now supported (larger token numbers, larger grammar
4306 size (= sum of the LHS and RHS lengths), larger LALR tables).
4307 Formerly, many of these numbers ran afoul of 16-bit limits;
4308 now these limits are 32 bits on most hosts.
4310 ** Explicit initial rule
4311 Bison used to play hacks with the initial rule, which the user does
4312 not write. It is now explicit, and visible in the reports and
4316 Before, Bison reported the useless rules, but, although not used,
4317 included them in the parsers. They are now actually removed.
4319 ** Useless rules, useless nonterminals
4320 They are now reported, as a warning, with their locations.
4322 ** Rules never reduced
4323 Rules that can never be reduced because of conflicts are now
4326 ** Incorrect "Token not used"
4327 On a grammar such as
4329 %token useless useful
4331 exp: '0' %prec useful;
4333 where a token was used to set the precedence of the last rule,
4334 bison reported both "useful" and "useless" as useless tokens.
4336 ** Revert the C++ namespace changes introduced in 1.31
4337 as they caused too many portability hassles.
4339 ** Default locations
4340 By an accident of design, the default computation of @$ was
4341 performed after another default computation was performed: @$ = @1.
4342 The latter is now removed: YYLLOC_DEFAULT is fully responsible of
4343 the computation of @$.
4345 ** Token end-of-file
4346 The token end of file may be specified by the user, in which case,
4347 the user symbol is used in the reports, the graphs, and the verbose
4348 error messages instead of "$end", which remains being the default.
4352 %token MYEOF 0 "end of file"
4355 This old option, which has been broken for ages, is removed.
4358 Brazilian Portuguese, thanks to Alexandre Folle de Menezes.
4359 Croatian, thanks to Denis Lackovic.
4361 ** Incorrect token definitions
4364 bison used to output
4367 ** Token definitions as enums
4368 Tokens are output both as the traditional #define's, and, provided
4369 the compiler supports ANSI C or is a C++ compiler, as enums.
4370 This lets debuggers display names instead of integers.
4373 In addition to --verbose, bison supports --report=THINGS, which
4374 produces additional information:
4376 complete the core item sets with their closure
4377 - lookahead [changed to "look-ahead" in 1.875e through 2.3, but changed back]
4378 explicitly associate lookahead tokens to items
4380 describe shift/reduce conflicts solving.
4381 Bison used to systematically output this information on top of
4382 the report. Solved conflicts are now attached to their states.
4385 Previous versions don't complain when there is a type clash on
4386 the default action if the rule has a midrule action, such as in:
4394 ** GNU M4 is now required when using Bison.
4397 * Noteworthy changes in release 1.35 (2002-03-25)
4400 Some projects use Bison's C parser with C++ compilers, and define
4401 YYSTYPE as a class. The recent adjustment of C parsers for data
4402 alignment and 64 bit architectures made this impossible.
4404 Because for the time being no real solution for C++ parser
4405 generation exists, kludges were implemented in the parser to
4406 maintain this use. In the future, when Bison has C++ parsers, this
4407 kludge will be disabled.
4409 This kludge also addresses some C++ problems when the stack was
4413 * Noteworthy changes in release 1.34 (2002-03-12)
4415 ** File name clashes are detected
4416 $ bison foo.y -d -o foo.x
4417 fatal error: header and parser would both be named "foo.x"
4419 ** A missing ";" at the end of a rule triggers a warning
4420 In accordance with POSIX, and in agreement with other
4421 Yacc implementations, Bison will mandate this semicolon in the near
4422 future. This eases the implementation of a Bison parser of Bison
4423 grammars by making this grammar LALR(1) instead of LR(2). To
4424 facilitate the transition, this release introduces a warning.
4426 ** Revert the C++ namespace changes introduced in 1.31, as they caused too
4427 many portability hassles.
4429 ** DJGPP support added.
4431 ** Fix test suite portability problems.
4434 * Noteworthy changes in release 1.33 (2002-02-07)
4437 Groff could not be compiled for the definition of size_t was lacking
4438 under some conditions.
4444 * Noteworthy changes in release 1.32 (2002-01-23)
4446 ** Fix Yacc output file names
4448 ** Portability fixes
4450 ** Italian, Dutch translations
4453 * Noteworthy changes in release 1.31 (2002-01-14)
4457 ** GNU Gettext and %expect
4458 GNU Gettext asserts 10 s/r conflicts, but there are 7. Now that
4459 Bison dies on incorrect %expectations, we fear there will be
4460 too many bug reports for Gettext, so _for the time being_, %expect
4461 does not trigger an error when the input file is named "plural.y".
4463 ** Use of alloca in parsers
4464 If YYSTACK_USE_ALLOCA is defined to 0, then the parsers will use
4465 malloc exclusively. Since 1.29, but was not NEWS'ed.
4467 alloca is used only when compiled with GCC, to avoid portability
4470 ** yyparse now returns 2 if memory is exhausted; formerly it dumped core.
4472 ** When the generated parser lacks debugging code, YYDEBUG is now 0
4473 (as POSIX requires) instead of being undefined.
4476 Bison has always permitted actions such as { $$ = $1 }: it adds the
4477 ending semicolon. Now if in Yacc compatibility mode, the semicolon
4478 is no longer output: one has to write { $$ = $1; }.
4480 ** Better C++ compliance
4481 The output parsers try to respect C++ namespaces.
4482 [This turned out to be a failed experiment, and it was reverted later.]
4485 Fixed bugs when reporting useless nonterminals.
4488 The parsers work properly on 64 bit hosts.
4491 Some calls to strerror resulted in scrambled or missing error messages.
4494 When the number of shift/reduce conflicts is correct, don't issue
4497 ** The verbose report includes the rule line numbers.
4499 ** Rule line numbers are fixed in traces.
4501 ** Swedish translation
4504 Verbose parse error messages from the parsers are better looking.
4505 Before: parse error: unexpected `'/'', expecting `"number"' or `'-'' or `'(''
4506 Now: parse error: unexpected '/', expecting "number" or '-' or '('
4508 ** Fixed parser memory leaks.
4509 When the generated parser was using malloc to extend its stacks, the
4510 previous allocations were not freed.
4512 ** Fixed verbose output file.
4513 Some newlines were missing.
4514 Some conflicts in state descriptions were missing.
4516 ** Fixed conflict report.
4517 Option -v was needed to get the result.
4521 Mismatches are errors, not warnings.
4523 ** Fixed incorrect processing of some invalid input.
4525 ** Fixed CPP guards: 9foo.h uses BISON_9FOO_H instead of 9FOO_H.
4527 ** Fixed some typos in the documentation.
4529 ** %token MY_EOF 0 is supported.
4530 Before, MY_EOF was silently renumbered as 257.
4532 ** doc/refcard.tex is updated.
4534 ** %output, %file-prefix, %name-prefix.
4538 New, aliasing "--output-file".
4541 * Noteworthy changes in release 1.30 (2001-10-26)
4543 ** "--defines" and "--graph" have now an optional argument which is the
4544 output file name. "-d" and "-g" do not change; they do not take any
4547 ** "%source_extension" and "%header_extension" are removed, failed
4550 ** Portability fixes.
4553 * Noteworthy changes in release 1.29 (2001-09-07)
4555 ** The output file does not define const, as this caused problems when used
4556 with common autoconfiguration schemes. If you still use ancient compilers
4557 that lack const, compile with the equivalent of the C compiler option
4558 "-Dconst=". Autoconf's AC_C_CONST macro provides one way to do this.
4560 ** Added "-g" and "--graph".
4562 ** The Bison manual is now distributed under the terms of the GNU FDL.
4564 ** The input and the output files has automatically a similar extension.
4566 ** Russian translation added.
4568 ** NLS support updated; should hopefully be less troublesome.
4570 ** Added the old Bison reference card.
4572 ** Added "--locations" and "%locations".
4574 ** Added "-S" and "--skeleton".
4576 ** "%raw", "-r", "--raw" is disabled.
4578 ** Special characters are escaped when output. This solves the problems
4579 of the #line lines with path names including backslashes.
4582 "%yacc", "%fixed_output_files", "%defines", "%no_parser", "%verbose",
4583 "%debug", "%source_extension" and "%header_extension".
4586 Automatic location tracking.
4589 * Noteworthy changes in release 1.28 (1999-07-06)
4591 ** Should compile better now with K&R compilers.
4595 ** Fixed a problem with escaping the double quote character.
4597 ** There is now a FAQ.
4600 * Noteworthy changes in release 1.27
4602 ** The make rule which prevented bison.simple from being created on
4603 some systems has been fixed.
4606 * Noteworthy changes in release 1.26
4608 ** Bison now uses Automake.
4610 ** New mailing lists: <bug-bison@gnu.org> and <help-bison@gnu.org>.
4612 ** Token numbers now start at 257 as previously documented, not 258.
4614 ** Bison honors the TMPDIR environment variable.
4616 ** A couple of buffer overruns have been fixed.
4618 ** Problems when closing files should now be reported.
4620 ** Generated parsers should now work even on operating systems which do
4621 not provide alloca().
4624 * Noteworthy changes in release 1.25 (1995-10-16)
4626 ** Errors in the input grammar are not fatal; Bison keeps reading
4627 the grammar file, and reports all the errors found in it.
4629 ** Tokens can now be specified as multiple-character strings: for
4630 example, you could use "<=" for a token which looks like <=, instead
4631 of choosing a name like LESSEQ.
4633 ** The %token_table declaration says to write a table of tokens (names
4634 and numbers) into the parser file. The yylex function can use this
4635 table to recognize multiple-character string tokens, or for other
4638 ** The %no_lines declaration says not to generate any #line preprocessor
4639 directives in the parser file.
4641 ** The %raw declaration says to use internal Bison token numbers, not
4642 Yacc-compatible token numbers, when token names are defined as macros.
4644 ** The --no-parser option produces the parser tables without including
4645 the parser engine; a project can now use its own parser engine.
4646 The actions go into a separate file called NAME.act, in the form of
4647 a switch statement body.
4650 * Noteworthy changes in release 1.23
4652 The user can define YYPARSE_PARAM as the name of an argument to be
4653 passed into yyparse. The argument should have type void *. It should
4654 actually point to an object. Grammar actions can access the variable
4655 by casting it to the proper pointer type.
4657 Line numbers in output file corrected.
4660 * Noteworthy changes in release 1.22
4662 --help option added.
4665 * Noteworthy changes in release 1.20
4667 Output file does not redefine const for C++.
4671 LocalWords: yacc YYBACKUP glr GCC lalr ArrayIndexOutOfBoundsException nullptr
4672 LocalWords: cplusplus liby rpl fprintf mfcalc Wyacc stmt cond expr mk sym lr
4673 LocalWords: IELR ielr Lookahead YYERROR nonassoc LALR's api lookaheads yychar
4674 LocalWords: destructor lookahead YYRHSLOC YYLLOC Rhs ifndef YYFAIL cpp sr rr
4675 LocalWords: preprocessor initializer Wno Wnone Werror FreeBSD prec livelocks
4676 LocalWords: Solaris AIX UX RHEL Tru LHS gcc's Wundef YYENABLE NLS YYLTYPE VCG
4677 LocalWords: yyerror cpp's Wunused yylval yylloc prepend yyparse yylex yypush
4678 LocalWords: Graphviz xml nonterminals midrule destructor's YYSTYPE typedef ly
4679 LocalWords: CHR chr printf stdout namespace preprocessing enum pre include's
4680 LocalWords: YYRECOVERING nonfree destructors YYABORT YYACCEPT params enums de
4681 LocalWords: struct yystype DJGPP lex param Haible NUM alloca YYSTACK NUL goto
4682 LocalWords: YYMAXDEPTH Unescaped UCNs YYLTYPE's yyltype typedefs inline Yaccs
4683 LocalWords: Heriyanto Reenable dprec Hilfinger Eggert MYEOF Folle Menezes EOF
4684 LocalWords: Lackovic define's itemset Groff Gettext malloc NEWS'ed YYDEBUG YY
4685 LocalWords: namespaces strerror const autoconfiguration Dconst Autoconf's FDL
4686 LocalWords: Automake TMPDIR LESSEQ ylwrap endif yydebug YYTOKEN YYLSP ival hh
4687 LocalWords: extern YYTOKENTYPE TOKENTYPE yytokentype tokentype STYPE lval pdf
4688 LocalWords: lang yyoutput dvi html ps POSIX lvalp llocp Wother nterm arg init
4689 LocalWords: TOK calc yyo fval Wconflicts parsers yystackp yyval yynerrs
4690 LocalWords: Théophile Ranquet Santet fno fnone stype associativity Tolmer
4691 LocalWords: Wprecedence Rassoul Wempty Paolo Bonzini parser's Michiel loc
4692 LocalWords: redeclaration sval fcaret reentrant XSLT xsl Wmaybe yyvsp Tedi
4693 LocalWords: pragmas noreturn untyped Rozenman unexpanded Wojciech Polak
4694 LocalWords: Alexandre MERCHANTABILITY yytype emplace ptr automove lvalues
4695 LocalWords: nonterminal yy args Pragma dereference yyformat rhs docdir bw
4696 LocalWords: Redeclarations rpcalc Autoconf YFLAGS Makefiles PROG DECL num
4697 LocalWords: Heimbigner AST src ast Makefile srcdir MinGW xxlex XXSTYPE CVE
4698 LocalWords: XXLTYPE strictfp IDEs ffixit fdiagnostics parseable fixits
4699 LocalWords: Wdeprecated yytext Variadic variadic yyrhs yyphrs RCS README
4700 LocalWords: noexcept constexpr ispell american deprecations backend Teoh
4701 LocalWords: YYPRINT Mangold Bonzini's Wdangling exVal baz checkable gcc
4702 LocalWords: fsanitize Vogelsgesang lis redeclared stdint automata yytname
4703 LocalWords: yysymbol yytnamerr yyreport ctx ARGMAX yysyntax stderr LPAREN
4704 LocalWords: symrec yypcontext TOKENMAX yyexpected YYEMPTY yypstate YYEOF
4705 LocalWords: autocompletion bistromathic submessages Cayuela lexcalc hoc
4706 LocalWords: yytoken YYUNDEF YYerror basename Automake's UTF ifdef ffile
4707 LocalWords: gotos readline Imbimbo Wcounterexamples Wcex Nonunifying rcex
4708 LocalWords: Vais xsltproc YYNOMEM YYLOCATION signedness YYBISON MITRE's
4709 LocalWords: libreadline YYMALLOC YYFREE MSVC redefinitions
4712 ispell-dictionary: "american"
4717 Copyright (C) 1995-2015, 2018-2021 Free Software Foundation, Inc.
4719 This file is part of Bison, the GNU Parser Generator.
4721 Permission is granted to copy, distribute and/or modify this document
4722 under the terms of the GNU Free Documentation License, Version 1.3 or
4723 any later version published by the Free Software Foundation; with no
4724 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
4725 Texts. A copy of the license is included in the "GNU Free
4726 Documentation License" file as part of this distribution.