3 * Noteworthy changes in release ?.? (????-??-??) [?]
7 *** A C++ native GLR parser
9 A new version of the generated C++ GLR parser was added as "glr2.cc". It
10 is forked from the existing glr.c/cc parser, with the objective of making
11 it a more modern, truly C++ parser (instead of a C++ wrapper around a C
12 parser). Down the line, the goal is to support `%define api.value.type
13 variant` and maybe share code with lalr1.cc.
15 The current parser should be identical in terms of interface, functionality
16 and performance to "glr.cc". To try it out, simply use
22 Counterexamples now show the rule numbers, and always show ε for rules
23 with an empty right-hand side. For instance
36 * Noteworthy changes in release 3.7.2 (2020-09-05) [stable]
38 This release of Bison fixes all known bugs reported for Bison in MITRE's
39 Common Vulnerabilities and Exposures (CVE) system. These vulnerabilities
40 are only about bison-the-program itself, not the generated code.
42 Although these bugs are typically irrelevant to how Bison is used, they
43 are worth fixing if only to give users peace of mind.
45 There is no known vulnerability in the generated parsers.
49 Fix concurrent build issues (introduced in Bison 3.5).
51 Push parsers always use YYMALLOC/YYFREE (no direct calls to malloc/free).
53 Fix portability issues of the test suite, and of bison itself.
55 Some unlikely crashes found by fuzzing have been fixed. This is only
56 about bison itself, not the generated parsers.
59 * Noteworthy changes in release 3.7.1 (2020-08-02) [stable]
63 Crash when a token alias contains a NUL byte.
65 Portability issues with libtextstyle.
67 Portability issues of Bison itself with MSVC.
71 Improvements and fixes in the documentation.
73 More precise location about symbol type redefinitions.
76 * Noteworthy changes in release 3.7 (2020-07-23) [stable]
78 ** Deprecated features
80 The YYPRINT macro, which works only with yacc.c and only for tokens, was
81 obsoleted long ago by %printer, introduced in Bison 1.50 (November 2002).
82 It is deprecated and its support will be removed eventually.
84 In conformance with the recommendations of the Graphviz team, in the next
85 version Bison the option `--graph` will generate a *.gv file by default,
86 instead of *.dot. A transition started in Bison 3.4.
90 *** Counterexample Generation
92 Contributed by Vincent Imbimbo.
94 When given `-Wcounterexamples`/`-Wcex`, bison will now output
95 counterexamples for conflicts.
97 **** Unifying Counterexamples
99 Unifying counterexamples are strings which can be parsed in two ways due
100 to the conflict. For example on a grammar that contains the usual
101 "dangling else" ambiguity:
104 else.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
105 else.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
108 else.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
109 else.y: warning: shift/reduce conflict on token "else" [-Wcounterexamples]
110 Example: "if" exp "then" "if" exp "then" exp • "else" exp
113 ↳ "if" exp "then" exp
114 ↳ "if" exp "then" exp • "else" exp
115 Example: "if" exp "then" "if" exp "then" exp • "else" exp
118 ↳ "if" exp "then" exp "else" exp
119 ↳ "if" exp "then" exp •
121 When text styling is enabled, colors are used in the examples and the
122 derivations to highlight the structure of both analyses. In this case,
124 "if" exp "then" [ "if" exp "then" exp • ] "else" exp
128 "if" exp "then" [ "if" exp "then" exp • "else" exp ]
131 The counterexamples are "focused", in two different ways. First, they do
132 not clutter the output with all the derivations from the start symbol,
133 rather they start on the "conflicted nonterminal". They go straight to the
134 point. Second, they don't "expand" nonterminal symbols uselessly.
136 **** Nonunifying Counterexamples
138 In the case of the dangling else, Bison found an example that can be
139 parsed in two ways (therefore proving that the grammar is ambiguous).
140 When it cannot find such an example, it instead generates two examples
141 that are the same up until the dot:
144 foo.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
145 foo.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples
146 foo.y:4.4-7: warning: rule useless in parser due to conflicts [-Wother]
151 foo.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
152 foo.y: warning: shift/reduce conflict on token ID [-Wcounterexamples]
153 First example: expr • ID ',' ID $end
160 Second example: expr • ID $end
166 foo.y:4.4-7: warning: rule useless in parser due to conflicts [-Wother]
170 In these cases, the parser usually doesn't have enough lookahead to
171 differentiate the two given examples.
175 Counterexamples are also included in the report when given
176 `--report=counterexamples`/`-rcex` (or `--report=all`), with more
181 1 exp: "if" exp "then" exp • [$end, "then", "else"]
182 2 | "if" exp "then" exp • "else" exp
184 "else" shift, and go to state 8
186 "else" [reduce using rule 1 (exp)]
187 $default reduce using rule 1 (exp)
189 shift/reduce conflict on token "else":
190 1 exp: "if" exp "then" exp •
191 2 exp: "if" exp "then" exp • "else" exp
192 Example: "if" exp "then" "if" exp "then" exp • "else" exp
195 ↳ "if" exp "then" exp
196 ↳ "if" exp "then" exp • "else" exp
197 Example: "if" exp "then" "if" exp "then" exp • "else" exp
200 ↳ "if" exp "then" exp "else" exp
201 ↳ "if" exp "then" exp •
203 *** File prefix mapping
205 Contributed by Joshua Watt.
207 Bison learned a new argument, `--file-prefix-map OLD=NEW`. Any file path
208 in the output (specifically `#line` directives and `#ifdef` header guards)
209 that begins with the prefix OLD will have it replaced with the prefix NEW,
210 similar to the `-ffile-prefix-map` in GCC. This option can be used to
211 make bison output reproducible.
217 When text styling is enabled and the terminal supports it, the warnings
218 now include hyperlinks to the documentation.
220 *** Relocatable installation
222 When installed to be relocatable (via `configure --enable-relocatable`),
223 bison will now also look for a relocated m4.
227 The `filename_type` %define variable was renamed `api.filename.type`.
230 %define filename_type "symbol"
234 %define api.filename.type {symbol}
236 (Or let `bison --update` do it for you).
238 It now defaults to `const std::string` instead of `std::string`.
240 *** Deprecated %define variable names
242 The following variables have been renamed for consistency. Backward
243 compatibility is ensured, but upgrading is recommended.
245 filename_type -> api.filename.type
246 package -> api.package
248 *** Push parsers no longer clear their state when parsing is finished
250 Previously push-parsers cleared their state when parsing was finished (on
251 success and on failure). This made it impossible to check if there were
252 parse errors, since `yynerrs` was also reset. This can be especially
253 troublesome when used in autocompletion, since a parser with error
254 recovery would suggest (irrelevant) expected tokens even if there were
257 Now the parser state can be examined when parsing is finished. The parser
258 state is reset when starting a new parse.
264 The bistromathic demonstrates %param and how to quote sources in the error
268 1.5-7: syntax error: expected end of file or + or - or * or / or ^ before number
274 *** Include the generated header (yacc.c)
276 Historically, when --defines was used, bison generated a header and pasted
277 an exact copy of it into the generated parser implementation file. Since
278 Bison 3.4 it is possible to specify that the header should be `#include`d,
279 and how. For instance
281 %define api.header.include {"parse.h"}
285 %define api.header.include {<parser/parse.h>}
287 Now api.header.include defaults to `"header-basename"`, as was intended in
288 Bison 3.4, where `header-basename` is the basename of the generated
289 header. This is disabled when the generated header is `y.tab.h`, to
290 comply with Automake's ylwrap.
292 *** String aliases are faithfully propagated
294 Bison used to interpret user strings (i.e., decoding backslash escapes)
295 when reading them, and to escape them (i.e., issue non-printable
296 characters as backslash escapes, taking the locale into account) when
297 outputting them. As a consequence non-ASCII strings (say in UTF-8) ended
298 up "ciphered" as sequences of backslash escapes. This happened not only
299 in the generated sources (where the compiler will reinterpret them), but
300 also in all the generated reports (text, xml, html, dot, etc.). Reports
301 were therefore not readable when string aliases were not pure ASCII.
302 Worse yet: the output depended on the user's locale.
304 Now Bison faithfully treats the string aliases exactly the way the user
305 spelled them. This fixes all the aforementioned problems. However, now,
306 string aliases semantically equivalent but syntactically different (e.g.,
307 "A", "\x41", "\101") are considered to be different.
309 *** Crash when generating IELR
311 An old, well hidden, bug in the generation of IELR parsers was fixed.
314 * Noteworthy changes in release 3.6.4 (2020-06-15) [stable]
318 In glr.cc some internal macros leaked in the user's code, and could damage
319 access to the token kinds.
322 * Noteworthy changes in release 3.6.3 (2020-06-03) [stable]
326 Incorrect comments in the generated parsers.
328 Warnings in push parsers (yacc.c).
330 Incorrect display of gotos in LAC traces (lalr1.cc).
333 * Noteworthy changes in release 3.6.2 (2020-05-17) [stable]
337 Some tests were fixed.
339 When token aliases contain comment delimiters:
341 %token FOO "/* foo */"
343 bison used to emit "nested" comments, which is invalid C.
346 * Noteworthy changes in release 3.6.1 (2020-05-10) [stable]
350 Restored ANSI-C compliance in yacc.c.
352 GNU readline portability issues.
354 In C++, yy::parser::symbol_name is now a public member, as was intended.
358 In C++, yy::parser::symbol_type now has a public name() member function.
361 * Noteworthy changes in release 3.6 (2020-05-08) [stable]
363 ** Backward incompatible changes
365 TL;DR: replace "#define YYERROR_VERBOSE 1" by "%define parse.error verbose".
367 The YYERROR_VERBOSE macro is no longer supported; the parsers that still
368 depend on it will now produce Yacc-like error messages (just "syntax
369 error"). It was superseded by the "%error-verbose" directive in Bison
370 1.875 (2003-01-01). Bison 2.6 (2012-07-19) clearly announced that support
371 for YYERROR_VERBOSE would be removed. Note that since Bison 3.0
372 (2013-07-25), "%error-verbose" is deprecated in favor of "%define
373 parse.error verbose".
375 ** Deprecated features
377 The YYPRINT macro, which works only with yacc.c and only for tokens, was
378 obsoleted long ago by %printer, introduced in Bison 1.50 (November 2002).
379 It is deprecated and its support will be removed eventually.
383 *** Improved syntax error messages
385 Two new values for the %define parse.error variable offer more control to
386 the user. Available in all the skeletons (C, C++, Java).
388 **** %define parse.error detailed
390 The behavior of "%define parse.error detailed" is closely resembling that
391 of "%define parse.error verbose" with a few exceptions. First, it is safe
392 to use non-ASCII characters in token aliases (with 'verbose', the result
393 depends on the locale with which bison was run). Second, a yysymbol_name
394 function is exposed to the user, instead of the yytnamerr function and the
395 yytname table. Third, token internationalization is supported (see
398 **** %define parse.error custom
400 With this directive, the user forges and emits the syntax error message
401 herself by defining the yyreport_syntax_error function. A new type,
402 yypcontext_t, captures the circumstances of the error, and provides the
403 user with functions to get details, such as yypcontext_expected_tokens to
404 get the list of expected token kinds.
406 A possible implementation of yyreport_syntax_error is:
409 yyreport_syntax_error (const yypcontext_t *ctx)
412 YY_LOCATION_PRINT (stderr, *yypcontext_location (ctx));
413 fprintf (stderr, ": syntax error");
414 // Report the tokens expected at this point.
416 enum { TOKENMAX = 10 };
417 yysymbol_kind_t expected[TOKENMAX];
418 int n = yypcontext_expected_tokens (ctx, expected, TOKENMAX);
420 // Forward errors to yyparse.
423 for (int i = 0; i < n; ++i)
424 fprintf (stderr, "%s %s",
425 i == 0 ? ": expected" : " or", yysymbol_name (expected[i]));
427 // Report the unexpected token.
429 yysymbol_kind_t lookahead = yypcontext_token (ctx);
430 if (lookahead != YYSYMBOL_YYEMPTY)
431 fprintf (stderr, " before %s", yysymbol_name (lookahead));
433 fprintf (stderr, "\n");
437 **** Token aliases internationalization
439 When the %define variable parse.error is set to `custom` or `detailed`,
440 one may specify which token aliases are to be translated using _(). For
452 In that case the user must define _() and N_(), and yysymbol_name returns
453 the translated symbol (i.e., it returns '_("variable")' rather that
454 '"variable"'). In Java, the user must provide an i18n() function.
456 *** List of expected tokens (yacc.c)
458 Push parsers may invoke yypstate_expected_tokens at any point during
459 parsing (including even before submitting the first token) to get the list
460 of possible tokens. This feature can be used to propose autocompletion
461 (see below the "bistromathic" example).
463 It makes little sense to use this feature without enabling LAC (lookahead
466 *** Returning the error token
468 When the scanner returns an invalid token or the undefined token
469 (YYUNDEF), the parser generates an error message and enters error
470 recovery. Because of that error message, most scanners that find lexical
471 errors generate an error message, and then ignore the invalid input
472 without entering the error-recovery.
474 The scanners may now return YYerror, the error token, to enter the
475 error-recovery mode without triggering an additional error message. See
476 the bistromathic for an example.
478 *** Deep overhaul of the symbol and token kinds
480 To avoid the confusion with types in programming languages, we now refer
481 to token and symbol "kinds" instead of token and symbol "types". The
482 documentation and error messages have been revised.
484 All the skeletons have been updated to use dedicated enum types rather
485 than integral types. Special symbols are now regular citizens, instead of
486 being declared in ad hoc ways.
490 The "token kind" is what is returned by the scanner, e.g., PLUS, NUMBER,
491 LPAREN, etc. While backward compatibility is of course ensured, users are
492 nonetheless invited to replace their uses of "enum yytokentype" by
495 This type now also includes tokens that were previously hidden: YYEOF (end
496 of input), YYUNDEF (undefined token), and YYerror (error token). They
497 now have string aliases, internationalized when internationalization is
498 enabled. Therefore, by default, error messages now refer to "end of file"
499 (internationalized) rather than the cryptic "$end", or to "invalid token"
500 rather than "$undefined".
502 Therefore in most cases it is now useless to define the end-of-line token
505 %token T_EOF 0 "end of file"
507 Rather simply use "YYEOF" in your scanner.
511 The "symbol kinds" is what the parser actually uses. (Unless the
512 api.token.raw %define variable is used, the symbol kind of a terminal
513 differs from the corresponding token kind.)
515 They are now exposed as a enum, "yysymbol_kind_t".
517 This allows users to tailor the error messages the way they want, or to
518 process some symbols in a specific way in autocompletion (see the
519 bistromathic example below).
521 *** Modernize display of explanatory statements in diagnostics
523 Since Bison 2.7, output was indented four spaces for explanatory
524 statements. For example:
526 input.y:2.7-13: error: %type redeclaration for exp
527 input.y:1.7-11: previous declaration
529 Since the introduction of caret-diagnostics, it became less clear. This
530 indentation has been removed and submessages are displayed similarly as in
533 input.y:2.7-13: error: %type redeclaration for exp
534 2 | %type <float> exp
536 input.y:1.7-11: note: previous declaration
540 Contributed by Victor Morales Cayuela.
544 The token and symbol kinds are yy::parser::token_kind_type and
545 yy::parser::symbol_kind_type.
547 The symbol_type::kind() member function allows to get the kind of a
548 symbol. This can be used to write unit tests for scanners, e.g.,
550 yy::parser::symbol_type t = make_NUMBER ("123");
551 assert (t.kind () == yy::parser::symbol_kind::S_NUMBER);
552 assert (t.value.as<int> () == 123);
558 In order to avoid ambiguities with "type" as in "typing", we now refer to
559 the "token kind" (e.g., `PLUS`, `NUMBER`, etc.) rather than the "token
560 type". We now also refer to the "symbol type" (e.g., `PLUS`, `expr`,
565 There are now examples/java: a very simple calculator, and a more complete
566 one (push-parser, location tracking, and debug traces).
568 The lexcalc example (a simple example in C based on Flex and Bison) now
569 also demonstrates location tracking.
572 A new C example, bistromathic, is a fully featured interactive calculator
573 using many Bison features: pure interface, push parser, autocompletion
574 based on the current parser state (using yypstate_expected_tokens),
575 location tracking, internationalized custom error messages, lookahead
576 correction, rich debug traces, etc.
578 It shows how to depend on the symbol kinds to tailor autocompletion. For
579 instance it recognizes the symbol kind "VARIABLE" to propose
580 autocompletion on the existing variables, rather than of the word
584 * Noteworthy changes in release 3.5.4 (2020-04-05) [stable]
586 ** WARNING: Future backward-incompatibilities!
588 TL;DR: replace "#define YYERROR_VERBOSE 1" by "%define parse.error verbose".
590 Bison 3.6 will no longer support the YYERROR_VERBOSE macro; the parsers
591 that still depend on it will produce Yacc-like error messages (just
592 "syntax error"). It was superseded by the "%error-verbose" directive in
593 Bison 1.875 (2003-01-01). Bison 2.6 (2012-07-19) clearly announced that
594 support for YYERROR_VERBOSE would be removed. Note that since Bison 3.0
595 (2013-07-25), "%error-verbose" is deprecated in favor of "%define
596 parse.error verbose".
600 Fix portability issues of the package itself on old compilers.
602 Fix api.token.raw support in Java.
605 * Noteworthy changes in release 3.5.3 (2020-03-08) [stable]
609 Error messages could quote lines containing zero-width characters (such as
610 \005) with incorrect styling. Fixes for similar issues with unexpectedly
611 short lines (e.g., the file was changed between parsing and diagnosing).
613 Some unlikely crashes found by fuzzing have been fixed. This is only
614 about bison itself, not the generated parsers.
617 * Noteworthy changes in release 3.5.2 (2020-02-13) [stable]
621 Portability issues and minor cosmetic issues.
623 The lalr1.cc skeleton properly rejects unsupported values for parse.lac
627 * Noteworthy changes in release 3.5.1 (2020-01-19) [stable]
633 Fix compiler warnings.
636 * Noteworthy changes in release 3.5 (2019-12-11) [stable]
638 ** Backward incompatible changes
640 Lone carriage-return characters (aka \r or ^M) in the grammar files are no
641 longer treated as end-of-lines. This changes the diagnostics, and in
642 particular their locations.
644 In C++, line numbers and columns are now represented as 'int' not
645 'unsigned', so that integer overflow on positions is easily checkable via
646 'gcc -fsanitize=undefined' and the like. This affects the API for
647 positions. The default position and location classes now expose
648 'counter_type' (int), used to define line and column numbers.
650 ** Deprecated features
652 The YYPRINT macro, which works only with yacc.c and only for tokens, was
653 obsoleted long ago by %printer, introduced in Bison 1.50 (November 2002).
654 It is deprecated and its support will be removed eventually.
658 *** Lookahead correction in C++
660 Contributed by Adrian Vogelsgesang.
662 The C++ deterministic skeleton (lalr1.cc) now supports LAC, via the
663 %define variable parse.lac.
665 *** Variable api.token.raw: Optimized token numbers (all skeletons)
667 In the generated parsers, tokens have two numbers: the "external" token
668 number as returned by yylex (which starts at 257), and the "internal"
669 symbol number (which starts at 3). Each time yylex is called, a table
670 lookup maps the external token number to the internal symbol number.
672 When the %define variable api.token.raw is set, tokens are assigned their
673 internal number, which saves one table lookup per token, and also saves
674 the generation of the mapping table.
676 The gain is typically moderate, but in extreme cases (very simple user
677 actions), a 10% improvement can be observed.
679 *** Generated parsers use better types for states
681 Stacks now use the best integral type for state numbers, instead of always
682 using 15 bits. As a result "small" parsers now have a smaller memory
683 footprint (they use 8 bits), and there is support for large automata (16
684 bits), and extra large (using int, i.e., typically 31 bits).
686 *** Generated parsers prefer signed integer types
688 Bison skeletons now prefer signed to unsigned integer types when either
689 will do, as the signed types are less error-prone and allow for better
690 checking with 'gcc -fsanitize=undefined'. Also, the types chosen are now
691 portable to unusual machines where char, short and int are all the same
692 width. On non-GNU platforms this may entail including <limits.h> and (if
693 available) <stdint.h> to define integer types and constants.
695 *** A skeleton for the D programming language
697 For the last few releases, Bison has shipped a stealth experimental
698 skeleton: lalr1.d. It was first contributed by Oliver Mangold, based on
699 Paolo Bonzini's lalr1.java, and was cleaned and improved thanks to
702 However, because nobody has committed to improving, testing, and
703 documenting this skeleton, it is not clear that it will be supported in
706 The lalr1.d skeleton *is functional*, and works well, as demonstrated in
707 examples/d/calc.d. Please try it, enjoy it, and... commit to support it.
709 *** Debug traces in Java
711 The Java backend no longer emits code and data for parser tracing if the
712 %define variable parse.trace is not defined.
716 *** New diagnostic: -Wdangling-alias
718 String literals, which allow for better error messages, are (too)
719 liberally accepted by Bison, which might result in silent errors. For
722 %type <exVal> cond "condition"
724 does not define "condition" as a string alias to 'cond' (nonterminal
725 symbols do not have string aliases). It is rather equivalent to
728 %token <exVal> "condition"
730 i.e., it gives the type 'exVal' to the "condition" token, which was
731 clearly not the intention.
733 Also, because string aliases need not be defined, typos such as "baz"
734 instead of "bar" will be not reported.
736 The option -Wdangling-alias catches these situations. On
739 %type <ival> foo "foo"
743 bison -Wdangling-alias reports
745 warning: string literal not attached to a symbol
746 | %type <ival> foo "foo"
748 warning: string literal not attached to a symbol
752 The -Wall option does not (yet?) include -Wdangling-alias.
754 *** Better POSIX Yacc compatibility diagnostics
756 POSIX Yacc restricts %type to nonterminals. This is now diagnosed by
760 %type <ival> TOKEN1 TOKEN2 't'
767 input.y:2.15-20: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
768 2 | %type <ival> TOKEN1 TOKEN2 't'
770 input.y:2.29-31: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
771 2 | %type <ival> TOKEN1 TOKEN2 't'
773 input.y:2.22-27: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
774 2 | %type <ival> TOKEN1 TOKEN2 't'
777 *** Diagnostics with insertion
779 The diagnostics now display the suggestion below the underlined source.
780 Replacement for undeclared symbols are now also suggested.
787 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'?
791 foo.y:2.16: warning: empty rule without %empty [-Wempty-rule]
795 foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
797 *** Diagnostics about long lines
799 Quoted sources may now be truncated to fit the screen. For instance, on a
800 30-column wide terminal:
807 foo.y:1.34-36: warning: symbol FOO redeclared [-Wother]
810 foo.y:1.8-10: previous declaration
813 foo.y:1.62-64: warning: symbol FOO redeclared [-Wother]
816 foo.y:1.8-10: previous declaration
822 *** Debugging glr.c and glr.cc
824 The glr.c skeleton always had asserts to check its own behavior (not the
825 user's). These assertions are now under the control of the parse.assert
826 %define variable (disabled by default).
830 Several new compiler warnings in the generated output have been avoided.
831 Some unused features are no longer emitted. Cleaner generated code in
836 Portability issues in the test suite.
838 In theory, parsers using %nonassoc could crash when reporting verbose
839 error messages. This unlikely bug has been fixed.
841 In Java, %define api.prefix was ignored. It now behaves as expected.
844 * Noteworthy changes in release 3.4.2 (2019-09-12) [stable]
848 In some cases, when warnings are disabled, bison could emit tons of white
849 spaces as diagnostics.
851 When running out of memory, bison could crash (found by fuzzing).
853 When defining twice the EOF token, bison would crash.
855 New warnings from recent compilers have been addressed in the generated
856 parsers (yacc.c, glr.c, glr.cc).
858 When lone carriage-return characters appeared in the input file,
859 diagnostics could hang forever.
862 * Noteworthy changes in release 3.4.1 (2019-05-22) [stable]
869 * Noteworthy changes in release 3.4 (2019-05-19) [stable]
871 ** Deprecated features
873 The %pure-parser directive is deprecated in favor of '%define api.pure'
874 since Bison 2.3b (2008-05-27), but no warning was issued; there is one
875 now. Note that since Bison 2.7 you are strongly encouraged to use
876 '%define api.pure full' instead of '%define api.pure'.
880 *** Colored diagnostics
882 As an experimental feature, diagnostics are now colored, controlled by the
883 new options --color and --style.
885 To use them, install the libtextstyle library before configuring Bison.
888 https://alpha.gnu.org/gnu/gettext/
892 https://alpha.gnu.org/gnu/gettext/libtextstyle-0.8.tar.gz
894 The option --color supports the following arguments:
895 - always, yes: Enable colors.
896 - never, no: Disable colors.
897 - auto, tty (default): Enable colors if the output device is a tty.
899 To customize the styles, create a CSS file similar to
903 .error { font-weight: 800; text-decoration: underline; }
906 then invoke bison with --style=bison-bw.css, or set the BISON_STYLE
907 environment variable to "bison-bw.css".
911 When given -fsyntax-only, the diagnostics are reported, but no output is
914 The name of this option is somewhat misleading as bison does more than
915 just checking the syntax: every stage is run (including checking for
916 conflicts for instance), except the generation of the output files.
918 *** Include the generated header (yacc.c)
920 Before, when --defines is used, bison generated a header, and pasted an
921 exact copy of it into the generated parser implementation file. If the
922 header name is not "y.tab.h", it is now #included instead of being
925 To use an '#include' even if the header name is "y.tab.h" (which is what
926 happens with --yacc, or when using the Autotools' ylwrap), define
927 api.header.include to the exact argument to pass to #include. For
930 %define api.header.include {"parse.h"}
934 %define api.header.include {<parser/parse.h>}
936 *** api.location.type is now supported in C (yacc.c, glr.c)
938 The %define variable api.location.type defines the name of the type to use
939 for locations. When defined, Bison no longer defines YYLTYPE.
941 This can be used in programs with several parsers to factor their
942 definition of locations: let one of them generate them, and the others
949 In conformance with the recommendations of the Graphviz team, if %require
950 "3.4" (or better) is specified, the option --graph generates a *.gv file
951 by default, instead of *.dot.
953 *** Diagnostics overhaul
955 Column numbers were wrong with multibyte characters, which would also
956 result in skewed diagnostics with carets. Beside, because we were
957 indenting the quoted source with a single space, lines with tab characters
958 were incorrectly underlined.
960 To address these issues, and to be clearer, Bison now issues diagnostics
961 as GCC9 does. For instance it used to display (there's a tab before the
964 foo.y:3.37-38: error: $2 of ‘expr’ has no declared type
965 expr: expr '+' "number" { $$ = $1 + $2; }
969 foo.y:3.37-38: error: $2 of ‘expr’ has no declared type
970 3 | expr: expr '+' "number" { $$ = $1 + $2; }
973 Other constructs now also have better locations, resulting in more precise
976 *** Fix-it hints for %empty
978 Running Bison with -Wempty-rules and --update will remove incorrect %empty
979 annotations, and add the missing ones.
981 *** Generated reports
983 The format of the reports (parse.output) was improved for readability.
985 *** Better support for --no-line.
987 When --no-line is used, the generated files are now cleaner: no lines are
988 generated instead of empty lines. Together with using api.header.include,
989 that should help people saving the generated files into version control
990 systems get smaller diffs.
994 A new example in C shows an simple infix calculator with a hand-written
995 scanner (examples/c/calc).
997 A new example in C shows a reentrant parser (capable of recursive calls)
998 built with Flex and Bison (examples/c/reccalc).
1000 There is a new section about the history of Yaccs and Bison.
1004 A few obscure bugs were fixed, including the second oldest (known) bug in
1005 Bison: it was there when Bison was entered in the RCS version control
1006 system, in December 1987. See the NEWS of Bison 3.3 for the previous
1010 * Noteworthy changes in release 3.3.2 (2019-02-03) [stable]
1014 Bison 3.3 failed to generate parsers for grammars with unused nonterminal
1018 * Noteworthy changes in release 3.3.1 (2019-01-27) [stable]
1022 The option -y/--yacc used to imply -Werror=yacc, which turns uses of Bison
1023 extensions into errors. It now makes them simple warnings (-Wyacc).
1026 * Noteworthy changes in release 3.3 (2019-01-26) [stable]
1028 A new mailing list was created, Bison Announce. It is low traffic, and is
1029 only about announcing new releases and important messages (e.g., polls
1030 about major decisions to make).
1032 https://lists.gnu.org/mailman/listinfo/bison-announce
1034 ** Backward incompatible changes
1036 Support for DJGPP, which has been unmaintained and untested for years, is
1039 ** Deprecated features
1041 A new feature, --update (see below) helps adjusting existing grammars to
1044 *** Deprecated directives
1046 The %error-verbose directive is deprecated in favor of '%define
1047 parse.error verbose' since Bison 3.0, but no warning was issued.
1049 The '%name-prefix "xx"' directive is deprecated in favor of '%define
1050 api.prefix {xx}' since Bison 3.0, but no warning was issued. These
1051 directives are slightly different, you might need to adjust your code.
1052 %name-prefix renames only symbols with external linkage, while api.prefix
1053 also renames types and macros, including YYDEBUG, YYTOKENTYPE,
1054 yytokentype, YYSTYPE, YYLTYPE, etc.
1056 Users of Flex that move from '%name-prefix "xx"' to '%define api.prefix
1057 {xx}' will typically have to update YY_DECL from
1059 #define YY_DECL int xxlex (YYSTYPE *yylval, YYLTYPE *yylloc)
1063 #define YY_DECL int xxlex (XXSTYPE *yylval, XXLTYPE *yylloc)
1065 *** Deprecated %define variable names
1067 The following variables, mostly related to parsers in Java, have been
1068 renamed for consistency. Backward compatibility is ensured, but upgrading
1071 abstract -> api.parser.abstract
1072 annotations -> api.parser.annotations
1073 extends -> api.parser.extends
1074 final -> api.parser.final
1075 implements -> api.parser.implements
1076 parser_class_name -> api.parser.class
1077 public -> api.parser.public
1078 strictfp -> api.parser.strictfp
1082 *** Generation of fix-its for IDEs/Editors
1084 When given the new option -ffixit (aka -fdiagnostics-parseable-fixits),
1085 bison now generates machine readable editing instructions to fix some
1086 issues. Currently, this is mostly limited to updating deprecated
1087 directives and removing duplicates. For instance:
1091 %define parser_class_name "Parser"
1092 %define api.parser.class "Parser"
1096 See the "fix-it:" lines below:
1098 $ bison -ffixit foo.y
1099 foo.y:1.1-14: warning: deprecated directive, use '%define parse.error verbose' [-Wdeprecated]
1102 fix-it:"foo.y":{1:1-1:15}:"%define parse.error verbose"
1103 foo.y:2.1-34: warning: deprecated directive, use '%define api.parser.class {Parser}' [-Wdeprecated]
1104 %define parser_class_name "Parser"
1105 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1106 fix-it:"foo.y":{2:1-2:35}:"%define api.parser.class {Parser}"
1107 foo.y:3.1-33: error: %define variable 'api.parser.class' redefined
1108 %define api.parser.class "Parser"
1109 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1110 foo.y:2.1-34: previous definition
1111 %define parser_class_name "Parser"
1112 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1113 fix-it:"foo.y":{3:1-3:34}:""
1114 foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
1116 This uses the same output format as GCC and Clang.
1118 *** Updating grammar files
1120 Fixes can be applied on the fly. The previous example ends with the
1121 suggestion to re-run bison with the option -u/--update, which results in a
1122 cleaner grammar file.
1124 $ bison --update foo.y
1126 bison: file 'foo.y' was updated (backup: 'foo.y~')
1129 %define parse.error verbose
1130 %define api.parser.class {Parser}
1134 *** Bison is now relocatable
1136 If you pass '--enable-relocatable' to 'configure', Bison is relocatable.
1138 A relocatable program can be moved or copied to a different location on
1139 the file system. It can also be used through mount points for network
1140 sharing. It is possible to make symbolic links to the installed and moved
1141 programs, and invoke them through the symbolic link.
1143 *** %expect and %expect-rr modifiers on individual rules
1145 One can now document (and check) which rules participate in shift/reduce
1146 and reduce/reduce conflicts. This is particularly important GLR parsers,
1147 where conflicts are a normal occurrence. For example,
1163 | argument_list ',' expression
1168 Looking at the output from -v, one can see that the shift/reduce conflict
1169 here is due to the fact that the parser does not know whether to reduce
1170 arguments to argument_list until it sees the token _after_ the following
1171 ','. By marking the rule with %expect 1 (because there is a conflict in
1172 one state), we document the source of the 1 overall shift/reduce conflict.
1174 In GLR parsers, we can use %expect-rr in a rule for reduce/reduce
1175 conflicts. In this case, we mark each of the conflicting rules. For
1184 target_list '=' expr ';'
1190 | target ',' target_list
1199 | expr ',' expr_list
1207 In a statement such as
1211 the parser must reduce x to a target or an expr, but does not know which
1212 until it sees the '='. So we notate the two possible reductions to
1213 indicate that each conflicts in one rule.
1215 This feature needs user feedback, and might evolve in the future.
1217 *** C++: Actual token constructors
1219 When variants and token constructors are enabled, in addition to the
1220 type-safe named token constructors (make_ID, make_INT, etc.), we now
1221 generate genuine constructors for symbol_type.
1223 For instance with these declarations
1229 you may use these constructors:
1231 symbol_type (int token, const std::string&);
1232 symbol_type (int token, const int&);
1233 symbol_type (int token);
1235 Correct matching between token types and value types is checked via
1236 'assert'; for instance, 'symbol_type (ID, 42)' would abort. Named
1237 constructors are preferable, as they offer better type safety (for
1238 instance 'make_ID (42)' would not even compile), but symbol_type
1239 constructors may help when token types are discovered at run-time, e.g.,
1242 if (auto i = lookup_keyword (yytext))
1243 return yy::parser::symbol_type (i);
1245 return yy::parser::make_ID (yytext);
1248 *** C++: Variadic emplace
1250 If your application requires C++11 and you don't use symbol constructors,
1251 you may now use a variadic emplace for semantic values:
1253 %define api.value.type variant
1254 %token <std::pair<int, int>> PAIR
1258 int yylex (parser::semantic_type *lvalp)
1260 lvalp->emplace <std::pair<int, int>> (1, 2);
1261 return parser::token::PAIR;
1264 *** C++: Syntax error exceptions in GLR
1266 The glr.cc skeleton now supports syntax_error exceptions thrown from user
1267 actions, or from the scanner.
1269 *** More POSIX Yacc compatibility warnings
1271 More Bison specific directives are now reported with -y or -Wyacc. This
1272 change was ready since the release of Bison 3.0 in September 2015. It was
1273 delayed because Autoconf used to define YACC as `bison -y`, which resulted
1274 in numerous warnings for Bison users that use the GNU Build System.
1276 If you still experience that problem, either redefine YACC as `bison -o
1277 y.tab.c`, or pass -Wno-yacc to Bison.
1279 *** The tables yyrhs and yyphrs are back
1281 Because no Bison skeleton uses them, these tables were removed (no longer
1282 passed to the skeletons, not even computed) in 2008. However, some users
1283 have expressed interest in being able to use them in their own skeletons.
1287 *** Incorrect number of reduce/reduce conflicts
1289 On a grammar such as
1291 exp: "num" | "num" | "num"
1293 bison used to report a single RR conflict, instead of two. This is now
1294 fixed. This was the oldest (known) bug in Bison: it was there when Bison
1295 was entered in the RCS version control system, in December 1987.
1297 Some grammar files might have to adjust their %expect-rr.
1299 *** Parser directives that were not careful enough
1301 Passing invalid arguments to %nterm, for instance character literals, used
1302 to result in unclear error messages.
1306 The examples/ directory (installed in .../share/doc/bison/examples) has
1307 been restructured per language for clarity. The examples come with a
1308 README and a Makefile. Not only can they be used to toy with Bison, they
1309 can also be starting points for your own grammars.
1311 There is now a Java example, and a simple example in C based on Flex and
1312 Bison (examples/c/lexcalc/).
1318 They now use noexcept and constexpr. Please, report missing annotations.
1320 *** Symbol Declarations
1322 The syntax of the variation directives to declare symbols was overhauled
1323 for more consistency, and also better POSIX Yacc compliance (which, for
1324 instance, allows "%type" without actually providing a type). The %nterm
1325 directive, supported by Bison since its inception, is now documented and
1326 officially supported.
1328 The syntax is now as follows:
1330 %token TAG? ( ID NUMBER? STRING? )+ ( TAG ( ID NUMBER? STRING? )+ )*
1331 %left TAG? ( ID NUMBER? )+ ( TAG ( ID NUMBER? )+ )*
1332 %type TAG? ( ID | CHAR | STRING )+ ( TAG ( ID | CHAR | STRING )+ )*
1333 %nterm TAG? ID+ ( TAG ID+ )*
1335 where TAG denotes a type tag such as ‘<ival>’, ID denotes an identifier
1336 such as ‘NUM’, NUMBER a decimal or hexadecimal integer such as ‘300’ or
1337 ‘0x12d’, CHAR a character literal such as ‘'+'’, and STRING a string
1338 literal such as ‘"number"’. The post-fix quantifiers are ‘?’ (zero or
1339 one), ‘*’ (zero or more) and ‘+’ (one or more).
1342 * Noteworthy changes in release 3.2.4 (2018-12-24) [stable]
1346 Fix the move constructor of symbol_type.
1348 Always provide a copy constructor for symbol_type, even in modern C++.
1351 * Noteworthy changes in release 3.2.3 (2018-12-18) [stable]
1355 Properly support token constructors in C++ with types that include commas
1356 (e.g., std::pair<int, int>). A regression introduced in Bison 3.2.
1359 * Noteworthy changes in release 3.2.2 (2018-11-21) [stable]
1363 C++ portability issues.
1366 * Noteworthy changes in release 3.2.1 (2018-11-09) [stable]
1370 Several portability issues have been fixed in the build system, in the
1371 test suite, and in the generated parsers in C++.
1374 * Noteworthy changes in release 3.2 (2018-10-29) [stable]
1376 ** Backward incompatible changes
1378 Support for DJGPP, which has been unmaintained and untested for years, is
1379 obsolete. Unless there is activity to revive it, it will be removed.
1383 %printers should use yyo rather than yyoutput to denote the output stream.
1385 Variant-based symbols in C++ should use emplace() rather than build().
1387 In C++ parsers, parser::operator() is now a synonym for the parser::parse.
1391 A new section, "A Simple C++ Example", is a tutorial for parsers in C++.
1393 A comment in the generated code now emphasizes that users should not
1394 depend upon non-documented implementation details, such as macros starting
1399 *** C++: Support for move semantics (lalr1.cc)
1401 The lalr1.cc skeleton now fully supports C++ move semantics, while
1402 maintaining compatibility with C++98. You may now store move-only types
1403 when using Bison's variants. For instance:
1410 %skeleton "lalr1.cc"
1411 %define api.value.type variant
1415 %token <int> INT "int";
1416 %type <std::unique_ptr<int>> int;
1417 %type <std::vector<std::unique_ptr<int>>> list;
1421 | list int { $$ = std::move($1); $$.emplace_back(std::move($2)); }
1423 int: "int" { $$ = std::make_unique<int>($1); }
1425 *** C++: Implicit move of right-hand side values (lalr1.cc)
1427 In modern C++ (C++11 and later), you should always use 'std::move' with
1428 the values of the right-hand side symbols ($1, $2, etc.), as they will be
1429 popped from the stack anyway. Using 'std::move' is mandatory for
1430 move-only types such as unique_ptr, and it provides a significant speedup
1431 for large types such as std::string, or std::vector, etc.
1433 If '%define api.value.automove' is set, every occurrence '$n' is replaced
1434 by 'std::move ($n)'. The second rule in the previous grammar can be
1437 list: list int { $$ = $1; $$.emplace_back($2); }
1439 With automove enabled, the semantic values are no longer lvalues, so do
1440 not use the swap idiom:
1442 list: list int { std::swap($$, $1); $$.emplace_back($2); }
1444 This idiom is anyway obsolete: it is preferable to move than to swap.
1446 A warning is issued when automove is enabled, and a value is used several
1449 input.yy:16.31-32: warning: multiple occurrences of $2 with api.value.automove enabled [-Wother]
1450 exp: "twice" exp { $$ = $2 + $2; }
1453 Enabling api.value.automove does not require support for modern C++. The
1454 generated code is valid C++98/03, but will use copies instead of moves.
1456 The new examples/c++/variant-11.yy shows these features in action.
1458 *** C++: The implicit default semantic action is always run
1460 When variants are enabled, the default action was not run, so
1468 It now behaves like in all the other cases, as
1470 exp: "number" { $$ = $1; }
1472 possibly using std::move if automove is enabled.
1474 We do not expect backward compatibility issues. However, beware of
1475 forward compatibility issues: if you rely on default actions with
1476 variants, be sure to '%require "3.2"' to avoid older versions of Bison to
1477 generate incorrect parsers.
1479 *** C++: Renaming location.hh
1481 When both %defines and %locations are enabled, Bison generates a
1482 location.hh file. If you don't use locations outside of the parser, you
1483 may avoid its creation with:
1485 %define api.location.file none
1487 However this file is useful if, for instance, your parser builds an AST
1488 decorated with locations: you may use Bison's location independently of
1489 Bison's parser. You can now give it another name, for instance:
1491 %define api.location.file "my-location.hh"
1493 This name can have directory components, and even be absolute. The name
1494 under which the location file is included is controlled by
1495 api.location.include.
1497 This way it is possible to have several parsers share the same location
1500 For instance, in src/foo/parser.hh, generate the include/ast/loc.hh file:
1503 %define api.namespace {foo}
1504 %define api.location.file "include/ast/loc.hh"
1505 %define api.location.include {<ast/loc.hh>}
1507 and use it in src/bar/parser.hh:
1510 %define api.namespace {bar}
1511 %code requires {#include <ast/loc.hh>}
1512 %define api.location.type {bar::location}
1514 Absolute file names are supported, so in your Makefile, passing the flag
1515 -Dapi.location.file='"$(top_srcdir)/include/ast/location.hh"' to bison is
1518 *** C++: stack.hh and position.hh are deprecated
1520 When asked to generate a header file (%defines), the lalr1.cc skeleton
1521 generates a stack.hh file. This file had no interest for users; it is now
1522 made useless: its content is included in the parser definition. It is
1523 still generated for backward compatibility.
1525 When in addition to %defines, location support is requested (%locations),
1526 the file position.hh is also generated. It is now also useless: its
1527 content is now included in location.hh.
1529 These files are no longer generated when your grammar file requires at
1530 least Bison 3.2 (%require "3.2").
1534 Portability issues on MinGW and VS2015.
1536 Portability issues in the test suite.
1538 Portability/warning issues with Flex.
1541 * Noteworthy changes in release 3.1 (2018-08-27) [stable]
1543 ** Backward incompatible changes
1545 Compiling Bison now requires a C99 compiler---as announced during the
1546 release of Bison 3.0, five years ago. Generated parsers do not require a
1549 Support for DJGPP, which has been unmaintained and untested for years, is
1550 obsolete. Unless there is activity to revive it, the next release of Bison
1551 will have it removed.
1555 *** Typed midrule actions
1557 Because their type is unknown to Bison, the values of midrule actions are
1558 not treated like the others: they don't have %printer and %destructor
1559 support. It also prevents C++ (Bison) variants to handle them properly.
1561 Typed midrule actions address these issues. Instead of:
1563 exp: { $<ival>$ = 1; } { $<ival>$ = 2; } { $$ = $<ival>1 + $<ival>2; }
1567 exp: <ival>{ $$ = 1; } <ival>{ $$ = 2; } { $$ = $1 + $2; }
1569 *** Reports include the type of the symbols
1571 The sections about terminal and nonterminal symbols of the '*.output' file
1572 now specify their declared type. For instance, for:
1576 the report now shows '<ival>':
1578 Terminals, with rules where they appear
1582 *** Diagnostics about useless rules
1584 In the following grammar, the 'exp' nonterminal is trivially useless. So,
1585 of course, its rules are useless too.
1589 exp: exp '+' exp | exp '-' exp | '(' exp ')'
1591 Previously all the useless rules were reported, including those whose
1592 left-hand side is the 'exp' nonterminal:
1594 warning: 1 nonterminal useless in grammar [-Wother]
1595 warning: 4 rules useless in grammar [-Wother]
1596 2.14-16: warning: nonterminal useless in grammar: exp [-Wother]
1599 2.14-16: warning: rule useless in grammar [-Wother]
1602 3.6-16: warning: rule useless in grammar [-Wother]
1603 exp: exp '+' exp | exp '-' exp | '(' exp ')'
1605 3.20-30: warning: rule useless in grammar [-Wother]
1606 exp: exp '+' exp | exp '-' exp | '(' exp ')'
1608 3.34-44: warning: rule useless in grammar [-Wother]
1609 exp: exp '+' exp | exp '-' exp | '(' exp ')'
1612 Now, rules whose left-hand side symbol is useless are no longer reported
1613 as useless. The locations of the errors have also been adjusted to point
1614 to the first use of the nonterminal as a left-hand side of a rule:
1616 warning: 1 nonterminal useless in grammar [-Wother]
1617 warning: 4 rules useless in grammar [-Wother]
1618 3.1-3: warning: nonterminal useless in grammar: exp [-Wother]
1619 exp: exp '+' exp | exp '-' exp | '(' exp ')'
1621 2.14-16: warning: rule useless in grammar [-Wother]
1625 *** C++: Generated parsers can be compiled with -fno-exceptions (lalr1.cc)
1627 When compiled with exceptions disabled, the generated parsers no longer
1628 uses try/catch clauses.
1630 Currently only GCC and Clang are supported.
1634 *** A demonstration of variants
1636 A new example was added (installed in .../share/doc/bison/examples),
1637 'variant.yy', which shows how to use (Bison) variants in C++.
1639 The other examples were made nicer to read.
1641 *** Some features are no longer 'experimental'
1643 The following features, mature enough, are no longer flagged as
1644 experimental in the documentation: push parsers, default %printer and
1645 %destructor (typed: <*> and untyped: <>), %define api.value.type union and
1646 variant, Java parsers, XML output, LR family (lr, ielr, lalr), and
1647 semantic predicates (%?).
1651 *** GLR: Predicates support broken by #line directives
1653 Predicates (%?) in GLR such as
1656 %? {new_syntax} 'w' id new_args
1657 | %?{!new_syntax} 'w' id old_args
1659 were issued with #lines in the middle of C code.
1661 *** Printer and destructor with broken #line directives
1663 The #line directives were not properly escaped when emitting the code for
1664 %printer/%destructor, which resulted in compiler errors if there are
1665 backslashes or double-quotes in the grammar file name.
1667 *** Portability on ICC
1669 The Intel compiler claims compatibility with GCC, yet rejects its _Pragma.
1670 Generated parsers now work around this.
1674 There were several small fixes in the test suite and in the build system,
1675 many warnings in bison and in the generated parsers were eliminated. The
1676 documentation also received its share of minor improvements.
1678 Useless code was removed from C++ parsers, and some of the generated
1679 constructors are more 'natural'.
1682 * Noteworthy changes in release 3.0.5 (2018-05-27) [stable]
1686 *** C++: Fix support of 'syntax_error'
1688 One incorrect 'inline' resulted in linking errors about the constructor of
1689 the syntax_error exception.
1691 *** C++: Fix warnings
1693 GCC 7.3 (with -O1 or -O2 but not -O0 or -O3) issued null-dereference
1694 warnings about yyformat being possibly null. It also warned about the
1695 deprecated implicit definition of copy constructors when there's a
1696 user-defined (copy) assignment operator.
1698 *** Location of errors
1700 In C++ parsers, out-of-bounds errors can happen when a rule with an empty
1701 ride-hand side raises a syntax error. The behavior of the default parser
1702 (yacc.c) in such a condition was undefined.
1704 Now all the parsers match the behavior of glr.c: @$ is used as the
1705 location of the error. This handles gracefully rules with and without
1708 *** Portability fixes in the test suite
1710 On some platforms, some Java and/or C++ tests were failing.
1713 * Noteworthy changes in release 3.0.4 (2015-01-23) [stable]
1717 *** C++ with Variants (lalr1.cc)
1719 Fix a compiler warning when no %destructor use $$.
1723 Several portability issues in tests were fixed.
1726 * Noteworthy changes in release 3.0.3 (2015-01-15) [stable]
1730 *** C++ with Variants (lalr1.cc)
1732 Problems with %destructor and '%define parse.assert' have been fixed.
1734 *** Named %union support (yacc.c, glr.c)
1736 Bison 3.0 introduced a regression on named %union such as
1738 %union foo { int ival; };
1740 The possibility to use a name was introduced "for Yacc compatibility".
1741 It is however not required by POSIX Yacc, and its usefulness is not clear.
1743 *** %define api.value.type union with %defines (yacc.c, glr.c)
1745 The C parsers were broken when %defines was used together with "%define
1746 api.value.type union".
1748 *** Redeclarations are reported in proper order
1756 bison used to report:
1758 foo.yy:2.10-11: error: %printer redeclaration for FOO
1761 foo.yy:3.10-11: previous declaration
1765 Now, the "previous" declaration is always the first one.
1770 Bison now installs various files in its docdir (which defaults to
1771 '/usr/local/share/doc/bison'), including the three fully blown examples
1772 extracted from the documentation:
1775 Reverse Polish Calculator, a simple introductory example.
1777 Multi-function Calc, a calculator with memory and functions and located
1780 a calculator in C++ using variant support and token constructors.
1783 * Noteworthy changes in release 3.0.2 (2013-12-05) [stable]
1787 *** Generated source files when errors are reported
1789 When warnings are issued and -Werror is set, bison would still generate
1790 the source files (*.c, *.h...). As a consequence, some runs of "make"
1791 could fail the first time, but not the second (as the files were generated
1794 This is fixed: bison no longer generates this source files, but, of
1795 course, still produces the various reports (*.output, *.xml, etc.).
1797 *** %empty is used in reports
1799 Empty right-hand sides are denoted by '%empty' in all the reports (text,
1800 dot, XML and formats derived from it).
1802 *** YYERROR and variants
1804 When C++ variant support is enabled, an error triggered via YYERROR, but
1805 not caught via error recovery, resulted in a double deletion.
1808 * Noteworthy changes in release 3.0.1 (2013-11-12) [stable]
1812 *** Errors in caret diagnostics
1814 On some platforms, some errors could result in endless diagnostics.
1816 *** Fixes of the -Werror option
1818 Options such as "-Werror -Wno-error=foo" were still turning "foo"
1819 diagnostics into errors instead of warnings. This is fixed.
1821 Actually, for consistency with GCC, "-Wno-error=foo -Werror" now also
1822 leaves "foo" diagnostics as warnings. Similarly, with "-Werror=foo
1823 -Wno-error", "foo" diagnostics are now errors.
1827 As demonstrated in the documentation, one can now leave spaces between
1832 The yacc.1 man page is no longer installed if --disable-yacc was
1835 *** Fixes in the test suite
1837 Bugs and portability issues.
1840 * Noteworthy changes in release 3.0 (2013-07-25) [stable]
1842 ** WARNING: Future backward-incompatibilities!
1844 Like other GNU packages, Bison will start using some of the C99 features
1845 for its own code, especially the definition of variables after statements.
1846 The generated C parsers still aim at C90.
1848 ** Backward incompatible changes
1850 *** Obsolete features
1852 Support for YYFAIL is removed (deprecated in Bison 2.4.2): use YYERROR.
1854 Support for yystype and yyltype is removed (deprecated in Bison 1.875):
1855 use YYSTYPE and YYLTYPE.
1857 Support for YYLEX_PARAM and YYPARSE_PARAM is removed (deprecated in Bison
1858 1.875): use %lex-param, %parse-param, or %param.
1860 Missing semicolons at the end of actions are no longer added (as announced
1861 in the release 2.5).
1863 *** Use of YACC='bison -y'
1865 TL;DR: With Autoconf <= 2.69, pass -Wno-yacc to (AM_)YFLAGS if you use
1868 Traditional Yacc generates 'y.tab.c' whatever the name of the input file.
1869 Therefore Makefiles written for Yacc expect 'y.tab.c' (and possibly
1870 'y.tab.h' and 'y.output') to be generated from 'foo.y'.
1872 To this end, for ages, AC_PROG_YACC, Autoconf's macro to look for an
1873 implementation of Yacc, was using Bison as 'bison -y'. While it does
1874 ensure compatible output file names, it also enables warnings for
1875 incompatibilities with POSIX Yacc. In other words, 'bison -y' triggers
1876 warnings for Bison extensions.
1878 Autoconf 2.70+ fixes this incompatibility by using YACC='bison -o y.tab.c'
1879 (which also generates 'y.tab.h' and 'y.output' when needed).
1880 Alternatively, disable Yacc warnings by passing '-Wno-yacc' to your Yacc
1881 flags (YFLAGS, or AM_YFLAGS with Automake).
1885 *** The epilogue is no longer affected by internal #defines (glr.c)
1887 The glr.c skeleton uses defines such as #define yylval (yystackp->yyval) in
1888 generated code. These weren't properly undefined before the inclusion of
1889 the user epilogue, so functions such as the following were butchered by the
1890 preprocessor expansion:
1892 int yylex (YYSTYPE *yylval);
1894 This is fixed: yylval, yynerrs, yychar, and yylloc are now valid
1895 identifiers for user-provided variables.
1897 *** stdio.h is no longer needed when locations are enabled (yacc.c)
1899 Changes in Bison 2.7 introduced a dependency on FILE and fprintf when
1900 locations are enabled. This is fixed.
1902 *** Warnings about useless %pure-parser/%define api.pure are restored
1904 ** Diagnostics reported by Bison
1906 Most of these features were contributed by Théophile Ranquet and Victor
1911 Version 2.7 introduced caret errors, for a prettier output. These are now
1912 activated by default. The old format can still be used by invoking Bison
1913 with -fno-caret (or -fnone).
1915 Some error messages that reproduced excerpts of the grammar are now using
1916 the caret information only. For instance on:
1923 in.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
1924 in.y:2.12-14: warning: rule useless in parser due to conflicts: exp: 'a' [-Wother]
1928 in.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
1929 in.y:2.12-14: warning: rule useless in parser due to conflicts [-Wother]
1933 and "bison -fno-caret" reports:
1935 in.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
1936 in.y:2.12-14: warning: rule useless in parser due to conflicts [-Wother]
1938 *** Enhancements of the -Werror option
1940 The -Werror=CATEGORY option is now recognized, and will treat specified
1941 warnings as errors. The warnings need not have been explicitly activated
1942 using the -W option, this is similar to what GCC 4.7 does.
1944 For example, given the following command line, Bison will treat both
1945 warnings related to POSIX Yacc incompatibilities and S/R conflicts as
1946 errors (and only those):
1948 $ bison -Werror=yacc,error=conflicts-sr input.y
1950 If no categories are specified, -Werror will make all active warnings into
1951 errors. For example, the following line does the same the previous example:
1953 $ bison -Werror -Wnone -Wyacc -Wconflicts-sr input.y
1955 (By default -Wconflicts-sr,conflicts-rr,deprecated,other is enabled.)
1957 Note that the categories in this -Werror option may not be prefixed with
1958 "no-". However, -Wno-error[=CATEGORY] is valid.
1960 Note that -y enables -Werror=yacc. Therefore it is now possible to require
1961 Yacc-like behavior (e.g., always generate y.tab.c), but to report
1962 incompatibilities as warnings: "-y -Wno-error=yacc".
1964 *** The display of warnings is now richer
1966 The option that controls a given warning is now displayed:
1968 foo.y:4.6: warning: type clash on default action: <foo> != <bar> [-Wother]
1970 In the case of warnings treated as errors, the prefix is changed from
1971 "warning: " to "error: ", and the suffix is displayed, in a manner similar
1972 to GCC, as [-Werror=CATEGORY].
1974 For instance, where the previous version of Bison would report (and exit
1977 bison: warnings being treated as errors
1978 input.y:1.1: warning: stray ',' treated as white space
1982 input.y:1.1: error: stray ',' treated as white space [-Werror=other]
1984 *** Deprecated constructs
1986 The new 'deprecated' warning category flags obsolete constructs whose
1987 support will be discontinued. It is enabled by default. These warnings
1988 used to be reported as 'other' warnings.
1990 *** Useless semantic types
1992 Bison now warns about useless (uninhabited) semantic types. Since
1993 semantic types are not declared to Bison (they are defined in the opaque
1994 %union structure), it is %printer/%destructor directives about useless
1995 types that trigger the warning:
1999 %printer {} <type1> <type3>
2000 %destructor {} <type2> <type4>
2002 nterm: term { $$ = $1; };
2004 3.28-34: warning: type <type3> is used, but is not associated to any symbol
2005 4.28-34: warning: type <type4> is used, but is not associated to any symbol
2007 *** Undefined but unused symbols
2009 Bison used to raise an error for undefined symbols that are not used in
2010 the grammar. This is now only a warning.
2013 %destructor {} symbol2
2014 %type <type> symbol3
2018 *** Useless destructors or printers
2020 Bison now warns about useless destructors or printers. In the following
2021 example, the printer for <type1>, and the destructor for <type2> are
2022 useless: all symbols of <type1> (token1) already have a printer, and all
2023 symbols of type <type2> (token2) already have a destructor.
2025 %token <type1> token1
2029 %printer {} token1 <type1> <type3>
2030 %destructor {} token2 <type2> <type4>
2034 The warnings and error messages about shift/reduce and reduce/reduce
2035 conflicts have been normalized. For instance on the following foo.y file:
2039 exp: exp '+' exp | '0' | '0';
2041 compare the previous version of bison:
2044 foo.y: conflicts: 1 shift/reduce, 2 reduce/reduce
2045 $ bison -Werror foo.y
2046 bison: warnings being treated as errors
2047 foo.y: conflicts: 1 shift/reduce, 2 reduce/reduce
2049 with the new behavior:
2052 foo.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
2053 foo.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
2054 $ bison -Werror foo.y
2055 foo.y: error: 1 shift/reduce conflict [-Werror=conflicts-sr]
2056 foo.y: error: 2 reduce/reduce conflicts [-Werror=conflicts-rr]
2058 When %expect or %expect-rr is used, such as with bar.y:
2063 exp: exp '+' exp | '0' | '0';
2068 bar.y: conflicts: 1 shift/reduce, 2 reduce/reduce
2069 bar.y: expected 0 shift/reduce conflicts
2070 bar.y: expected 0 reduce/reduce conflicts
2075 bar.y: error: shift/reduce conflicts: 1 found, 0 expected
2076 bar.y: error: reduce/reduce conflicts: 2 found, 0 expected
2078 ** Incompatibilities with POSIX Yacc
2080 The 'yacc' category is no longer part of '-Wall', enable it explicitly
2083 ** Additional yylex/yyparse arguments
2085 The new directive %param declares additional arguments to both yylex and
2086 yyparse. The %lex-param, %parse-param, and %param directives support one
2087 or more arguments. Instead of
2089 %lex-param {arg1_type *arg1}
2090 %lex-param {arg2_type *arg2}
2091 %parse-param {arg1_type *arg1}
2092 %parse-param {arg2_type *arg2}
2096 %param {arg1_type *arg1} {arg2_type *arg2}
2098 ** Types of values for %define variables
2100 Bison used to make no difference between '%define foo bar' and '%define
2101 foo "bar"'. The former is now called a 'keyword value', and the latter a
2102 'string value'. A third kind was added: 'code values', such as '%define
2105 Keyword variables are used for fixed value sets, e.g.,
2107 %define lr.type lalr
2109 Code variables are used for value in the target language, e.g.,
2111 %define api.value.type {struct semantic_type}
2113 String variables are used remaining cases, e.g. file names.
2115 ** Variable api.token.prefix
2117 The variable api.token.prefix changes the way tokens are identified in
2118 the generated files. This is especially useful to avoid collisions
2119 with identifiers in the target language. For instance
2121 %token FILE for ERROR
2122 %define api.token.prefix {TOK_}
2124 start: FILE for ERROR;
2126 will generate the definition of the symbols TOK_FILE, TOK_for, and
2127 TOK_ERROR in the generated sources. In particular, the scanner must
2128 use these prefixed token names, although the grammar itself still
2129 uses the short names (as in the sample rule given above).
2131 ** Variable api.value.type
2133 This new %define variable supersedes the #define macro YYSTYPE. The use
2134 of YYSTYPE is discouraged. In particular, #defining YYSTYPE *and* either
2135 using %union or %defining api.value.type results in undefined behavior.
2137 Either define api.value.type, or use "%union":
2144 %token <ival> INT "integer"
2145 %token <sval> STRING "string"
2146 %printer { fprintf (yyo, "%d", $$); } <ival>
2147 %destructor { free ($$); } <sval>
2150 yylval.ival = 42; return INT;
2151 yylval.sval = "42"; return STRING;
2153 The %define variable api.value.type supports both keyword and code values.
2155 The keyword value 'union' means that the user provides genuine types, not
2156 union member names such as "ival" and "sval" above (WARNING: will fail if
2157 -y/--yacc/%yacc is enabled).
2159 %define api.value.type union
2160 %token <int> INT "integer"
2161 %token <char *> STRING "string"
2162 %printer { fprintf (yyo, "%d", $$); } <int>
2163 %destructor { free ($$); } <char *>
2166 yylval.INT = 42; return INT;
2167 yylval.STRING = "42"; return STRING;
2169 The keyword value variant is somewhat equivalent, but for C++ special
2170 provision is made to allow classes to be used (more about this below).
2172 %define api.value.type variant
2173 %token <int> INT "integer"
2174 %token <std::string> STRING "string"
2176 Code values (in braces) denote user defined types. This is where YYSTYPE
2194 %define api.value.type {struct my_value}
2195 %token <u.ival> INT "integer"
2196 %token <u.sval> STRING "string"
2197 %printer { fprintf (yyo, "%d", $$); } <u.ival>
2198 %destructor { free ($$); } <u.sval>
2201 yylval.u.ival = 42; return INT;
2202 yylval.u.sval = "42"; return STRING;
2204 ** Variable parse.error
2206 This variable controls the verbosity of error messages. The use of the
2207 %error-verbose directive is deprecated in favor of "%define parse.error
2210 ** Deprecated %define variable names
2212 The following variables have been renamed for consistency. Backward
2213 compatibility is ensured, but upgrading is recommended.
2215 lr.default-reductions -> lr.default-reduction
2216 lr.keep-unreachable-states -> lr.keep-unreachable-state
2217 namespace -> api.namespace
2218 stype -> api.value.type
2220 ** Semantic predicates
2222 Contributed by Paul Hilfinger.
2224 The new, experimental, semantic-predicate feature allows actions of the
2225 form "%?{ BOOLEAN-EXPRESSION }", which cause syntax errors (as for
2226 YYERROR) if the expression evaluates to 0, and are evaluated immediately
2227 in GLR parsers, rather than being deferred. The result is that they allow
2228 the programmer to prune possible parses based on the values of run-time
2231 ** The directive %expect-rr is now an error in non GLR mode
2233 It used to be an error only if used in non GLR mode, _and_ if there are
2234 reduce/reduce conflicts.
2236 ** Tokens are numbered in their order of appearance
2238 Contributed by Valentin Tolmer.
2240 With '%token A B', A had a number less than the one of B. However,
2241 precedence declarations used to generate a reversed order. This is now
2242 fixed, and introducing tokens with any of %token, %left, %right,
2243 %precedence, or %nonassoc yields the same result.
2245 When mixing declarations of tokens with a literal character (e.g., 'a') or
2246 with an identifier (e.g., B) in a precedence declaration, Bison numbered
2247 the literal characters first. For example
2251 would lead to the tokens declared in this order: 'c' 'd' A B. Again, the
2252 input order is now preserved.
2254 These changes were made so that one can remove useless precedence and
2255 associativity declarations (i.e., map %nonassoc, %left or %right to
2256 %precedence, or to %token) and get exactly the same output.
2258 ** Useless precedence and associativity
2260 Contributed by Valentin Tolmer.
2262 When developing and maintaining a grammar, useless associativity and
2263 precedence directives are common. They can be a nuisance: new ambiguities
2264 arising are sometimes masked because their conflicts are resolved due to
2265 the extra precedence or associativity information. Furthermore, it can
2266 hinder the comprehension of a new grammar: one will wonder about the role
2267 of a precedence, where in fact it is useless. The following changes aim
2268 at detecting and reporting these extra directives.
2270 *** Precedence warning category
2272 A new category of warning, -Wprecedence, was introduced. It flags the
2273 useless precedence and associativity directives.
2275 *** Useless associativity
2277 Bison now warns about symbols with a declared associativity that is never
2278 used to resolve conflicts. In that case, using %precedence is sufficient;
2279 the parsing tables will remain unchanged. Solving these warnings may raise
2280 useless precedence warnings, as the symbols no longer have associativity.
2294 warning: useless associativity for '+', use %precedence [-Wprecedence]
2298 *** Useless precedence
2300 Bison now warns about symbols with a declared precedence and no declared
2301 associativity (i.e., declared with %precedence), and whose precedence is
2302 never used. In that case, the symbol can be safely declared with %token
2303 instead, without modifying the parsing tables. For example:
2307 exp: "var" '=' "number";
2311 warning: useless precedence for '=' [-Wprecedence]
2315 *** Useless precedence and associativity
2317 In case of both useless precedence and associativity, the issue is flagged
2322 exp: "var" '=' "number";
2326 warning: useless precedence and associativity for '=' [-Wprecedence]
2332 With help from Joel E. Denny and Gabriel Rassoul.
2334 Empty rules (i.e., with an empty right-hand side) can now be explicitly
2335 marked by the new %empty directive. Using %empty on a non-empty rule is
2336 an error. The new -Wempty-rule warning reports empty rules without
2337 %empty. On the following grammar:
2347 3.4-5: warning: empty rule without %empty [-Wempty-rule]
2350 5.8-13: error: %empty on non-empty rule
2354 ** Java skeleton improvements
2356 The constants for token names were moved to the Lexer interface. Also, it
2357 is possible to add code to the parser's constructors using "%code init"
2358 and "%define init_throws".
2359 Contributed by Paolo Bonzini.
2361 The Java skeleton now supports push parsing.
2362 Contributed by Dennis Heimbigner.
2364 ** C++ skeletons improvements
2366 *** The parser header is no longer mandatory (lalr1.cc, glr.cc)
2368 Using %defines is now optional. Without it, the needed support classes
2369 are defined in the generated parser, instead of additional files (such as
2370 location.hh, position.hh and stack.hh).
2372 *** Locations are no longer mandatory (lalr1.cc, glr.cc)
2374 Both lalr1.cc and glr.cc no longer require %location.
2376 *** syntax_error exception (lalr1.cc)
2378 The C++ parser features a syntax_error exception, which can be
2379 thrown from the scanner or from user rules to raise syntax errors.
2380 This facilitates reporting errors caught in sub-functions (e.g.,
2381 rejecting too large integral literals from a conversion function
2382 used by the scanner, or rejecting invalid combinations from a
2383 factory invoked by the user actions).
2385 *** %define api.value.type variant
2387 This is based on a submission from Michiel De Wilde. With help
2388 from Théophile Ranquet.
2390 In this mode, complex C++ objects can be used as semantic values. For
2393 %token <::std::string> TEXT;
2394 %token <int> NUMBER;
2395 %token SEMICOLON ";"
2396 %type <::std::string> item;
2397 %type <::std::list<std::string>> list;
2400 list { std::cout << $1 << std::endl; }
2404 %empty { /* Generates an empty string list. */ }
2405 | list item ";" { std::swap ($$, $1); $$.push_back ($2); }
2409 TEXT { std::swap ($$, $1); }
2410 | NUMBER { $$ = string_cast ($1); }
2413 *** %define api.token.constructor
2415 When variants are enabled, Bison can generate functions to build the
2416 tokens. This guarantees that the token type (e.g., NUMBER) is consistent
2417 with the semantic value (e.g., int):
2419 parser::symbol_type yylex ()
2421 parser::location_type loc = ...;
2423 return parser::make_TEXT ("Hello, world!", loc);
2425 return parser::make_NUMBER (42, loc);
2427 return parser::make_SEMICOLON (loc);
2433 There are operator- and operator-= for 'location'. Negative line/column
2434 increments can no longer underflow the resulting value.
2437 * Noteworthy changes in release 2.7.1 (2013-04-15) [stable]
2441 *** Fix compiler attribute portability (yacc.c)
2443 With locations enabled, __attribute__ was used unprotected.
2445 *** Fix some compiler warnings (lalr1.cc)
2448 * Noteworthy changes in release 2.7 (2012-12-12) [stable]
2452 Warnings about uninitialized yylloc in yyparse have been fixed.
2454 Restored C90 compliance (yet no report was ever made).
2456 ** Diagnostics are improved
2458 Contributed by Théophile Ranquet.
2460 *** Changes in the format of error messages
2462 This used to be the format of many error reports:
2464 input.y:2.7-12: %type redeclaration for exp
2465 input.y:1.7-12: previous declaration
2469 input.y:2.7-12: error: %type redeclaration for exp
2470 input.y:1.7-12: previous declaration
2472 *** New format for error reports: carets
2474 Caret errors have been added to Bison:
2476 input.y:2.7-12: error: %type redeclaration for exp
2479 input.y:1.7-12: previous declaration
2485 input.y:3.20-23: error: ambiguous reference: '$exp'
2486 exp: exp '+' exp { $exp = $1 + $3; };
2488 input.y:3.1-3: refers to: $exp at $$
2489 exp: exp '+' exp { $exp = $1 + $3; };
2491 input.y:3.6-8: refers to: $exp at $1
2492 exp: exp '+' exp { $exp = $1 + $3; };
2494 input.y:3.14-16: refers to: $exp at $3
2495 exp: exp '+' exp { $exp = $1 + $3; };
2498 The default behavior for now is still not to display these unless
2499 explicitly asked with -fcaret (or -fall). However, in a later release, it
2500 will be made the default behavior (but may still be deactivated with
2503 ** New value for %define variable: api.pure full
2505 The %define variable api.pure requests a pure (reentrant) parser. However,
2506 for historical reasons, using it in a location-tracking Yacc parser
2507 resulted in a yyerror function that did not take a location as a
2508 parameter. With this new value, the user may request a better pure parser,
2509 where yyerror does take a location as a parameter (in location-tracking
2512 The use of "%define api.pure true" is deprecated in favor of this new
2513 "%define api.pure full".
2515 ** New %define variable: api.location.type (glr.cc, lalr1.cc, lalr1.java)
2517 The %define variable api.location.type defines the name of the type to use
2518 for locations. When defined, Bison no longer generates the position.hh
2519 and location.hh files, nor does the parser will include them: the user is
2520 then responsible to define her type.
2522 This can be used in programs with several parsers to factor their location
2523 and position files: let one of them generate them, and the others just use
2526 This feature was actually introduced, but not documented, in Bison 2.5,
2527 under the name "location_type" (which is maintained for backward
2530 For consistency, lalr1.java's %define variables location_type and
2531 position_type are deprecated in favor of api.location.type and
2534 ** Exception safety (lalr1.cc)
2536 The parse function now catches exceptions, uses the %destructors to
2537 release memory (the lookahead symbol and the symbols pushed on the stack)
2538 before re-throwing the exception.
2540 This feature is somewhat experimental. User feedback would be
2543 ** Graph improvements in DOT and XSLT
2545 Contributed by Théophile Ranquet.
2547 The graphical presentation of the states is more readable: their shape is
2548 now rectangular, the state number is clearly displayed, and the items are
2549 numbered and left-justified.
2551 The reductions are now explicitly represented as transitions to other
2552 diamond shaped nodes.
2554 These changes are present in both --graph output and xml2dot.xsl XSLT
2555 processing, with minor (documented) differences.
2557 ** %language is no longer an experimental feature.
2559 The introduction of this feature, in 2.4, was four years ago. The
2560 --language option and the %language directive are no longer experimental.
2564 The sections about shift/reduce and reduce/reduce conflicts resolution
2565 have been fixed and extended.
2567 Although introduced more than four years ago, XML and Graphviz reports
2568 were not properly documented.
2570 The translation of midrule actions is now described.
2573 * Noteworthy changes in release 2.6.5 (2012-11-07) [stable]
2575 We consider compiler warnings about Bison generated parsers to be bugs.
2576 Rather than working around them in your own project, please consider
2577 reporting them to us.
2581 Warnings about uninitialized yylval and/or yylloc for push parsers with a
2582 pure interface have been fixed for GCC 4.0 up to 4.8, and Clang 2.9 to
2585 Other issues in the test suite have been addressed.
2587 Null characters are correctly displayed in error messages.
2589 When possible, yylloc is correctly initialized before calling yylex. It
2590 is no longer necessary to initialize it in the %initial-action.
2593 * Noteworthy changes in release 2.6.4 (2012-10-23) [stable]
2595 Bison 2.6.3's --version was incorrect. This release fixes this issue.
2598 * Noteworthy changes in release 2.6.3 (2012-10-22) [stable]
2602 Bugs and portability issues in the test suite have been fixed.
2604 Some errors in translations have been addressed, and --help now directs
2605 users to the appropriate place to report them.
2607 Stray Info files shipped by accident are removed.
2609 Incorrect definitions of YY_, issued by yacc.c when no parser header is
2610 generated, are removed.
2612 All the generated headers are self-contained.
2614 ** Header guards (yacc.c, glr.c, glr.cc)
2616 In order to avoid collisions, the header guards are now
2617 YY_<PREFIX>_<FILE>_INCLUDED, instead of merely <PREFIX>_<FILE>.
2618 For instance the header generated from
2620 %define api.prefix "calc"
2621 %defines "lib/parse.h"
2623 will use YY_CALC_LIB_PARSE_H_INCLUDED as guard.
2625 ** Fix compiler warnings in the generated parser (yacc.c, glr.c)
2627 The compilation of pure parsers (%define api.pure) can trigger GCC
2630 input.c: In function 'yyparse':
2631 input.c:1503:12: warning: 'yylval' may be used uninitialized in this
2632 function [-Wmaybe-uninitialized]
2636 This is now fixed; pragmas to avoid these warnings are no longer needed.
2638 Warnings from clang ("equality comparison with extraneous parentheses" and
2639 "function declared 'noreturn' should not return") have also been
2643 * Noteworthy changes in release 2.6.2 (2012-08-03) [stable]
2647 Buffer overruns, complaints from Flex, and portability issues in the test
2648 suite have been fixed.
2650 ** Spaces in %lex- and %parse-param (lalr1.cc, glr.cc)
2652 Trailing end-of-lines in %parse-param or %lex-param would result in
2653 invalid C++. This is fixed.
2655 ** Spurious spaces and end-of-lines
2657 The generated files no longer end (nor start) with empty lines.
2660 * Noteworthy changes in release 2.6.1 (2012-07-30) [stable]
2662 Bison no longer executes user-specified M4 code when processing a grammar.
2666 In addition to the removal of the features announced in Bison 2.6, the
2667 next major release will remove the "Temporary hack for adding a semicolon
2668 to the user action", as announced in the release 2.5. Instead of:
2670 exp: exp "+" exp { $$ = $1 + $3 };
2674 exp: exp "+" exp { $$ = $1 + $3; };
2678 *** Type names are now properly escaped.
2680 *** glr.cc: set_debug_level and debug_level work as expected.
2682 *** Stray @ or $ in actions
2684 While Bison used to warn about stray $ or @ in action rules, it did not
2685 for other actions such as printers, destructors, or initial actions. It
2688 ** Type names in actions
2690 For consistency with rule actions, it is now possible to qualify $$ by a
2691 type-name in destructors, printers, and initial actions. For instance:
2693 %printer { fprintf (yyo, "(%d, %f)", $<ival>$, $<fval>$); } <*> <>;
2695 will display two values for each typed and untyped symbol (provided
2696 that YYSTYPE has both "ival" and "fval" fields).
2699 * Noteworthy changes in release 2.6 (2012-07-19) [stable]
2703 The next major release of Bison will drop support for the following
2704 deprecated features. Please report disagreements to bug-bison@gnu.org.
2708 Support for generating parsers in K&R C will be removed. Parsers
2709 generated for C support ISO C90, and are tested with ISO C99 and ISO C11
2712 *** Features deprecated since Bison 1.875
2714 The definitions of yystype and yyltype will be removed; use YYSTYPE and
2717 YYPARSE_PARAM and YYLEX_PARAM, deprecated in favor of %parse-param and
2718 %lex-param, will no longer be supported.
2720 Support for the preprocessor symbol YYERROR_VERBOSE will be removed, use
2723 *** The generated header will be included (yacc.c)
2725 Instead of duplicating the content of the generated header (definition of
2726 YYSTYPE, yyparse declaration etc.), the generated parser will include it,
2727 as is already the case for GLR or C++ parsers. This change is deferred
2728 because existing versions of ylwrap (e.g., Automake 1.12.1) do not support
2731 ** Generated Parser Headers
2733 *** Guards (yacc.c, glr.c, glr.cc)
2735 The generated headers are now guarded, as is already the case for C++
2736 parsers (lalr1.cc). For instance, with --defines=foo.h:
2741 #endif /* !YY_FOO_H */
2743 *** New declarations (yacc.c, glr.c)
2745 The generated header now declares yydebug and yyparse. Both honor
2746 --name-prefix=bar_, and yield
2748 int bar_parse (void);
2752 #define yyparse bar_parse
2755 in order to facilitate the inclusion of several parser headers inside a
2756 single compilation unit.
2758 *** Exported symbols in C++
2760 The symbols YYTOKEN_TABLE and YYERROR_VERBOSE, which were defined in the
2761 header, are removed, as they prevent the possibility of including several
2762 generated headers from a single compilation unit.
2766 For the same reasons, the undocumented and unused macro YYLSP_NEEDED is no
2769 ** New %define variable: api.prefix
2771 Now that the generated headers are more complete and properly protected
2772 against multiple inclusions, constant names, such as YYSTYPE are a
2773 problem. While yyparse and others are properly renamed by %name-prefix,
2774 YYSTYPE, YYDEBUG and others have never been affected by it. Because it
2775 would introduce backward compatibility issues in projects not expecting
2776 YYSTYPE to be renamed, instead of changing the behavior of %name-prefix,
2777 it is deprecated in favor of a new %define variable: api.prefix.
2779 The following examples compares both:
2781 %name-prefix "bar_" | %define api.prefix "bar_"
2782 %token <ival> FOO %token <ival> FOO
2783 %union { int ival; } %union { int ival; }
2789 #ifndef BAR_FOO_H #ifndef BAR_FOO_H
2790 # define BAR_FOO_H # define BAR_FOO_H
2792 /* Enabling traces. */ /* Enabling traces. */
2793 # ifndef YYDEBUG | # ifndef BAR_DEBUG
2794 > # if defined YYDEBUG
2796 > # define BAR_DEBUG 1
2798 > # define BAR_DEBUG 0
2801 # define YYDEBUG 0 | # define BAR_DEBUG 0
2805 # if YYDEBUG | # if BAR_DEBUG
2806 extern int bar_debug; extern int bar_debug;
2809 /* Tokens. */ /* Tokens. */
2810 # ifndef YYTOKENTYPE | # ifndef BAR_TOKENTYPE
2811 # define YYTOKENTYPE | # define BAR_TOKENTYPE
2812 enum yytokentype { | enum bar_tokentype {
2817 #if ! defined YYSTYPE \ | #if ! defined BAR_STYPE \
2818 && ! defined YYSTYPE_IS_DECLARED | && ! defined BAR_STYPE_IS_DECLARED
2819 typedef union YYSTYPE | typedef union BAR_STYPE
2822 } YYSTYPE; | } BAR_STYPE;
2823 # define YYSTYPE_IS_DECLARED 1 | # define BAR_STYPE_IS_DECLARED 1
2826 extern YYSTYPE bar_lval; | extern BAR_STYPE bar_lval;
2828 int bar_parse (void); int bar_parse (void);
2830 #endif /* !BAR_FOO_H */ #endif /* !BAR_FOO_H */
2833 * Noteworthy changes in release 2.5.1 (2012-06-05) [stable]
2837 The next major release will drop support for generating parsers in K&R C.
2839 ** yacc.c: YYBACKUP works as expected.
2841 ** glr.c improvements:
2843 *** Location support is eliminated when not requested:
2845 GLR parsers used to include location-related code even when locations were
2846 not requested, and therefore not even usable.
2848 *** __attribute__ is preserved:
2850 __attribute__ is no longer disabled when __STRICT_ANSI__ is defined (i.e.,
2851 when -std is passed to GCC).
2853 ** lalr1.java: several fixes:
2855 The Java parser no longer throws ArrayIndexOutOfBoundsException if the
2856 first token leads to a syntax error. Some minor clean ups.
2860 *** C++11 compatibility:
2862 C and C++ parsers use "nullptr" instead of "0" when __cplusplus is 201103L
2867 The header files such as "parser.hh", "location.hh", etc. used a constant
2868 name for preprocessor guards, for instance:
2870 #ifndef BISON_LOCATION_HH
2871 # define BISON_LOCATION_HH
2873 #endif // !BISON_LOCATION_HH
2875 The inclusion guard is now computed from "PREFIX/FILE-NAME", where lower
2876 case characters are converted to upper case, and series of
2877 non-alphanumerical characters are converted to an underscore.
2879 With "bison -o lang++/parser.cc", "location.hh" would now include:
2881 #ifndef YY_LANG_LOCATION_HH
2882 # define YY_LANG_LOCATION_HH
2884 #endif // !YY_LANG_LOCATION_HH
2888 The position and location constructors (and their initialize methods)
2889 accept new arguments for line and column. Several issues in the
2890 documentation were fixed.
2892 ** liby is no longer asking for "rpl_fprintf" on some platforms.
2894 ** Changes in the manual:
2896 *** %printer is documented
2898 The "%printer" directive, supported since at least Bison 1.50, is finally
2899 documented. The "mfcalc" example is extended to demonstrate it.
2901 For consistency with the C skeletons, the C++ parsers now also support
2902 "yyoutput" (as an alias to "debug_stream ()").
2904 *** Several improvements have been made:
2906 The layout for grammar excerpts was changed to a more compact scheme.
2907 Named references are motivated. The description of the automaton
2908 description file (*.output) is updated to the current format. Incorrect
2909 index entries were fixed. Some other errors were fixed.
2913 *** Conflicting prototypes with recent/modified Flex.
2915 Fixed build problems with the current, unreleased, version of Flex, and
2916 some modified versions of 2.5.35, which have modified function prototypes.
2918 *** Warnings during the build procedure have been eliminated.
2920 *** Several portability problems in the test suite have been fixed:
2922 This includes warnings with some compilers, unexpected behavior of tools
2923 such as diff, warning messages from the test suite itself, etc.
2925 *** The install-pdf target works properly:
2927 Running "make install-pdf" (or -dvi, -html, -info, and -ps) no longer
2928 halts in the middle of its course.
2931 * Noteworthy changes in release 2.5 (2011-05-14)
2933 ** Grammar symbol names can now contain non-initial dashes:
2935 Consistently with directives (such as %error-verbose) and with
2936 %define variables (e.g. push-pull), grammar symbol names may contain
2937 dashes in any position except the beginning. This is a GNU
2938 extension over POSIX Yacc. Thus, use of this extension is reported
2939 by -Wyacc and rejected in Yacc mode (--yacc).
2941 ** Named references:
2943 Historically, Yacc and Bison have supported positional references
2944 ($n, $$) to allow access to symbol values from inside of semantic
2947 Starting from this version, Bison can also accept named references.
2948 When no ambiguity is possible, original symbol names may be used
2949 as named references:
2951 if_stmt : "if" cond_expr "then" then_stmt ';'
2952 { $if_stmt = mk_if_stmt($cond_expr, $then_stmt); }
2954 In the more common case, explicit names may be declared:
2956 stmt[res] : "if" expr[cond] "then" stmt[then] "else" stmt[else] ';'
2957 { $res = mk_if_stmt($cond, $then, $else); }
2959 Location information is also accessible using @name syntax. When
2960 accessing symbol names containing dots or dashes, explicit bracketing
2961 ($[sym.1]) must be used.
2963 These features are experimental in this version. More user feedback
2964 will help to stabilize them.
2965 Contributed by Alex Rozenman.
2967 ** IELR(1) and canonical LR(1):
2969 IELR(1) is a minimal LR(1) parser table generation algorithm. That
2970 is, given any context-free grammar, IELR(1) generates parser tables
2971 with the full language-recognition power of canonical LR(1) but with
2972 nearly the same number of parser states as LALR(1). This reduction
2973 in parser states is often an order of magnitude. More importantly,
2974 because canonical LR(1)'s extra parser states may contain duplicate
2975 conflicts in the case of non-LR(1) grammars, the number of conflicts
2976 for IELR(1) is often an order of magnitude less as well. This can
2977 significantly reduce the complexity of developing of a grammar.
2979 Bison can now generate IELR(1) and canonical LR(1) parser tables in
2980 place of its traditional LALR(1) parser tables, which remain the
2981 default. You can specify the type of parser tables in the grammar
2982 file with these directives:
2984 %define lr.type lalr
2985 %define lr.type ielr
2986 %define lr.type canonical-lr
2988 The default-reduction optimization in the parser tables can also be
2989 adjusted using "%define lr.default-reductions". For details on both
2990 of these features, see the new section "Tuning LR" in the Bison
2993 These features are experimental. More user feedback will help to
2996 ** LAC (Lookahead Correction) for syntax error handling
2998 Contributed by Joel E. Denny.
3000 Canonical LR, IELR, and LALR can suffer from a couple of problems
3001 upon encountering a syntax error. First, the parser might perform
3002 additional parser stack reductions before discovering the syntax
3003 error. Such reductions can perform user semantic actions that are
3004 unexpected because they are based on an invalid token, and they
3005 cause error recovery to begin in a different syntactic context than
3006 the one in which the invalid token was encountered. Second, when
3007 verbose error messages are enabled (with %error-verbose or the
3008 obsolete "#define YYERROR_VERBOSE"), the expected token list in the
3009 syntax error message can both contain invalid tokens and omit valid
3012 The culprits for the above problems are %nonassoc, default
3013 reductions in inconsistent states, and parser state merging. Thus,
3014 IELR and LALR suffer the most. Canonical LR can suffer only if
3015 %nonassoc is used or if default reductions are enabled for
3016 inconsistent states.
3018 LAC is a new mechanism within the parsing algorithm that solves
3019 these problems for canonical LR, IELR, and LALR without sacrificing
3020 %nonassoc, default reductions, or state merging. When LAC is in
3021 use, canonical LR and IELR behave almost exactly the same for both
3022 syntactically acceptable and syntactically unacceptable input.
3023 While LALR still does not support the full language-recognition
3024 power of canonical LR and IELR, LAC at least enables LALR's syntax
3025 error handling to correctly reflect LALR's language-recognition
3028 Currently, LAC is only supported for deterministic parsers in C.
3029 You can enable LAC with the following directive:
3031 %define parse.lac full
3033 See the new section "LAC" in the Bison manual for additional
3034 details including a few caveats.
3036 LAC is an experimental feature. More user feedback will help to
3039 ** %define improvements:
3041 *** Can now be invoked via the command line:
3043 Each of these command-line options
3046 --define=NAME[=VALUE]
3049 --force-define=NAME[=VALUE]
3051 is equivalent to this grammar file declaration
3053 %define NAME ["VALUE"]
3055 except that the manner in which Bison processes multiple definitions
3056 for the same NAME differs. Most importantly, -F and --force-define
3057 quietly override %define, but -D and --define do not. For further
3058 details, see the section "Bison Options" in the Bison manual.
3060 *** Variables renamed:
3062 The following %define variables
3065 lr.keep_unreachable_states
3067 have been renamed to
3070 lr.keep-unreachable-states
3072 The old names are now deprecated but will be maintained indefinitely
3073 for backward compatibility.
3075 *** Values no longer need to be quoted in the grammar file:
3077 If a %define value is an identifier, it no longer needs to be placed
3078 within quotations marks. For example,
3080 %define api.push-pull "push"
3084 %define api.push-pull push
3086 *** Unrecognized variables are now errors not warnings.
3088 *** Multiple invocations for any variable is now an error not a warning.
3090 ** Unrecognized %code qualifiers are now errors not warnings.
3092 ** Character literals not of length one:
3094 Previously, Bison quietly converted all character literals to length
3095 one. For example, without warning, Bison interpreted the operators in
3096 the following grammar to be the same token:
3102 Bison now warns when a character literal is not of length one. In
3103 some future release, Bison will start reporting an error instead.
3105 ** Destructor calls fixed for lookaheads altered in semantic actions:
3107 Previously for deterministic parsers in C, if a user semantic action
3108 altered yychar, the parser in some cases used the old yychar value to
3109 determine which destructor to call for the lookahead upon a syntax
3110 error or upon parser return. This bug has been fixed.
3112 ** C++ parsers use YYRHSLOC:
3114 Similarly to the C parsers, the C++ parsers now define the YYRHSLOC
3115 macro and use it in the default YYLLOC_DEFAULT. You are encouraged
3116 to use it. If, for instance, your location structure has "first"
3117 and "last" members, instead of
3119 # define YYLLOC_DEFAULT(Current, Rhs, N) \
3123 (Current).first = (Rhs)[1].location.first; \
3124 (Current).last = (Rhs)[N].location.last; \
3128 (Current).first = (Current).last = (Rhs)[0].location.last; \
3134 # define YYLLOC_DEFAULT(Current, Rhs, N) \
3138 (Current).first = YYRHSLOC (Rhs, 1).first; \
3139 (Current).last = YYRHSLOC (Rhs, N).last; \
3143 (Current).first = (Current).last = YYRHSLOC (Rhs, 0).last; \
3147 ** YYLLOC_DEFAULT in C++:
3149 The default implementation of YYLLOC_DEFAULT used to be issued in
3150 the header file. It is now output in the implementation file, after
3151 the user %code sections so that its #ifndef guard does not try to
3152 override the user's YYLLOC_DEFAULT if provided.
3154 ** YYFAIL now produces warnings and Java parsers no longer implement it:
3156 YYFAIL has existed for many years as an undocumented feature of
3157 deterministic parsers in C generated by Bison. More recently, it was
3158 a documented feature of Bison's experimental Java parsers. As
3159 promised in Bison 2.4.2's NEWS entry, any appearance of YYFAIL in a
3160 semantic action now produces a deprecation warning, and Java parsers
3161 no longer implement YYFAIL at all. For further details, including a
3162 discussion of how to suppress C preprocessor warnings about YYFAIL
3163 being unused, see the Bison 2.4.2 NEWS entry.
3165 ** Temporary hack for adding a semicolon to the user action:
3167 Previously, Bison appended a semicolon to every user action for
3168 reductions when the output language defaulted to C (specifically, when
3169 neither %yacc, %language, %skeleton, or equivalent command-line
3170 options were specified). This allowed actions such as
3172 exp: exp "+" exp { $$ = $1 + $3 };
3176 exp: exp "+" exp { $$ = $1 + $3; };
3178 As a first step in removing this misfeature, Bison now issues a
3179 warning when it appends a semicolon. Moreover, in cases where Bison
3180 cannot easily determine whether a semicolon is needed (for example, an
3181 action ending with a cpp directive or a braced compound initializer),
3182 it no longer appends one. Thus, the C compiler might now complain
3183 about a missing semicolon where it did not before. Future releases of
3184 Bison will cease to append semicolons entirely.
3186 ** Verbose syntax error message fixes:
3188 When %error-verbose or the obsolete "#define YYERROR_VERBOSE" is
3189 specified, syntax error messages produced by the generated parser
3190 include the unexpected token as well as a list of expected tokens.
3191 The effect of %nonassoc on these verbose messages has been corrected
3192 in two ways, but a more complete fix requires LAC, described above:
3194 *** When %nonassoc is used, there can exist parser states that accept no
3195 tokens, and so the parser does not always require a lookahead token
3196 in order to detect a syntax error. Because no unexpected token or
3197 expected tokens can then be reported, the verbose syntax error
3198 message described above is suppressed, and the parser instead
3199 reports the simpler message, "syntax error". Previously, this
3200 suppression was sometimes erroneously triggered by %nonassoc when a
3201 lookahead was actually required. Now verbose messages are
3202 suppressed only when all previous lookaheads have already been
3203 shifted or discarded.
3205 *** Previously, the list of expected tokens erroneously included tokens
3206 that would actually induce a syntax error because conflicts for them
3207 were resolved with %nonassoc in the current parser state. Such
3208 tokens are now properly omitted from the list.
3210 *** Expected token lists are still often wrong due to state merging
3211 (from LALR or IELR) and default reductions, which can both add
3212 invalid tokens and subtract valid tokens. Canonical LR almost
3213 completely fixes this problem by eliminating state merging and
3214 default reductions. However, there is one minor problem left even
3215 when using canonical LR and even after the fixes above. That is,
3216 if the resolution of a conflict with %nonassoc appears in a later
3217 parser state than the one at which some syntax error is
3218 discovered, the conflicted token is still erroneously included in
3219 the expected token list. Bison's new LAC implementation,
3220 described above, eliminates this problem and the need for
3221 canonical LR. However, LAC is still experimental and is disabled
3224 ** Java skeleton fixes:
3226 *** A location handling bug has been fixed.
3228 *** The top element of each of the value stack and location stack is now
3229 cleared when popped so that it can be garbage collected.
3231 *** Parser traces now print the top element of the stack.
3233 ** -W/--warnings fixes:
3235 *** Bison now properly recognizes the "no-" versions of categories:
3237 For example, given the following command line, Bison now enables all
3238 warnings except warnings for incompatibilities with POSIX Yacc:
3240 bison -Wall,no-yacc gram.y
3242 *** Bison now treats S/R and R/R conflicts like other warnings:
3244 Previously, conflict reports were independent of Bison's normal
3245 warning system. Now, Bison recognizes the warning categories
3246 "conflicts-sr" and "conflicts-rr". This change has important
3247 consequences for the -W and --warnings command-line options. For
3250 bison -Wno-conflicts-sr gram.y # S/R conflicts not reported
3251 bison -Wno-conflicts-rr gram.y # R/R conflicts not reported
3252 bison -Wnone gram.y # no conflicts are reported
3253 bison -Werror gram.y # any conflict is an error
3255 However, as before, if the %expect or %expect-rr directive is
3256 specified, an unexpected number of conflicts is an error, and an
3257 expected number of conflicts is not reported, so -W and --warning
3258 then have no effect on the conflict report.
3260 *** The "none" category no longer disables a preceding "error":
3262 For example, for the following command line, Bison now reports
3263 errors instead of warnings for incompatibilities with POSIX Yacc:
3265 bison -Werror,none,yacc gram.y
3267 *** The "none" category now disables all Bison warnings:
3269 Previously, the "none" category disabled only Bison warnings for
3270 which there existed a specific -W/--warning category. However,
3271 given the following command line, Bison is now guaranteed to
3272 suppress all warnings:
3276 ** Precedence directives can now assign token number 0:
3278 Since Bison 2.3b, which restored the ability of precedence
3279 directives to assign token numbers, doing so for token number 0 has
3280 produced an assertion failure. For example:
3284 This bug has been fixed.
3287 * Noteworthy changes in release 2.4.3 (2010-08-05)
3289 ** Bison now obeys -Werror and --warnings=error for warnings about
3290 grammar rules that are useless in the parser due to conflicts.
3292 ** Problems with spawning M4 on at least FreeBSD 8 and FreeBSD 9 have
3295 ** Failures in the test suite for GCC 4.5 have been fixed.
3297 ** Failures in the test suite for some versions of Sun Studio C++ have
3300 ** Contrary to Bison 2.4.2's NEWS entry, it has been decided that
3301 warnings about undefined %prec identifiers will not be converted to
3302 errors in Bison 2.5. They will remain warnings, which should be
3303 sufficient for POSIX while avoiding backward compatibility issues.
3305 ** Minor documentation fixes.
3308 * Noteworthy changes in release 2.4.2 (2010-03-20)
3310 ** Some portability problems that resulted in failures and livelocks
3311 in the test suite on some versions of at least Solaris, AIX, HP-UX,
3312 RHEL4, and Tru64 have been addressed. As a result, fatal Bison
3313 errors should no longer cause M4 to report a broken pipe on the
3316 ** "%prec IDENTIFIER" requires IDENTIFIER to be defined separately.
3318 POSIX specifies that an error be reported for any identifier that does
3319 not appear on the LHS of a grammar rule and that is not defined by
3320 %token, %left, %right, or %nonassoc. Bison 2.3b and later lost this
3321 error report for the case when an identifier appears only after a
3322 %prec directive. It is now restored. However, for backward
3323 compatibility with recent Bison releases, it is only a warning for
3324 now. In Bison 2.5 and later, it will return to being an error.
3325 [Between the 2.4.2 and 2.4.3 releases, it was decided that this
3326 warning will not be converted to an error in Bison 2.5.]
3328 ** Detection of GNU M4 1.4.6 or newer during configure is improved.
3330 ** Warnings from gcc's -Wundef option about undefined YYENABLE_NLS,
3331 YYLTYPE_IS_TRIVIAL, and __STRICT_ANSI__ in C/C++ parsers are now
3334 ** %code is now a permanent feature.
3336 A traditional Yacc prologue directive is written in the form:
3340 To provide a more flexible alternative, Bison 2.3b introduced the
3341 %code directive with the following forms for C/C++:
3344 %code requires {CODE}
3345 %code provides {CODE}
3348 These forms are now considered permanent features of Bison. See the
3349 %code entries in the section "Bison Declaration Summary" in the Bison
3350 manual for a summary of their functionality. See the section
3351 "Prologue Alternatives" for a detailed discussion including the
3352 advantages of %code over the traditional Yacc prologue directive.
3354 Bison's Java feature as a whole including its current usage of %code
3355 is still considered experimental.
3357 ** YYFAIL is deprecated and will eventually be removed.
3359 YYFAIL has existed for many years as an undocumented feature of
3360 deterministic parsers in C generated by Bison. Previously, it was
3361 documented for Bison's experimental Java parsers. YYFAIL is no longer
3362 documented for Java parsers and is formally deprecated in both cases.
3363 Users are strongly encouraged to migrate to YYERROR, which is
3366 Like YYERROR, you can invoke YYFAIL from a semantic action in order to
3367 induce a syntax error. The most obvious difference from YYERROR is
3368 that YYFAIL will automatically invoke yyerror to report the syntax
3369 error so that you don't have to. However, there are several other
3370 subtle differences between YYERROR and YYFAIL, and YYFAIL suffers from
3371 inherent flaws when %error-verbose or "#define YYERROR_VERBOSE" is
3372 used. For a more detailed discussion, see:
3374 http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html
3376 The upcoming Bison 2.5 will remove YYFAIL from Java parsers, but
3377 deterministic parsers in C will continue to implement it. However,
3378 because YYFAIL is already flawed, it seems futile to try to make new
3379 Bison features compatible with it. Thus, during parser generation,
3380 Bison 2.5 will produce a warning whenever it discovers YYFAIL in a
3381 rule action. In a later release, YYFAIL will be disabled for
3382 %error-verbose and "#define YYERROR_VERBOSE". Eventually, YYFAIL will
3383 be removed altogether.
3385 There exists at least one case where Bison 2.5's YYFAIL warning will
3386 be a false positive. Some projects add phony uses of YYFAIL and other
3387 Bison-defined macros for the sole purpose of suppressing C
3388 preprocessor warnings (from GCC cpp's -Wunused-macros, for example).
3389 To avoid Bison's future warning, such YYFAIL uses can be moved to the
3390 epilogue (that is, after the second "%%") in the Bison input file. In
3391 this release (2.4.2), Bison already generates its own code to suppress
3392 C preprocessor warnings for YYFAIL, so projects can remove their own
3393 phony uses of YYFAIL if compatibility with Bison releases prior to
3394 2.4.2 is not necessary.
3396 ** Internationalization.
3398 Fix a regression introduced in Bison 2.4: Under some circumstances,
3399 message translations were not installed although supported by the
3403 * Noteworthy changes in release 2.4.1 (2008-12-11)
3405 ** In the GLR defines file, unexpanded M4 macros in the yylval and yylloc
3406 declarations have been fixed.
3408 ** Temporary hack for adding a semicolon to the user action.
3410 Bison used to prepend a trailing semicolon at the end of the user
3411 action for reductions. This allowed actions such as
3413 exp: exp "+" exp { $$ = $1 + $3 };
3417 exp: exp "+" exp { $$ = $1 + $3; };
3419 Some grammars still depend on this "feature". Bison 2.4.1 restores
3420 the previous behavior in the case of C output (specifically, when
3421 neither %language or %skeleton or equivalent command-line options
3422 are used) to leave more time for grammars depending on the old
3423 behavior to be adjusted. Future releases of Bison will disable this
3426 ** A few minor improvements to the Bison manual.
3429 * Noteworthy changes in release 2.4 (2008-11-02)
3431 ** %language is an experimental feature.
3433 We first introduced this feature in test release 2.3b as a cleaner
3434 alternative to %skeleton. Since then, we have discussed the possibility of
3435 modifying its effect on Bison's output file names. Thus, in this release,
3436 we consider %language to be an experimental feature that will likely evolve
3439 ** Forward compatibility with GNU M4 has been improved.
3441 ** Several bugs in the C++ skeleton and the experimental Java skeleton have been
3445 * Noteworthy changes in release 2.3b (2008-05-27)
3447 ** The quotes around NAME that used to be required in the following directive
3450 %define NAME "VALUE"
3452 ** The directive "%pure-parser" is now deprecated in favor of:
3456 which has the same effect except that Bison is more careful to warn about
3457 unreasonable usage in the latter case.
3461 Bison can now generate an LALR(1) parser in C with a push interface. That
3462 is, instead of invoking "yyparse", which pulls tokens from "yylex", you can
3463 push one token at a time to the parser using "yypush_parse", which will
3464 return to the caller after processing each token. By default, the push
3465 interface is disabled. Either of the following directives will enable it:
3467 %define api.push_pull "push" // Just push; does not require yylex.
3468 %define api.push_pull "both" // Push and pull; requires yylex.
3470 See the new section "A Push Parser" in the Bison manual for details.
3472 The current push parsing interface is experimental and may evolve. More user
3473 feedback will help to stabilize it.
3475 ** The -g and --graph options now output graphs in Graphviz DOT format,
3476 not VCG format. Like --graph, -g now also takes an optional FILE argument
3477 and thus cannot be bundled with other short options.
3481 Bison can now generate an LALR(1) parser in Java. The skeleton is
3482 "data/lalr1.java". Consider using the new %language directive instead of
3483 %skeleton to select it.
3485 See the new section "Java Parsers" in the Bison manual for details.
3487 The current Java interface is experimental and may evolve. More user
3488 feedback will help to stabilize it.
3489 Contributed by Paolo Bonzini.
3493 This new directive specifies the programming language of the generated
3494 parser, which can be C (the default), C++, or Java. Besides the skeleton
3495 that Bison uses, the directive affects the names of the generated files if
3496 the grammar file's name ends in ".y".
3498 ** XML Automaton Report
3500 Bison can now generate an XML report of the LALR(1) automaton using the new
3501 "--xml" option. The current XML schema is experimental and may evolve. More
3502 user feedback will help to stabilize it.
3503 Contributed by Wojciech Polak.
3505 ** The grammar file may now specify the name of the parser header file using
3506 %defines. For example:
3510 ** When reporting useless rules, useless nonterminals, and unused terminals,
3511 Bison now employs the terms "useless in grammar" instead of "useless",
3512 "useless in parser" instead of "never reduced", and "unused in grammar"
3513 instead of "unused".
3515 ** Unreachable State Removal
3517 Previously, Bison sometimes generated parser tables containing unreachable
3518 states. A state can become unreachable during conflict resolution if Bison
3519 disables a shift action leading to it from a predecessor state. Bison now:
3521 1. Removes unreachable states.
3523 2. Does not report any conflicts that appeared in unreachable states.
3524 WARNING: As a result, you may need to update %expect and %expect-rr
3525 directives in existing grammar files.
3527 3. For any rule used only in such states, Bison now reports the rule as
3528 "useless in parser due to conflicts".
3530 This feature can be disabled with the following directive:
3532 %define lr.keep_unreachable_states
3534 See the %define entry in the "Bison Declaration Summary" in the Bison manual
3535 for further discussion.
3537 ** Lookahead Set Correction in the ".output" Report
3539 When instructed to generate a ".output" file including lookahead sets
3540 (using "--report=lookahead", for example), Bison now prints each reduction's
3541 lookahead set only next to the associated state's one item that (1) is
3542 associated with the same rule as the reduction and (2) has its dot at the end
3543 of its RHS. Previously, Bison also erroneously printed the lookahead set
3544 next to all of the state's other items associated with the same rule. This
3545 bug affected only the ".output" file and not the generated parser source
3548 ** --report-file=FILE is a new option to override the default ".output" file
3551 ** The "=" that used to be required in the following directives is now
3554 %file-prefix "parser"
3558 ** An Alternative to "%{...%}" -- "%code QUALIFIER {CODE}"
3560 Bison 2.3a provided a new set of directives as a more flexible alternative to
3561 the traditional Yacc prologue blocks. Those have now been consolidated into
3562 a single %code directive with an optional qualifier field, which identifies
3563 the purpose of the code and thus the location(s) where Bison should generate
3566 1. "%code {CODE}" replaces "%after-header {CODE}"
3567 2. "%code requires {CODE}" replaces "%start-header {CODE}"
3568 3. "%code provides {CODE}" replaces "%end-header {CODE}"
3569 4. "%code top {CODE}" replaces "%before-header {CODE}"
3571 See the %code entries in section "Bison Declaration Summary" in the Bison
3572 manual for a summary of the new functionality. See the new section "Prologue
3573 Alternatives" for a detailed discussion including the advantages of %code
3574 over the traditional Yacc prologues.
3576 The prologue alternatives are experimental. More user feedback will help to
3577 determine whether they should become permanent features.
3579 ** Revised warning: unset or unused midrule values
3581 Since Bison 2.2, Bison has warned about midrule values that are set but not
3582 used within any of the actions of the parent rule. For example, Bison warns
3585 exp: '1' { $$ = 1; } '+' exp { $$ = $1 + $4; };
3587 Now, Bison also warns about midrule values that are used but not set. For
3588 example, Bison warns about unset $$ in the midrule action in:
3590 exp: '1' { $1 = 1; } '+' exp { $$ = $2 + $4; };
3592 However, Bison now disables both of these warnings by default since they
3593 sometimes prove to be false alarms in existing grammars employing the Yacc
3594 constructs $0 or $-N (where N is some positive integer).
3596 To enable these warnings, specify the option "--warnings=midrule-values" or
3597 "-W", which is a synonym for "--warnings=all".
3599 ** Default %destructor or %printer with "<*>" or "<>"
3601 Bison now recognizes two separate kinds of default %destructor's and
3604 1. Place "<*>" in a %destructor/%printer symbol list to define a default
3605 %destructor/%printer for all grammar symbols for which you have formally
3606 declared semantic type tags.
3608 2. Place "<>" in a %destructor/%printer symbol list to define a default
3609 %destructor/%printer for all grammar symbols without declared semantic
3612 Bison no longer supports the "%symbol-default" notation from Bison 2.3a.
3613 "<*>" and "<>" combined achieve the same effect with one exception: Bison no
3614 longer applies any %destructor to a midrule value if that midrule value is
3615 not actually ever referenced using either $$ or $n in a semantic action.
3617 The default %destructor's and %printer's are experimental. More user
3618 feedback will help to determine whether they should become permanent
3621 See the section "Freeing Discarded Symbols" in the Bison manual for further
3624 ** %left, %right, and %nonassoc can now declare token numbers. This is required
3625 by POSIX. However, see the end of section "Operator Precedence" in the Bison
3626 manual for a caveat concerning the treatment of literal strings.
3628 ** The nonfunctional --no-parser, -n, and %no-parser options have been
3629 completely removed from Bison.
3632 * Noteworthy changes in release 2.3a (2006-09-13)
3634 ** Instead of %union, you can define and use your own union type
3635 YYSTYPE if your grammar contains at least one <type> tag.
3636 Your YYSTYPE need not be a macro; it can be a typedef.
3637 This change is for compatibility with other Yacc implementations,
3638 and is required by POSIX.
3640 ** Locations columns and lines start at 1.
3641 In accordance with the GNU Coding Standards and Emacs.
3643 ** You may now declare per-type and default %destructor's and %printer's:
3647 %union { char *string; }
3648 %token <string> STRING1
3649 %token <string> STRING2
3650 %type <string> string1
3651 %type <string> string2
3652 %union { char character; }
3653 %token <character> CHR
3654 %type <character> chr
3655 %destructor { free ($$); } %symbol-default
3656 %destructor { free ($$); printf ("%d", @$.first_line); } STRING1 string1
3657 %destructor { } <character>
3659 guarantees that, when the parser discards any user-defined symbol that has a
3660 semantic type tag other than "<character>", it passes its semantic value to
3661 "free". However, when the parser discards a "STRING1" or a "string1", it
3662 also prints its line number to "stdout". It performs only the second
3663 "%destructor" in this case, so it invokes "free" only once.
3665 [Although we failed to mention this here in the 2.3a release, the default
3666 %destructor's and %printer's were experimental, and they were rewritten in
3669 ** Except for LALR(1) parsers in C with POSIX Yacc emulation enabled (with "-y",
3670 "--yacc", or "%yacc"), Bison no longer generates #define statements for
3671 associating token numbers with token names. Removing the #define statements
3672 helps to sanitize the global namespace during preprocessing, but POSIX Yacc
3673 requires them. Bison still generates an enum for token names in all cases.
3675 ** Handling of traditional Yacc prologue blocks is now more consistent but
3676 potentially incompatible with previous releases of Bison.
3678 As before, you declare prologue blocks in your grammar file with the
3679 "%{ ... %}" syntax. To generate the pre-prologue, Bison concatenates all
3680 prologue blocks that you've declared before the first %union. To generate
3681 the post-prologue, Bison concatenates all prologue blocks that you've
3682 declared after the first %union.
3684 Previous releases of Bison inserted the pre-prologue into both the header
3685 file and the code file in all cases except for LALR(1) parsers in C. In the
3686 latter case, Bison inserted it only into the code file. For parsers in C++,
3687 the point of insertion was before any token definitions (which associate
3688 token numbers with names). For parsers in C, the point of insertion was
3689 after the token definitions.
3691 Now, Bison never inserts the pre-prologue into the header file. In the code
3692 file, it always inserts it before the token definitions.
3694 ** Bison now provides a more flexible alternative to the traditional Yacc
3695 prologue blocks: %before-header, %start-header, %end-header, and
3698 For example, the following declaration order in the grammar file reflects the
3699 order in which Bison will output these code blocks. However, you are free to
3700 declare these code blocks in your grammar file in whatever order is most
3704 /* Bison treats this block like a pre-prologue block: it inserts it into
3705 * the code file before the contents of the header file. It does *not*
3706 * insert it into the header file. This is a good place to put
3707 * #include's that you want at the top of your code file. A common
3708 * example is '#include "system.h"'. */
3711 /* Bison inserts this block into both the header file and the code file.
3712 * In both files, the point of insertion is before any Bison-generated
3713 * token, semantic type, location type, and class definitions. This is a
3714 * good place to define %union dependencies, for example. */
3717 /* Unlike the traditional Yacc prologue blocks, the output order for the
3718 * new %*-header blocks is not affected by their declaration position
3719 * relative to any %union in the grammar file. */
3722 /* Bison inserts this block into both the header file and the code file.
3723 * In both files, the point of insertion is after the Bison-generated
3724 * definitions. This is a good place to declare or define public
3725 * functions or data structures that depend on the Bison-generated
3729 /* Bison treats this block like a post-prologue block: it inserts it into
3730 * the code file after the contents of the header file. It does *not*
3731 * insert it into the header file. This is a good place to declare or
3732 * define internal functions or data structures that depend on the
3733 * Bison-generated definitions. */
3736 If you have multiple occurrences of any one of the above declarations, Bison
3737 will concatenate the contents in declaration order.
3739 [Although we failed to mention this here in the 2.3a release, the prologue
3740 alternatives were experimental, and they were rewritten in future versions.]
3742 ** The option "--report=look-ahead" has been changed to "--report=lookahead".
3743 The old spelling still works, but is not documented and may be removed
3744 in a future release.
3747 * Noteworthy changes in release 2.3 (2006-06-05)
3749 ** GLR grammars should now use "YYRECOVERING ()" instead of "YYRECOVERING",
3750 for compatibility with LALR(1) grammars.
3752 ** It is now documented that any definition of YYSTYPE or YYLTYPE should
3753 be to a type name that does not contain parentheses or brackets.
3756 * Noteworthy changes in release 2.2 (2006-05-19)
3758 ** The distribution terms for all Bison-generated parsers now permit
3759 using the parsers in nonfree programs. Previously, this permission
3760 was granted only for Bison-generated LALR(1) parsers in C.
3762 ** %name-prefix changes the namespace name in C++ outputs.
3764 ** The C++ parsers export their token_type.
3766 ** Bison now allows multiple %union declarations, and concatenates
3767 their contents together.
3769 ** New warning: unused values
3770 Right-hand side symbols whose values are not used are reported,
3771 if the symbols have destructors. For instance:
3773 exp: exp "?" exp ":" exp { $1 ? $1 : $3; }
3777 will trigger a warning about $$ and $5 in the first rule, and $3 in
3778 the second ($1 is copied to $$ by the default rule). This example
3779 most likely contains three errors, and could be rewritten as:
3781 exp: exp "?" exp ":" exp
3782 { $$ = $1 ? $3 : $5; free ($1 ? $5 : $3); free ($1); }
3784 { $$ = $1 ? $1 : $3; if ($1) free ($3); }
3787 However, if the original actions were really intended, memory leaks
3788 and all, the warnings can be suppressed by letting Bison believe the
3789 values are used, e.g.:
3791 exp: exp "?" exp ":" exp { $1 ? $1 : $3; (void) ($$, $5); }
3792 | exp "+" exp { $$ = $1; (void) $3; }
3795 If there are midrule actions, the warning is issued if no action
3796 uses it. The following triggers no warning: $1 and $3 are used.
3798 exp: exp { push ($1); } '+' exp { push ($3); sum (); };
3800 The warning is intended to help catching lost values and memory leaks.
3801 If a value is ignored, its associated memory typically is not reclaimed.
3803 ** %destructor vs. YYABORT, YYACCEPT, and YYERROR.
3804 Destructors are now called when user code invokes YYABORT, YYACCEPT,
3805 and YYERROR, for all objects on the stack, other than objects
3806 corresponding to the right-hand side of the current rule.
3808 ** %expect, %expect-rr
3809 Incorrect numbers of expected conflicts are now actual errors,
3810 instead of warnings.
3812 ** GLR, YACC parsers.
3813 The %parse-params are available in the destructors (and the
3814 experimental printers) as per the documentation.
3816 ** Bison now warns if it finds a stray "$" or "@" in an action.
3818 ** %require "VERSION"
3819 This specifies that the grammar file depends on features implemented
3820 in Bison version VERSION or higher.
3822 ** lalr1.cc: The token and value types are now class members.
3823 The tokens were defined as free form enums and cpp macros. YYSTYPE
3824 was defined as a free form union. They are now class members:
3825 tokens are enumerations of the "yy::parser::token" struct, and the
3826 semantic values have the "yy::parser::semantic_type" type.
3828 If you do not want or can update to this scheme, the directive
3829 '%define "global_tokens_and_yystype" "1"' triggers the global
3830 definition of tokens and YYSTYPE. This change is suitable both
3831 for previous releases of Bison, and this one.
3833 If you wish to update, then make sure older version of Bison will
3834 fail using '%require "2.2"'.
3836 ** DJGPP support added.
3839 * Noteworthy changes in release 2.1 (2005-09-16)
3841 ** The C++ lalr1.cc skeleton supports %lex-param.
3843 ** Bison-generated parsers now support the translation of diagnostics like
3844 "syntax error" into languages other than English. The default
3845 language is still English. For details, please see the new
3846 Internationalization section of the Bison manual. Software
3847 distributors should also see the new PACKAGING file. Thanks to
3848 Bruno Haible for this new feature.
3850 ** Wording in the Bison-generated parsers has been changed slightly to
3851 simplify translation. In particular, the message "memory exhausted"
3852 has replaced "parser stack overflow", as the old message was not
3853 always accurate for modern Bison-generated parsers.
3855 ** Destructors are now called when the parser aborts, for all symbols left
3856 behind on the stack. Also, the start symbol is now destroyed after a
3857 successful parse. In both cases, the behavior was formerly inconsistent.
3859 ** When generating verbose diagnostics, Bison-generated parsers no longer
3860 quote the literal strings associated with tokens. For example, for
3861 a syntax error associated with '%token NUM "number"' they might
3862 print 'syntax error, unexpected number' instead of 'syntax error,
3863 unexpected "number"'.
3866 * Noteworthy changes in release 2.0 (2004-12-25)
3868 ** Possibly-incompatible changes
3870 - Bison-generated parsers no longer default to using the alloca function
3871 (when available) to extend the parser stack, due to widespread
3872 problems in unchecked stack-overflow detection. You can "#define
3873 YYSTACK_USE_ALLOCA 1" to require the use of alloca, but please read
3874 the manual to determine safe values for YYMAXDEPTH in that case.
3876 - Error token location.
3877 During error recovery, the location of the syntax error is updated
3878 to cover the whole sequence covered by the error token: it includes
3879 the shifted symbols thrown away during the first part of the error
3880 recovery, and the lookahead rejected during the second part.
3882 - Semicolon changes:
3883 . Stray semicolons are no longer allowed at the start of a grammar.
3884 . Semicolons are now required after in-grammar declarations.
3886 - Unescaped newlines are no longer allowed in character constants or
3887 string literals. They were never portable, and GCC 3.4.0 has
3888 dropped support for them. Better diagnostics are now generated if
3889 forget a closing quote.
3891 - NUL bytes are no longer allowed in Bison string literals, unfortunately.
3895 - GLR grammars now support locations.
3897 - New directive: %initial-action.
3898 This directive allows the user to run arbitrary code (including
3899 initializing @$) from yyparse before parsing starts.
3901 - A new directive "%expect-rr N" specifies the expected number of
3902 reduce/reduce conflicts in GLR parsers.
3904 - %token numbers can now be hexadecimal integers, e.g., "%token FOO 0x12d".
3905 This is a GNU extension.
3907 - The option "--report=lookahead" was changed to "--report=look-ahead".
3908 [However, this was changed back after 2.3.]
3910 - Experimental %destructor support has been added to lalr1.cc.
3912 - New configure option --disable-yacc, to disable installation of the
3913 yacc command and -ly library introduced in 1.875 for POSIX conformance.
3917 - For now, %expect-count violations are now just warnings, not errors.
3918 This is for compatibility with Bison 1.75 and earlier (when there are
3919 reduce/reduce conflicts) and with Bison 1.30 and earlier (when there
3920 are too many or too few shift/reduce conflicts). However, in future
3921 versions of Bison we plan to improve the %expect machinery so that
3922 these violations will become errors again.
3924 - Within Bison itself, numbers (e.g., goto numbers) are no longer
3925 arbitrarily limited to 16-bit counts.
3927 - Semicolons are now allowed before "|" in grammar rules, as POSIX requires.
3930 * Noteworthy changes in release 1.875 (2003-01-01)
3932 ** The documentation license has been upgraded to version 1.2
3933 of the GNU Free Documentation License.
3935 ** syntax error processing
3937 - In Yacc-style parsers YYLLOC_DEFAULT is now used to compute error
3938 locations too. This fixes bugs in error-location computation.
3941 It is now possible to reclaim the memory associated to symbols
3942 discarded during error recovery. This feature is still experimental.
3945 This new directive is preferred over YYERROR_VERBOSE.
3947 - #defining yyerror to steal internal variables is discouraged.
3948 It is not guaranteed to work forever.
3950 ** POSIX conformance
3952 - Semicolons are once again optional at the end of grammar rules.
3953 This reverts to the behavior of Bison 1.33 and earlier, and improves
3954 compatibility with Yacc.
3956 - "parse error" -> "syntax error"
3957 Bison now uniformly uses the term "syntax error"; formerly, the code
3958 and manual sometimes used the term "parse error" instead. POSIX
3959 requires "syntax error" in diagnostics, and it was thought better to
3962 - The documentation now emphasizes that yylex and yyerror must be
3963 declared before use. C99 requires this.
3965 - Bison now parses C99 lexical constructs like UCNs and
3966 backslash-newline within C escape sequences, as POSIX 1003.1-2001 requires.
3968 - File names are properly escaped in C output. E.g., foo\bar.y is
3969 output as "foo\\bar.y".
3971 - Yacc command and library now available
3972 The Bison distribution now installs a "yacc" command, as POSIX requires.
3973 Also, Bison now installs a small library liby.a containing
3974 implementations of Yacc-compatible yyerror and main functions.
3975 This library is normally not useful, but POSIX requires it.
3977 - Type clashes now generate warnings, not errors.
3979 - If the user does not define YYSTYPE as a macro, Bison now declares it
3980 using typedef instead of defining it as a macro.
3981 For consistency, YYLTYPE is also declared instead of defined.
3983 ** Other compatibility issues
3985 - %union directives can now have a tag before the "{", e.g., the
3986 directive "%union foo {...}" now generates the C code
3987 "typedef union foo { ... } YYSTYPE;"; this is for Yacc compatibility.
3988 The default union tag is "YYSTYPE", for compatibility with Solaris 9 Yacc.
3989 For consistency, YYLTYPE's struct tag is now "YYLTYPE" not "yyltype".
3990 This is for compatibility with both Yacc and Bison 1.35.
3992 - ";" is output before the terminating "}" of an action, for
3993 compatibility with Bison 1.35.
3995 - Bison now uses a Yacc-style format for conflict reports, e.g.,
3996 "conflicts: 2 shift/reduce, 1 reduce/reduce".
3998 - "yystype" and "yyltype" are now obsolescent macros instead of being
3999 typedefs or tags; they are no longer documented and are planned to be
4000 withdrawn in a future release.
4005 Users of Bison have to decide how they handle the portability of the
4008 - "parsing stack overflow..." -> "parser stack overflow"
4009 GLR parsers now report "parser stack overflow" as per the Bison manual.
4011 ** %parse-param and %lex-param
4012 The macros YYPARSE_PARAM and YYLEX_PARAM provide a means to pass
4013 additional context to yyparse and yylex. They suffer from several
4016 - a single argument only can be added,
4017 - their types are weak (void *),
4018 - this context is not passed to ancillary functions such as yyerror,
4019 - only yacc.c parsers support them.
4021 The new %parse-param/%lex-param directives provide a more precise control.
4024 %parse-param {int *nastiness}
4025 %lex-param {int *nastiness}
4026 %parse-param {int *randomness}
4028 results in the following signatures:
4030 int yylex (int *nastiness);
4031 int yyparse (int *nastiness, int *randomness);
4033 or, if both %pure-parser and %locations are used:
4035 int yylex (YYSTYPE *lvalp, YYLTYPE *llocp, int *nastiness);
4036 int yyparse (int *nastiness, int *randomness);
4038 ** Bison now warns if it detects conflicting outputs to the same file,
4039 e.g., it generates a warning for "bison -d -o foo.h foo.y" since
4040 that command outputs both code and header to foo.h.
4042 ** #line in output files
4043 - --no-line works properly.
4045 ** Bison can no longer be built by a K&R C compiler; it requires C89 or
4046 later to be built. This change originally took place a few versions
4047 ago, but nobody noticed until we recently asked someone to try
4048 building Bison with a K&R C compiler.
4051 * Noteworthy changes in release 1.75 (2002-10-14)
4053 ** Bison should now work on 64-bit hosts.
4055 ** Indonesian translation thanks to Tedi Heriyanto.
4058 Fix spurious parse errors.
4061 Some people redefine yyerror to steal yyparse' private variables.
4062 Reenable this trick until an official feature replaces it.
4065 In agreement with POSIX and with other Yaccs, leaving a default
4066 action is valid when $$ is untyped, and $1 typed:
4070 but the converse remains an error:
4074 ** Values of midrule actions
4077 foo: { ... } { $$ = $1; } ...
4079 was incorrectly rejected: $1 is defined in the second midrule
4080 action, and is equal to the $$ of the first midrule action.
4083 * Noteworthy changes in release 1.50 (2002-10-04)
4088 causes Bison to produce a Generalized LR (GLR) parser, capable of handling
4089 almost any context-free grammar, ambiguous or not. The new declarations
4090 %dprec and %merge on grammar rules allow parse-time resolution of
4091 ambiguities. Contributed by Paul Hilfinger.
4093 Unfortunately Bison 1.50 does not work properly on 64-bit hosts
4094 like the Alpha, so please stick to 32-bit hosts for now.
4097 When not in Yacc compatibility mode, when the output file was not
4098 specified, running "bison foo/bar.y" created "foo/bar.c". It
4099 now creates "bar.c".
4102 The undefined token was systematically mapped to 2 which prevented
4103 the use of 2 by the user. This is no longer the case.
4105 ** Unknown token numbers
4106 If yylex returned an out of range value, yyparse could die. This is
4110 According to POSIX, the error token must be 256.
4111 Bison extends this requirement by making it a preference: *if* the
4112 user specified that one of her tokens is numbered 256, then error
4113 will be mapped onto another number.
4115 ** Verbose error messages
4116 They no longer report "..., expecting error or..." for states where
4117 error recovery is possible.
4120 Defaults to "$end" instead of "$".
4122 ** Error recovery now conforms to documentation and to POSIX
4123 When a Bison-generated parser encounters a syntax error, it now pops
4124 the stack until it finds a state that allows shifting the error
4125 token. Formerly, it popped the stack until it found a state that
4126 allowed some non-error action other than a default reduction on the
4127 error token. The new behavior has long been the documented behavior,
4128 and has long been required by POSIX. For more details, please see
4129 Paul Eggert, "Reductions during Bison error handling" (2002-05-20)
4130 <http://lists.gnu.org/archive/html/bug-bison/2002-05/msg00038.html>.
4133 Popped tokens and nonterminals are now reported.
4136 Larger grammars are now supported (larger token numbers, larger grammar
4137 size (= sum of the LHS and RHS lengths), larger LALR tables).
4138 Formerly, many of these numbers ran afoul of 16-bit limits;
4139 now these limits are 32 bits on most hosts.
4141 ** Explicit initial rule
4142 Bison used to play hacks with the initial rule, which the user does
4143 not write. It is now explicit, and visible in the reports and
4147 Before, Bison reported the useless rules, but, although not used,
4148 included them in the parsers. They are now actually removed.
4150 ** Useless rules, useless nonterminals
4151 They are now reported, as a warning, with their locations.
4153 ** Rules never reduced
4154 Rules that can never be reduced because of conflicts are now
4157 ** Incorrect "Token not used"
4158 On a grammar such as
4160 %token useless useful
4162 exp: '0' %prec useful;
4164 where a token was used to set the precedence of the last rule,
4165 bison reported both "useful" and "useless" as useless tokens.
4167 ** Revert the C++ namespace changes introduced in 1.31
4168 as they caused too many portability hassles.
4170 ** Default locations
4171 By an accident of design, the default computation of @$ was
4172 performed after another default computation was performed: @$ = @1.
4173 The latter is now removed: YYLLOC_DEFAULT is fully responsible of
4174 the computation of @$.
4176 ** Token end-of-file
4177 The token end of file may be specified by the user, in which case,
4178 the user symbol is used in the reports, the graphs, and the verbose
4179 error messages instead of "$end", which remains being the default.
4183 %token MYEOF 0 "end of file"
4186 This old option, which has been broken for ages, is removed.
4189 Brazilian Portuguese, thanks to Alexandre Folle de Menezes.
4190 Croatian, thanks to Denis Lackovic.
4192 ** Incorrect token definitions
4195 bison used to output
4198 ** Token definitions as enums
4199 Tokens are output both as the traditional #define's, and, provided
4200 the compiler supports ANSI C or is a C++ compiler, as enums.
4201 This lets debuggers display names instead of integers.
4204 In addition to --verbose, bison supports --report=THINGS, which
4205 produces additional information:
4207 complete the core item sets with their closure
4208 - lookahead [changed to "look-ahead" in 1.875e through 2.3, but changed back]
4209 explicitly associate lookahead tokens to items
4211 describe shift/reduce conflicts solving.
4212 Bison used to systematically output this information on top of
4213 the report. Solved conflicts are now attached to their states.
4216 Previous versions don't complain when there is a type clash on
4217 the default action if the rule has a midrule action, such as in:
4225 ** GNU M4 is now required when using Bison.
4228 * Noteworthy changes in release 1.35 (2002-03-25)
4231 Some projects use Bison's C parser with C++ compilers, and define
4232 YYSTYPE as a class. The recent adjustment of C parsers for data
4233 alignment and 64 bit architectures made this impossible.
4235 Because for the time being no real solution for C++ parser
4236 generation exists, kludges were implemented in the parser to
4237 maintain this use. In the future, when Bison has C++ parsers, this
4238 kludge will be disabled.
4240 This kludge also addresses some C++ problems when the stack was
4244 * Noteworthy changes in release 1.34 (2002-03-12)
4246 ** File name clashes are detected
4247 $ bison foo.y -d -o foo.x
4248 fatal error: header and parser would both be named "foo.x"
4250 ** A missing ";" at the end of a rule triggers a warning
4251 In accordance with POSIX, and in agreement with other
4252 Yacc implementations, Bison will mandate this semicolon in the near
4253 future. This eases the implementation of a Bison parser of Bison
4254 grammars by making this grammar LALR(1) instead of LR(2). To
4255 facilitate the transition, this release introduces a warning.
4257 ** Revert the C++ namespace changes introduced in 1.31, as they caused too
4258 many portability hassles.
4260 ** DJGPP support added.
4262 ** Fix test suite portability problems.
4265 * Noteworthy changes in release 1.33 (2002-02-07)
4268 Groff could not be compiled for the definition of size_t was lacking
4269 under some conditions.
4275 * Noteworthy changes in release 1.32 (2002-01-23)
4277 ** Fix Yacc output file names
4279 ** Portability fixes
4281 ** Italian, Dutch translations
4284 * Noteworthy changes in release 1.31 (2002-01-14)
4288 ** GNU Gettext and %expect
4289 GNU Gettext asserts 10 s/r conflicts, but there are 7. Now that
4290 Bison dies on incorrect %expectations, we fear there will be
4291 too many bug reports for Gettext, so _for the time being_, %expect
4292 does not trigger an error when the input file is named "plural.y".
4294 ** Use of alloca in parsers
4295 If YYSTACK_USE_ALLOCA is defined to 0, then the parsers will use
4296 malloc exclusively. Since 1.29, but was not NEWS'ed.
4298 alloca is used only when compiled with GCC, to avoid portability
4301 ** yyparse now returns 2 if memory is exhausted; formerly it dumped core.
4303 ** When the generated parser lacks debugging code, YYDEBUG is now 0
4304 (as POSIX requires) instead of being undefined.
4307 Bison has always permitted actions such as { $$ = $1 }: it adds the
4308 ending semicolon. Now if in Yacc compatibility mode, the semicolon
4309 is no longer output: one has to write { $$ = $1; }.
4311 ** Better C++ compliance
4312 The output parsers try to respect C++ namespaces.
4313 [This turned out to be a failed experiment, and it was reverted later.]
4316 Fixed bugs when reporting useless nonterminals.
4319 The parsers work properly on 64 bit hosts.
4322 Some calls to strerror resulted in scrambled or missing error messages.
4325 When the number of shift/reduce conflicts is correct, don't issue
4328 ** The verbose report includes the rule line numbers.
4330 ** Rule line numbers are fixed in traces.
4332 ** Swedish translation
4335 Verbose parse error messages from the parsers are better looking.
4336 Before: parse error: unexpected `'/'', expecting `"number"' or `'-'' or `'(''
4337 Now: parse error: unexpected '/', expecting "number" or '-' or '('
4339 ** Fixed parser memory leaks.
4340 When the generated parser was using malloc to extend its stacks, the
4341 previous allocations were not freed.
4343 ** Fixed verbose output file.
4344 Some newlines were missing.
4345 Some conflicts in state descriptions were missing.
4347 ** Fixed conflict report.
4348 Option -v was needed to get the result.
4352 Mismatches are errors, not warnings.
4354 ** Fixed incorrect processing of some invalid input.
4356 ** Fixed CPP guards: 9foo.h uses BISON_9FOO_H instead of 9FOO_H.
4358 ** Fixed some typos in the documentation.
4360 ** %token MY_EOF 0 is supported.
4361 Before, MY_EOF was silently renumbered as 257.
4363 ** doc/refcard.tex is updated.
4365 ** %output, %file-prefix, %name-prefix.
4369 New, aliasing "--output-file".
4372 * Noteworthy changes in release 1.30 (2001-10-26)
4374 ** "--defines" and "--graph" have now an optional argument which is the
4375 output file name. "-d" and "-g" do not change; they do not take any
4378 ** "%source_extension" and "%header_extension" are removed, failed
4381 ** Portability fixes.
4384 * Noteworthy changes in release 1.29 (2001-09-07)
4386 ** The output file does not define const, as this caused problems when used
4387 with common autoconfiguration schemes. If you still use ancient compilers
4388 that lack const, compile with the equivalent of the C compiler option
4389 "-Dconst=". Autoconf's AC_C_CONST macro provides one way to do this.
4391 ** Added "-g" and "--graph".
4393 ** The Bison manual is now distributed under the terms of the GNU FDL.
4395 ** The input and the output files has automatically a similar extension.
4397 ** Russian translation added.
4399 ** NLS support updated; should hopefully be less troublesome.
4401 ** Added the old Bison reference card.
4403 ** Added "--locations" and "%locations".
4405 ** Added "-S" and "--skeleton".
4407 ** "%raw", "-r", "--raw" is disabled.
4409 ** Special characters are escaped when output. This solves the problems
4410 of the #line lines with path names including backslashes.
4413 "%yacc", "%fixed_output_files", "%defines", "%no_parser", "%verbose",
4414 "%debug", "%source_extension" and "%header_extension".
4417 Automatic location tracking.
4420 * Noteworthy changes in release 1.28 (1999-07-06)
4422 ** Should compile better now with K&R compilers.
4426 ** Fixed a problem with escaping the double quote character.
4428 ** There is now a FAQ.
4431 * Noteworthy changes in release 1.27
4433 ** The make rule which prevented bison.simple from being created on
4434 some systems has been fixed.
4437 * Noteworthy changes in release 1.26
4439 ** Bison now uses Automake.
4441 ** New mailing lists: <bug-bison@gnu.org> and <help-bison@gnu.org>.
4443 ** Token numbers now start at 257 as previously documented, not 258.
4445 ** Bison honors the TMPDIR environment variable.
4447 ** A couple of buffer overruns have been fixed.
4449 ** Problems when closing files should now be reported.
4451 ** Generated parsers should now work even on operating systems which do
4452 not provide alloca().
4455 * Noteworthy changes in release 1.25 (1995-10-16)
4457 ** Errors in the input grammar are not fatal; Bison keeps reading
4458 the grammar file, and reports all the errors found in it.
4460 ** Tokens can now be specified as multiple-character strings: for
4461 example, you could use "<=" for a token which looks like <=, instead
4462 of choosing a name like LESSEQ.
4464 ** The %token_table declaration says to write a table of tokens (names
4465 and numbers) into the parser file. The yylex function can use this
4466 table to recognize multiple-character string tokens, or for other
4469 ** The %no_lines declaration says not to generate any #line preprocessor
4470 directives in the parser file.
4472 ** The %raw declaration says to use internal Bison token numbers, not
4473 Yacc-compatible token numbers, when token names are defined as macros.
4475 ** The --no-parser option produces the parser tables without including
4476 the parser engine; a project can now use its own parser engine.
4477 The actions go into a separate file called NAME.act, in the form of
4478 a switch statement body.
4481 * Noteworthy changes in release 1.23
4483 The user can define YYPARSE_PARAM as the name of an argument to be
4484 passed into yyparse. The argument should have type void *. It should
4485 actually point to an object. Grammar actions can access the variable
4486 by casting it to the proper pointer type.
4488 Line numbers in output file corrected.
4491 * Noteworthy changes in release 1.22
4493 --help option added.
4496 * Noteworthy changes in release 1.20
4498 Output file does not redefine const for C++.
4502 LocalWords: yacc YYBACKUP glr GCC lalr ArrayIndexOutOfBoundsException nullptr
4503 LocalWords: cplusplus liby rpl fprintf mfcalc Wyacc stmt cond expr mk sym lr
4504 LocalWords: IELR ielr Lookahead YYERROR nonassoc LALR's api lookaheads yychar
4505 LocalWords: destructor lookahead YYRHSLOC YYLLOC Rhs ifndef YYFAIL cpp sr rr
4506 LocalWords: preprocessor initializer Wno Wnone Werror FreeBSD prec livelocks
4507 LocalWords: Solaris AIX UX RHEL Tru LHS gcc's Wundef YYENABLE NLS YYLTYPE VCG
4508 LocalWords: yyerror cpp's Wunused yylval yylloc prepend yyparse yylex yypush
4509 LocalWords: Graphviz xml nonterminals midrule destructor's YYSTYPE typedef ly
4510 LocalWords: CHR chr printf stdout namespace preprocessing enum pre include's
4511 LocalWords: YYRECOVERING nonfree destructors YYABORT YYACCEPT params enums de
4512 LocalWords: struct yystype DJGPP lex param Haible NUM alloca YYSTACK NUL goto
4513 LocalWords: YYMAXDEPTH Unescaped UCNs YYLTYPE's yyltype typedefs inline Yaccs
4514 LocalWords: Heriyanto Reenable dprec Hilfinger Eggert MYEOF Folle Menezes EOF
4515 LocalWords: Lackovic define's itemset Groff Gettext malloc NEWS'ed YYDEBUG YY
4516 LocalWords: namespaces strerror const autoconfiguration Dconst Autoconf's FDL
4517 LocalWords: Automake TMPDIR LESSEQ ylwrap endif yydebug YYTOKEN YYLSP ival hh
4518 LocalWords: extern YYTOKENTYPE TOKENTYPE yytokentype tokentype STYPE lval pdf
4519 LocalWords: lang yyoutput dvi html ps POSIX lvalp llocp Wother nterm arg init
4520 LocalWords: TOK calc yyo fval Wconflicts parsers yystackp yyval yynerrs
4521 LocalWords: Théophile Ranquet Santet fno fnone stype associativity Tolmer
4522 LocalWords: Wprecedence Rassoul Wempty Paolo Bonzini parser's Michiel loc
4523 LocalWords: redeclaration sval fcaret reentrant XSLT xsl Wmaybe yyvsp Tedi
4524 LocalWords: pragmas noreturn untyped Rozenman unexpanded Wojciech Polak
4525 LocalWords: Alexandre MERCHANTABILITY yytype emplace ptr automove lvalues
4526 LocalWords: nonterminal yy args Pragma dereference yyformat rhs docdir bw
4527 LocalWords: Redeclarations rpcalc Autoconf YFLAGS Makefiles PROG DECL num
4528 LocalWords: Heimbigner AST src ast Makefile srcdir MinGW xxlex XXSTYPE
4529 LocalWords: XXLTYPE strictfp IDEs ffixit fdiagnostics parseable fixits
4530 LocalWords: Wdeprecated yytext Variadic variadic yyrhs yyphrs RCS README
4531 LocalWords: noexcept constexpr ispell american deprecations backend Teoh
4532 LocalWords: YYPRINT Mangold Bonzini's Wdangling exVal baz checkable gcc
4533 LocalWords: fsanitize Vogelsgesang lis redeclared stdint automata yytname
4534 LocalWords: yysymbol yytnamerr yyreport ctx ARGMAX yysyntax stderr LPAREN
4535 LocalWords: symrec yypcontext TOKENMAX yyexpected YYEMPTY yypstate YYEOF
4536 LocalWords: autocompletion bistromathic submessages Cayuela lexcalc hoc
4537 LocalWords: yytoken YYUNDEF YYerror basename Automake's UTF ifdef ffile
4538 LocalWords: gotos readline Imbimbo Wcounterexamples Wcex Nonunifying rcex
4541 ispell-dictionary: "american"
4546 Copyright (C) 1995-2015, 2018-2020 Free Software Foundation, Inc.
4548 This file is part of Bison, the GNU Parser Generator.
4550 Permission is granted to copy, distribute and/or modify this document
4551 under the terms of the GNU Free Documentation License, Version 1.3 or
4552 any later version published by the Free Software Foundation; with no
4553 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
4554 Texts. A copy of the license is included in the "GNU Free
4555 Documentation License" file as part of this distribution.