3 * Noteworthy changes in release ?.? (????-??-??) [?]
5 ** Backward incompatible changes
7 Lone carriage-return characters (aka \r or ^M) in the grammar files are no
8 longer treated as end-of-lines. This changes the diagnostics, and in
9 particular their locations.
11 Line numbers and columns are now represented as 'int' not 'unsigned',
12 so that integer overflow on positions is easily checkable via 'gcc
13 -fsanitize=undefined' and the like. This affects the API for positions.
17 In Java, %define api.prefix was ignored. It now behaves as expected.
21 *** Lookahead correction in C++
23 Contributed by Adrian Vogelsgesang.
25 The C++ deterministic skeleton (lalr1.cc) now supports LAC, via the
26 %define variable parse.lac.
28 *** Variable api.token.raw: Optimized token numbers (all skeletons)
30 In the generated parsers, tokens have two numbers: the "external" token
31 number as returned by yylex (which starts at 257), and the "internal"
32 symbol number (which starts at 3). Each time yylex is called, a table
33 lookup maps the external token number to the internal symbol number.
35 When the %define variable api.token.raw is set, tokens are assigned their
36 internal number, which saves one table lookup per token, and also saves
37 the generation of the mapping table.
39 The gain is typically moderate, but in extreme cases (very simple user
40 actions), a 10% improvement can be observed.
42 *** Diagnostics with insertion
44 The diagnostics now display suggestion below the underlined source.
45 Replacement for undeclared symbols are now also suggested.
52 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'?
56 foo.y:2.16: warning: empty rule without %empty [-Wempty-rule]
60 foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
62 *** Diagnostics about long lines
64 Quoted sources may now be truncated to fit the screen. For instance, on a
65 30-column wide terminal:
72 foo.y:1.34-36: warning: symbol FOO redeclared [-Wother]
75 foo.y:1.8-10: previous declaration
78 foo.y:1.62-64: warning: symbol FOO redeclared [-Wother]
81 foo.y:1.8-10: previous declaration
85 *** Debug traces in Java
87 The Java backend no longer emits code and data for parser tracing if the
88 %define variable parse.trace is not defined.
90 *** Generated parsers prefer signed integer types
92 Bison skeletons now prefer signed to unsigned integer types when either
93 will do, as the signed types are less error-prone and allow for better
94 checking with 'gcc -fsanitize=undefined'. Also, the types chosen are now
95 portable to unusual machines where char, short and int are all the same
96 width. On non-GNU platforms this may entail including <limits.h> and (if
97 available) <stdint.h> to define integer types and constants.
99 *** Generated parsers use better types for states
101 Stacks now use the best integral type for state numbers, instead of always
102 using 15 bits. As a result "small" parsers now have a smaller memory
103 footprint (they use 8 bits), and there is support for large automata (16
104 bits), and extra large (using int, i.e., typically 31 bits).
106 * Noteworthy changes in release 3.4.2 (2019-09-12) [stable]
110 In some cases, when warnings are disabled, bison could emit tons of white
111 spaces as diagnostics.
113 When running out of memory, bison could crash (found by fuzzing).
115 When defining twice the EOF token, bison would crash.
117 New warnings from recent compilers have been addressed in the generated
118 parsers (yacc.c, glr.c, glr.cc).
120 When lone carriage-return characters appeared in the input file,
121 diagnostics could hang forever.
123 * Noteworthy changes in release 3.4.1 (2019-05-22) [stable]
129 * Noteworthy changes in release 3.4 (2019-05-19) [stable]
131 ** Deprecated features
133 The %pure-parser directive is deprecated in favor of '%define api.pure'
134 since Bison 2.3b (2008-05-27), but no warning was issued; there is one
135 now. Note that since Bison 2.7 you are strongly encouraged to use
136 '%define api.pure full' instead of '%define api.pure'.
140 *** Colored diagnostics
142 As an experimental feature, diagnostics are now colored, controlled by the
143 new options --color and --style.
145 To use them, install the libtextstyle library before configuring Bison.
148 https://alpha.gnu.org/gnu/gettext/
152 https://alpha.gnu.org/gnu/gettext/libtextstyle-0.8.tar.gz
154 The option --color supports the following arguments:
155 - always, yes: Enable colors.
156 - never, no: Disable colors.
157 - auto, tty (default): Enable colors if the output device is a tty.
159 To customize the styles, create a CSS file similar to
163 .error { font-weight: 800; text-decoration: underline; }
166 then invoke bison with --style=bison-bw.css, or set the BISON_STYLE
167 environment variable to "bison-bw.css".
171 When given -fsyntax-only, the diagnostics are reported, but no output is
174 The name of this option is somewhat misleading as bison does more than
175 just checking the syntax: every stage is run (including checking for
176 conflicts for instance), except the generation of the output files.
178 *** Include the generated header (yacc.c)
180 Before, when --defines is used, bison generated a header, and pasted an
181 exact copy of it into the generated parser implementation file. If the
182 header name is not "y.tab.h", it is now #included instead of being
185 To use an '#include' even if the header name is "y.tab.h" (which is what
186 happens with --yacc, or when using the Autotools' ylwrap), define
187 api.header.include to the exact argument to pass to #include. For
190 %define api.header.include {"parse.h"}
194 %define api.header.include {<parser/parse.h>}
196 *** api.location.type is now supported in C (yacc.c, glr.c)
198 The %define variable api.location.type defines the name of the type to use
199 for locations. When defined, Bison no longer defines YYLTYPE.
201 This can be used in programs with several parsers to factor their
202 definition of locations: let one of them generate them, and the others
209 In conformance with the recommendations of the Graphviz team, if %require
210 "3.4" (or better) is specified, the option --graph generates a *.gv file
211 by default, instead of *.dot.
213 *** Diagnostics overhaul
215 Column numbers were wrong with multibyte characters, which would also
216 result in skewed diagnostics with carets. Beside, because we were
217 indenting the quoted source with a single space, lines with tab characters
218 were incorrectly underlined.
220 To address these issues, and to be clearer, Bison now issues diagnostics
221 as GCC9 does. For instance it used to display (there's a tab before the
224 foo.y:3.37-38: error: $2 of ‘expr’ has no declared type
225 expr: expr '+' "number" { $$ = $1 + $2; }
229 foo.y:3.37-38: error: $2 of ‘expr’ has no declared type
230 3 | expr: expr '+' "number" { $$ = $1 + $2; }
233 Other constructs now also have better locations, resulting in more precise
236 *** Fix-it hints for %empty
238 Running Bison with -Wempty-rules and --update will remove incorrect %empty
239 annotations, and add the missing ones.
241 *** Generated reports
243 The format of the reports (parse.output) was improved for readability.
245 *** Better support for --no-line.
247 When --no-line is used, the generated files are now cleaner: no lines are
248 generated instead of empty lines. Together with using api.header.include,
249 that should help people saving the generated files into version control
250 systems get smaller diffs.
254 A new example in C shows an simple infix calculator with a hand-written
255 scanner (examples/c/calc).
257 A new example in C shows a reentrant parser (capable of recursive calls)
258 built with Flex and Bison (examples/c/reccalc).
260 There is a new section about the history of Yaccs and Bison.
264 A few obscure bugs were fixed, including the second oldest (known) bug in
265 Bison: it was there when Bison was entered in the RCS version control
266 system, in December 1987. See the NEWS of Bison 3.3 for the previous
269 * Noteworthy changes in release 3.3.2 (2019-02-03) [stable]
273 Bison 3.3 failed to generate parsers for grammars with unused nonterminal
276 * Noteworthy changes in release 3.3.1 (2019-01-27) [stable]
280 The option -y/--yacc used to imply -Werror=yacc, which turns uses of Bison
281 extensions into errors. It now makes them simple warnings (-Wyacc).
283 * Noteworthy changes in release 3.3 (2019-01-26) [stable]
285 A new mailing list was created, Bison Announce. It is low traffic, and is
286 only about announcing new releases and important messages (e.g., polls
287 about major decisions to make).
289 https://lists.gnu.org/mailman/listinfo/bison-announce
291 ** Backward incompatible changes
293 Support for DJGPP, which has been unmaintained and untested for years, is
296 ** Deprecated features
298 A new feature, --update (see below) helps adjusting existing grammars to
301 *** Deprecated directives
303 The %error-verbose directive is deprecated in favor of '%define
304 parse.error verbose' since Bison 3.0, but no warning was issued.
306 The '%name-prefix "xx"' directive is deprecated in favor of '%define
307 api.prefix {xx}' since Bison 3.0, but no warning was issued. These
308 directives are slightly different, you might need to adjust your code.
309 %name-prefix renames only symbols with external linkage, while api.prefix
310 also renames types and macros, including YYDEBUG, YYTOKENTYPE,
311 yytokentype, YYSTYPE, YYLTYPE, etc.
313 Users of Flex that move from '%name-prefix "xx"' to '%define api.prefix
314 {xx}' will typically have to update YY_DECL from
316 #define YY_DECL int xxlex (YYSTYPE *yylval, YYLTYPE *yylloc)
320 #define YY_DECL int xxlex (XXSTYPE *yylval, XXLTYPE *yylloc)
322 *** Deprecated %define variable names
324 The following variables, mostly related to parsers in Java, have been
325 renamed for consistency. Backward compatibility is ensured, but upgrading
328 abstract -> api.parser.abstract
329 annotations -> api.parser.annotations
330 extends -> api.parser.extends
331 final -> api.parser.final
332 implements -> api.parser.implements
333 parser_class_name -> api.parser.class
334 public -> api.parser.public
335 strictfp -> api.parser.strictfp
339 *** Generation of fix-its for IDEs/Editors
341 When given the new option -ffixit (aka -fdiagnostics-parseable-fixits),
342 bison now generates machine readable editing instructions to fix some
343 issues. Currently, this is mostly limited to updating deprecated
344 directives and removing duplicates. For instance:
348 %define parser_class_name "Parser"
349 %define api.parser.class "Parser"
353 See the "fix-it:" lines below:
355 $ bison -ffixit foo.y
356 foo.y:1.1-14: warning: deprecated directive, use '%define parse.error verbose' [-Wdeprecated]
359 fix-it:"foo.y":{1:1-1:15}:"%define parse.error verbose"
360 foo.y:2.1-34: warning: deprecated directive, use '%define api.parser.class {Parser}' [-Wdeprecated]
361 %define parser_class_name "Parser"
362 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
363 fix-it:"foo.y":{2:1-2:35}:"%define api.parser.class {Parser}"
364 foo.y:3.1-33: error: %define variable 'api.parser.class' redefined
365 %define api.parser.class "Parser"
366 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
367 foo.y:2.1-34: previous definition
368 %define parser_class_name "Parser"
369 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
370 fix-it:"foo.y":{3:1-3:34}:""
371 foo.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
373 This uses the same output format as GCC and Clang.
375 *** Updating grammar files
377 Fixes can be applied on the fly. The previous example ends with the
378 suggestion to re-run bison with the option -u/--update, which results in a
379 cleaner grammar file.
381 $ bison --update foo.y
383 bison: file 'foo.y' was updated (backup: 'foo.y~')
386 %define parse.error verbose
387 %define api.parser.class {Parser}
391 *** Bison is now relocatable
393 If you pass '--enable-relocatable' to 'configure', Bison is relocatable.
395 A relocatable program can be moved or copied to a different location on
396 the file system. It can also be used through mount points for network
397 sharing. It is possible to make symbolic links to the installed and moved
398 programs, and invoke them through the symbolic link.
400 *** %expect and %expect-rr modifiers on individual rules
402 One can now document (and check) which rules participate in shift/reduce
403 and reduce/reduce conflicts. This is particularly important GLR parsers,
404 where conflicts are a normal occurrence. For example,
420 | argument_list ',' expression
425 Looking at the output from -v, one can see that the shift-reduce conflict
426 here is due to the fact that the parser does not know whether to reduce
427 arguments to argument_list until it sees the token _after_ the following
428 ','. By marking the rule with %expect 1 (because there is a conflict in
429 one state), we document the source of the 1 overall shift-reduce conflict.
431 In GLR parsers, we can use %expect-rr in a rule for reduce/reduce
432 conflicts. In this case, we mark each of the conflicting rules. For
441 target_list '=' expr ';'
447 | target ',' target_list
464 In a statement such as
468 the parser must reduce x to a target or an expr, but does not know which
469 until it sees the '='. So we notate the two possible reductions to
470 indicate that each conflicts in one rule.
472 This feature needs user feedback, and might evolve in the future.
474 *** C++: Actual token constructors
476 When variants and token constructors are enabled, in addition to the
477 type-safe named token constructors (make_ID, make_INT, etc.), we now
478 generate genuine constructors for symbol_type.
480 For instance with these declarations
486 you may use these constructors:
488 symbol_type (int token, const std::string&);
489 symbol_type (int token, const int&);
490 symbol_type (int token);
492 Correct matching between token types and value types is checked via
493 'assert'; for instance, 'symbol_type (ID, 42)' would abort. Named
494 constructors are preferable, as they offer better type safety (for
495 instance 'make_ID (42)' would not even compile), but symbol_type
496 constructors may help when token types are discovered at run-time, e.g.,
499 if (auto i = lookup_keyword (yytext))
500 return yy::parser::symbol_type (i);
502 return yy::parser::make_ID (yytext);
505 *** C++: Variadic emplace
507 If your application requires C++11 and you don't use symbol constructors,
508 you may now use a variadic emplace for semantic values:
510 %define api.value.type variant
511 %token <std::pair<int, int>> PAIR
515 int yylex (parser::semantic_type *lvalp)
517 lvalp->emplace <std::pair<int, int>> (1, 2);
518 return parser::token::PAIR;
521 *** C++: Syntax error exceptions in GLR
523 The glr.cc skeleton now supports syntax_error exceptions thrown from user
524 actions, or from the scanner.
526 *** More POSIX Yacc compatibility warnings
528 More Bison specific directives are now reported with -y or -Wyacc. This
529 change was ready since the release of Bison 3.0 in September 2015. It was
530 delayed because Autoconf used to define YACC as `bison -y`, which resulted
531 in numerous warnings for Bison users that use the GNU Build System.
533 If you still experience that problem, either redefine YACC as `bison -o
534 y.tab.c`, or pass -Wno-yacc to Bison.
536 *** The tables yyrhs and yyphrs are back
538 Because no Bison skeleton uses them, these tables were removed (no longer
539 passed to the skeletons, not even computed) in 2008. However, some users
540 have expressed interest in being able to use them in their own skeletons.
544 *** Incorrect number of reduce-reduce conflicts
548 exp: "num" | "num" | "num"
550 bison used to report a single RR conflict, instead of two. This is now
551 fixed. This was the oldest (known) bug in Bison: it was there when Bison
552 was entered in the RCS version control system, in December 1987.
554 Some grammar files might have to adjust their %expect-rr.
556 *** Parser directives that were not careful enough
558 Passing invalid arguments to %nterm, for instance character literals, used
559 to result in unclear error messages.
563 The examples/ directory (installed in .../share/doc/bison/examples) has
564 been restructured per language for clarity. The examples come with a
565 README and a Makefile. Not only can they be used to toy with Bison, they
566 can also be starting points for your own grammars.
568 There is now a Java example, and a simple example in C based on Flex and
569 Bison (examples/c/lexcalc/).
575 They now use noexcept and constexpr. Please, report missing annotations.
577 *** Symbol Declarations
579 The syntax of the variation directives to declare symbols was overhauled
580 for more consistency, and also better POSIX Yacc compliance (which, for
581 instance, allows "%type" without actually providing a type). The %nterm
582 directive, supported by Bison since its inception, is now documented and
583 officially supported.
585 The syntax is now as follows:
587 %token TAG? ( ID NUMBER? STRING? )+ ( TAG ( ID NUMBER? STRING? )+ )*
588 %left TAG? ( ID NUMBER? )+ ( TAG ( ID NUMBER? )+ )*
589 %type TAG? ( ID | CHAR | STRING )+ ( TAG ( ID | CHAR | STRING )+ )*
590 %nterm TAG? ID+ ( TAG ID+ )*
592 where TAG denotes a type tag such as ‘<ival>’, ID denotes an identifier
593 such as ‘NUM’, NUMBER a decimal or hexadecimal integer such as ‘300’ or
594 ‘0x12d’, CHAR a character literal such as ‘'+'’, and STRING a string
595 literal such as ‘"number"’. The post-fix quantifiers are ‘?’ (zero or
596 one), ‘*’ (zero or more) and ‘+’ (one or more).
598 * Noteworthy changes in release 3.2.4 (2018-12-24) [stable]
602 Fix the move constructor of symbol_type.
604 Always provide a copy constructor for symbol_type, even in modern C++.
606 * Noteworthy changes in release 3.2.3 (2018-12-18) [stable]
610 Properly support token constructors in C++ with types that include commas
611 (e.g., std::pair<int, int>). A regression introduced in Bison 3.2.
613 * Noteworthy changes in release 3.2.2 (2018-11-21) [stable]
617 C++ portability issues.
619 * Noteworthy changes in release 3.2.1 (2018-11-09) [stable]
623 Several portability issues have been fixed in the build system, in the
624 test suite, and in the generated parsers in C++.
626 * Noteworthy changes in release 3.2 (2018-10-29) [stable]
628 ** Backward incompatible changes
630 Support for DJGPP, which has been unmaintained and untested for years, is
631 obsolete. Unless there is activity to revive it, it will be removed.
635 %printers should use yyo rather than yyoutput to denote the output stream.
637 Variant-based symbols in C++ should use emplace() rather than build().
639 In C++ parsers, parser::operator() is now a synonym for the parser::parse.
643 A new section, "A Simple C++ Example", is a tutorial for parsers in C++.
645 A comment in the generated code now emphasizes that users should not
646 depend upon non-documented implementation details, such as macros starting
651 *** C++: Support for move semantics (lalr1.cc)
653 The lalr1.cc skeleton now fully supports C++ move semantics, while
654 maintaining compatibility with C++98. You may now store move-only types
655 when using Bison's variants. For instance:
663 %define api.value.type variant
667 %token <int> INT "int";
668 %type <std::unique_ptr<int>> int;
669 %type <std::vector<std::unique_ptr<int>>> list;
673 | list int { $$ = std::move($1); $$.emplace_back(std::move($2)); }
675 int: "int" { $$ = std::make_unique<int>($1); }
677 *** C++: Implicit move of right-hand side values (lalr1.cc)
679 In modern C++ (C++11 and later), you should always use 'std::move' with
680 the values of the right-hand side symbols ($1, $2, etc.), as they will be
681 popped from the stack anyway. Using 'std::move' is mandatory for
682 move-only types such as unique_ptr, and it provides a significant speedup
683 for large types such as std::string, or std::vector, etc.
685 If '%define api.value.automove' is set, every occurrence '$n' is replaced
686 by 'std::move ($n)'. The second rule in the previous grammar can be
689 list: list int { $$ = $1; $$.emplace_back($2); }
691 With automove enabled, the semantic values are no longer lvalues, so do
692 not use the swap idiom:
694 list: list int { std::swap($$, $1); $$.emplace_back($2); }
696 This idiom is anyway obsolete: it is preferable to move than to swap.
698 A warning is issued when automove is enabled, and a value is used several
701 input.yy:16.31-32: warning: multiple occurrences of $2 with api.value.automove enabled [-Wother]
702 exp: "twice" exp { $$ = $2 + $2; }
705 Enabling api.value.automove does not require support for modern C++. The
706 generated code is valid C++98/03, but will use copies instead of moves.
708 The new examples/c++/variant-11.yy shows these features in action.
710 *** C++: The implicit default semantic action is always run
712 When variants are enabled, the default action was not run, so
720 It now behaves like in all the other cases, as
722 exp: "number" { $$ = $1; }
724 possibly using std::move if automove is enabled.
726 We do not expect backward compatibility issues. However, beware of
727 forward compatibility issues: if you rely on default actions with
728 variants, be sure to '%require "3.2"' to avoid older versions of Bison to
729 generate incorrect parsers.
731 *** C++: Renaming location.hh
733 When both %defines and %locations are enabled, Bison generates a
734 location.hh file. If you don't use locations outside of the parser, you
735 may avoid its creation with:
737 %define api.location.file none
739 However this file is useful if, for instance, your parser builds an AST
740 decorated with locations: you may use Bison's location independently of
741 Bison's parser. You can now give it another name, for instance:
743 %define api.location.file "my-location.hh"
745 This name can have directory components, and even be absolute. The name
746 under which the location file is included is controlled by
747 api.location.include.
749 This way it is possible to have several parsers share the same location
752 For instance, in src/foo/parser.hh, generate the include/ast/loc.hh file:
755 %define api.namespace {foo}
756 %define api.location.file "include/ast/loc.hh"
757 %define api.location.include {<ast/loc.hh>}
759 and use it in src/bar/parser.hh:
762 %define api.namespace {bar}
763 %code requires {#include <ast/loc.hh>}
764 %define api.location.type {bar::location}
766 Absolute file names are supported, so in your Makefile, passing the flag
767 -Dapi.location.file='"$(top_srcdir)/include/ast/location.hh"' to bison is
770 *** C++: stack.hh and position.hh are deprecated
772 When asked to generate a header file (%defines), the lalr1.cc skeleton
773 generates a stack.hh file. This file had no interest for users; it is now
774 made useless: its content is included in the parser definition. It is
775 still generated for backward compatibility.
777 When in addition to %defines, location support is requested (%locations),
778 the file position.hh is also generated. It is now also useless: its
779 content is now included in location.hh.
781 These files are no longer generated when your grammar file requires at
782 least Bison 3.2 (%require "3.2").
786 Portability issues on MinGW and VS2015.
788 Portability issues in the test suite.
790 Portability/warning issues with Flex.
792 * Noteworthy changes in release 3.1 (2018-08-27) [stable]
794 ** Backward incompatible changes
796 Compiling Bison now requires a C99 compiler---as announced during the
797 release of Bison 3.0, five years ago. Generated parsers do not require a
800 Support for DJGPP, which has been unmaintained and untested for years, is
801 obsolete. Unless there is activity to revive it, the next release of Bison
802 will have it removed.
806 *** Typed midrule actions
808 Because their type is unknown to Bison, the values of midrule actions are
809 not treated like the others: they don't have %printer and %destructor
810 support. It also prevents C++ (Bison) variants to handle them properly.
812 Typed midrule actions address these issues. Instead of:
814 exp: { $<ival>$ = 1; } { $<ival>$ = 2; } { $$ = $<ival>1 + $<ival>2; }
818 exp: <ival>{ $$ = 1; } <ival>{ $$ = 2; } { $$ = $1 + $2; }
820 *** Reports include the type of the symbols
822 The sections about terminal and nonterminal symbols of the '*.output' file
823 now specify their declared type. For instance, for:
827 the report now shows '<ival>':
829 Terminals, with rules where they appear
833 *** Diagnostics about useless rules
835 In the following grammar, the 'exp' nonterminal is trivially useless. So,
836 of course, its rules are useless too.
840 exp: exp '+' exp | exp '-' exp | '(' exp ')'
842 Previously all the useless rules were reported, including those whose
843 left-hand side is the 'exp' nonterminal:
845 warning: 1 nonterminal useless in grammar [-Wother]
846 warning: 4 rules useless in grammar [-Wother]
847 2.14-16: warning: nonterminal useless in grammar: exp [-Wother]
850 2.14-16: warning: rule useless in grammar [-Wother]
853 3.6-16: warning: rule useless in grammar [-Wother]
854 exp: exp '+' exp | exp '-' exp | '(' exp ')'
856 3.20-30: warning: rule useless in grammar [-Wother]
857 exp: exp '+' exp | exp '-' exp | '(' exp ')'
859 3.34-44: warning: rule useless in grammar [-Wother]
860 exp: exp '+' exp | exp '-' exp | '(' exp ')'
863 Now, rules whose left-hand side symbol is useless are no longer reported
864 as useless. The locations of the errors have also been adjusted to point
865 to the first use of the nonterminal as a left-hand side of a rule:
867 warning: 1 nonterminal useless in grammar [-Wother]
868 warning: 4 rules useless in grammar [-Wother]
869 3.1-3: warning: nonterminal useless in grammar: exp [-Wother]
870 exp: exp '+' exp | exp '-' exp | '(' exp ')'
872 2.14-16: warning: rule useless in grammar [-Wother]
876 *** C++: Generated parsers can be compiled with -fno-exceptions (lalr1.cc)
878 When compiled with exceptions disabled, the generated parsers no longer
879 uses try/catch clauses.
881 Currently only GCC and Clang are supported.
885 *** A demonstration of variants
887 A new example was added (installed in .../share/doc/bison/examples),
888 'variant.yy', which shows how to use (Bison) variants in C++.
890 The other examples were made nicer to read.
892 *** Some features are no longer 'experimental'
894 The following features, mature enough, are no longer flagged as
895 experimental in the documentation: push parsers, default %printer and
896 %destructor (typed: <*> and untyped: <>), %define api.value.type union and
897 variant, Java parsers, XML output, LR family (lr, ielr, lalr), and
898 semantic predicates (%?).
902 *** GLR: Predicates support broken by #line directives
904 Predicates (%?) in GLR such as
907 %? {new_syntax} 'w' id new_args
908 | %?{!new_syntax} 'w' id old_args
910 were issued with #lines in the middle of C code.
912 *** Printer and destructor with broken #line directives
914 The #line directives were not properly escaped when emitting the code for
915 %printer/%destructor, which resulted in compiler errors if there are
916 backslashes or double-quotes in the grammar file name.
918 *** Portability on ICC
920 The Intel compiler claims compatibility with GCC, yet rejects its _Pragma.
921 Generated parsers now work around this.
925 There were several small fixes in the test suite and in the build system,
926 many warnings in bison and in the generated parsers were eliminated. The
927 documentation also received its share of minor improvements.
929 Useless code was removed from C++ parsers, and some of the generated
930 constructors are more 'natural'.
932 * Noteworthy changes in release 3.0.5 (2018-05-27) [stable]
936 *** C++: Fix support of 'syntax_error'
938 One incorrect 'inline' resulted in linking errors about the constructor of
939 the syntax_error exception.
941 *** C++: Fix warnings
943 GCC 7.3 (with -O1 or -O2 but not -O0 or -O3) issued null-dereference
944 warnings about yyformat being possibly null. It also warned about the
945 deprecated implicit definition of copy constructors when there's a
946 user-defined (copy) assignment operator.
948 *** Location of errors
950 In C++ parsers, out-of-bounds errors can happen when a rule with an empty
951 ride-hand side raises a syntax error. The behavior of the default parser
952 (yacc.c) in such a condition was undefined.
954 Now all the parsers match the behavior of glr.c: @$ is used as the
955 location of the error. This handles gracefully rules with and without
958 *** Portability fixes in the test suite
960 On some platforms, some Java and/or C++ tests were failing.
962 * Noteworthy changes in release 3.0.4 (2015-01-23) [stable]
966 *** C++ with Variants (lalr1.cc)
968 Fix a compiler warning when no %destructor use $$.
972 Several portability issues in tests were fixed.
974 * Noteworthy changes in release 3.0.3 (2015-01-15) [stable]
978 *** C++ with Variants (lalr1.cc)
980 Problems with %destructor and '%define parse.assert' have been fixed.
982 *** Named %union support (yacc.c, glr.c)
984 Bison 3.0 introduced a regression on named %union such as
986 %union foo { int ival; };
988 The possibility to use a name was introduced "for Yacc compatibility".
989 It is however not required by POSIX Yacc, and its usefulness is not clear.
991 *** %define api.value.type union with %defines (yacc.c, glr.c)
993 The C parsers were broken when %defines was used together with "%define
994 api.value.type union".
996 *** Redeclarations are reported in proper order
1004 bison used to report:
1006 foo.yy:2.10-11: error: %printer redeclaration for FOO
1009 foo.yy:3.10-11: previous declaration
1013 Now, the "previous" declaration is always the first one.
1018 Bison now installs various files in its docdir (which defaults to
1019 '/usr/local/share/doc/bison'), including the three fully blown examples
1020 extracted from the documentation:
1023 Reverse Polish Calculator, a simple introductory example.
1025 Multi-function Calc, a calculator with memory and functions and located
1028 a calculator in C++ using variant support and token constructors.
1030 * Noteworthy changes in release 3.0.2 (2013-12-05) [stable]
1034 *** Generated source files when errors are reported
1036 When warnings are issued and -Werror is set, bison would still generate
1037 the source files (*.c, *.h...). As a consequence, some runs of "make"
1038 could fail the first time, but not the second (as the files were generated
1041 This is fixed: bison no longer generates this source files, but, of
1042 course, still produces the various reports (*.output, *.xml, etc.).
1044 *** %empty is used in reports
1046 Empty right-hand sides are denoted by '%empty' in all the reports (text,
1047 dot, XML and formats derived from it).
1049 *** YYERROR and variants
1051 When C++ variant support is enabled, an error triggered via YYERROR, but
1052 not caught via error recovery, resulted in a double deletion.
1054 * Noteworthy changes in release 3.0.1 (2013-11-12) [stable]
1058 *** Errors in caret diagnostics
1060 On some platforms, some errors could result in endless diagnostics.
1062 *** Fixes of the -Werror option
1064 Options such as "-Werror -Wno-error=foo" were still turning "foo"
1065 diagnostics into errors instead of warnings. This is fixed.
1067 Actually, for consistency with GCC, "-Wno-error=foo -Werror" now also
1068 leaves "foo" diagnostics as warnings. Similarly, with "-Werror=foo
1069 -Wno-error", "foo" diagnostics are now errors.
1073 As demonstrated in the documentation, one can now leave spaces between
1078 The yacc.1 man page is no longer installed if --disable-yacc was
1081 *** Fixes in the test suite
1083 Bugs and portability issues.
1085 * Noteworthy changes in release 3.0 (2013-07-25) [stable]
1087 ** WARNING: Future backward-incompatibilities!
1089 Like other GNU packages, Bison will start using some of the C99 features
1090 for its own code, especially the definition of variables after statements.
1091 The generated C parsers still aim at C90.
1093 ** Backward incompatible changes
1095 *** Obsolete features
1097 Support for YYFAIL is removed (deprecated in Bison 2.4.2): use YYERROR.
1099 Support for yystype and yyltype is removed (deprecated in Bison 1.875):
1100 use YYSTYPE and YYLTYPE.
1102 Support for YYLEX_PARAM and YYPARSE_PARAM is removed (deprecated in Bison
1103 1.875): use %lex-param, %parse-param, or %param.
1105 Missing semicolons at the end of actions are no longer added (as announced
1106 in the release 2.5).
1108 *** Use of YACC='bison -y'
1110 TL;DR: With Autoconf <= 2.69, pass -Wno-yacc to (AM_)YFLAGS if you use
1113 Traditional Yacc generates 'y.tab.c' whatever the name of the input file.
1114 Therefore Makefiles written for Yacc expect 'y.tab.c' (and possibly
1115 'y.tab.h' and 'y.output') to be generated from 'foo.y'.
1117 To this end, for ages, AC_PROG_YACC, Autoconf's macro to look for an
1118 implementation of Yacc, was using Bison as 'bison -y'. While it does
1119 ensure compatible output file names, it also enables warnings for
1120 incompatibilities with POSIX Yacc. In other words, 'bison -y' triggers
1121 warnings for Bison extensions.
1123 Autoconf 2.70+ fixes this incompatibility by using YACC='bison -o y.tab.c'
1124 (which also generates 'y.tab.h' and 'y.output' when needed).
1125 Alternatively, disable Yacc warnings by passing '-Wno-yacc' to your Yacc
1126 flags (YFLAGS, or AM_YFLAGS with Automake).
1130 *** The epilogue is no longer affected by internal #defines (glr.c)
1132 The glr.c skeleton uses defines such as #define yylval (yystackp->yyval) in
1133 generated code. These weren't properly undefined before the inclusion of
1134 the user epilogue, so functions such as the following were butchered by the
1135 preprocessor expansion:
1137 int yylex (YYSTYPE *yylval);
1139 This is fixed: yylval, yynerrs, yychar, and yylloc are now valid
1140 identifiers for user-provided variables.
1142 *** stdio.h is no longer needed when locations are enabled (yacc.c)
1144 Changes in Bison 2.7 introduced a dependency on FILE and fprintf when
1145 locations are enabled. This is fixed.
1147 *** Warnings about useless %pure-parser/%define api.pure are restored
1149 ** Diagnostics reported by Bison
1151 Most of these features were contributed by Théophile Ranquet and Victor
1156 Version 2.7 introduced caret errors, for a prettier output. These are now
1157 activated by default. The old format can still be used by invoking Bison
1158 with -fno-caret (or -fnone).
1160 Some error messages that reproduced excerpts of the grammar are now using
1161 the caret information only. For instance on:
1168 in.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
1169 in.y:2.12-14: warning: rule useless in parser due to conflicts: exp: 'a' [-Wother]
1173 in.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
1174 in.y:2.12-14: warning: rule useless in parser due to conflicts [-Wother]
1178 and "bison -fno-caret" reports:
1180 in.y: warning: 1 reduce/reduce conflict [-Wconflicts-rr]
1181 in.y:2.12-14: warning: rule useless in parser due to conflicts [-Wother]
1183 *** Enhancements of the -Werror option
1185 The -Werror=CATEGORY option is now recognized, and will treat specified
1186 warnings as errors. The warnings need not have been explicitly activated
1187 using the -W option, this is similar to what GCC 4.7 does.
1189 For example, given the following command line, Bison will treat both
1190 warnings related to POSIX Yacc incompatibilities and S/R conflicts as
1191 errors (and only those):
1193 $ bison -Werror=yacc,error=conflicts-sr input.y
1195 If no categories are specified, -Werror will make all active warnings into
1196 errors. For example, the following line does the same the previous example:
1198 $ bison -Werror -Wnone -Wyacc -Wconflicts-sr input.y
1200 (By default -Wconflicts-sr,conflicts-rr,deprecated,other is enabled.)
1202 Note that the categories in this -Werror option may not be prefixed with
1203 "no-". However, -Wno-error[=CATEGORY] is valid.
1205 Note that -y enables -Werror=yacc. Therefore it is now possible to require
1206 Yacc-like behavior (e.g., always generate y.tab.c), but to report
1207 incompatibilities as warnings: "-y -Wno-error=yacc".
1209 *** The display of warnings is now richer
1211 The option that controls a given warning is now displayed:
1213 foo.y:4.6: warning: type clash on default action: <foo> != <bar> [-Wother]
1215 In the case of warnings treated as errors, the prefix is changed from
1216 "warning: " to "error: ", and the suffix is displayed, in a manner similar
1217 to GCC, as [-Werror=CATEGORY].
1219 For instance, where the previous version of Bison would report (and exit
1222 bison: warnings being treated as errors
1223 input.y:1.1: warning: stray ',' treated as white space
1227 input.y:1.1: error: stray ',' treated as white space [-Werror=other]
1229 *** Deprecated constructs
1231 The new 'deprecated' warning category flags obsolete constructs whose
1232 support will be discontinued. It is enabled by default. These warnings
1233 used to be reported as 'other' warnings.
1235 *** Useless semantic types
1237 Bison now warns about useless (uninhabited) semantic types. Since
1238 semantic types are not declared to Bison (they are defined in the opaque
1239 %union structure), it is %printer/%destructor directives about useless
1240 types that trigger the warning:
1244 %printer {} <type1> <type3>
1245 %destructor {} <type2> <type4>
1247 nterm: term { $$ = $1; };
1249 3.28-34: warning: type <type3> is used, but is not associated to any symbol
1250 4.28-34: warning: type <type4> is used, but is not associated to any symbol
1252 *** Undefined but unused symbols
1254 Bison used to raise an error for undefined symbols that are not used in
1255 the grammar. This is now only a warning.
1258 %destructor {} symbol2
1259 %type <type> symbol3
1263 *** Useless destructors or printers
1265 Bison now warns about useless destructors or printers. In the following
1266 example, the printer for <type1>, and the destructor for <type2> are
1267 useless: all symbols of <type1> (token1) already have a printer, and all
1268 symbols of type <type2> (token2) already have a destructor.
1270 %token <type1> token1
1274 %printer {} token1 <type1> <type3>
1275 %destructor {} token2 <type2> <type4>
1279 The warnings and error messages about shift/reduce and reduce/reduce
1280 conflicts have been normalized. For instance on the following foo.y file:
1284 exp: exp '+' exp | '0' | '0';
1286 compare the previous version of bison:
1289 foo.y: conflicts: 1 shift/reduce, 2 reduce/reduce
1290 $ bison -Werror foo.y
1291 bison: warnings being treated as errors
1292 foo.y: conflicts: 1 shift/reduce, 2 reduce/reduce
1294 with the new behavior:
1297 foo.y: warning: 1 shift/reduce conflict [-Wconflicts-sr]
1298 foo.y: warning: 2 reduce/reduce conflicts [-Wconflicts-rr]
1299 $ bison -Werror foo.y
1300 foo.y: error: 1 shift/reduce conflict [-Werror=conflicts-sr]
1301 foo.y: error: 2 reduce/reduce conflicts [-Werror=conflicts-rr]
1303 When %expect or %expect-rr is used, such as with bar.y:
1308 exp: exp '+' exp | '0' | '0';
1313 bar.y: conflicts: 1 shift/reduce, 2 reduce/reduce
1314 bar.y: expected 0 shift/reduce conflicts
1315 bar.y: expected 0 reduce/reduce conflicts
1320 bar.y: error: shift/reduce conflicts: 1 found, 0 expected
1321 bar.y: error: reduce/reduce conflicts: 2 found, 0 expected
1323 ** Incompatibilities with POSIX Yacc
1325 The 'yacc' category is no longer part of '-Wall', enable it explicitly
1328 ** Additional yylex/yyparse arguments
1330 The new directive %param declares additional arguments to both yylex and
1331 yyparse. The %lex-param, %parse-param, and %param directives support one
1332 or more arguments. Instead of
1334 %lex-param {arg1_type *arg1}
1335 %lex-param {arg2_type *arg2}
1336 %parse-param {arg1_type *arg1}
1337 %parse-param {arg2_type *arg2}
1341 %param {arg1_type *arg1} {arg2_type *arg2}
1343 ** Types of values for %define variables
1345 Bison used to make no difference between '%define foo bar' and '%define
1346 foo "bar"'. The former is now called a 'keyword value', and the latter a
1347 'string value'. A third kind was added: 'code values', such as '%define
1350 Keyword variables are used for fixed value sets, e.g.,
1352 %define lr.type lalr
1354 Code variables are used for value in the target language, e.g.,
1356 %define api.value.type {struct semantic_type}
1358 String variables are used remaining cases, e.g. file names.
1360 ** Variable api.token.prefix
1362 The variable api.token.prefix changes the way tokens are identified in
1363 the generated files. This is especially useful to avoid collisions
1364 with identifiers in the target language. For instance
1366 %token FILE for ERROR
1367 %define api.token.prefix {TOK_}
1369 start: FILE for ERROR;
1371 will generate the definition of the symbols TOK_FILE, TOK_for, and
1372 TOK_ERROR in the generated sources. In particular, the scanner must
1373 use these prefixed token names, although the grammar itself still
1374 uses the short names (as in the sample rule given above).
1376 ** Variable api.value.type
1378 This new %define variable supersedes the #define macro YYSTYPE. The use
1379 of YYSTYPE is discouraged. In particular, #defining YYSTYPE *and* either
1380 using %union or %defining api.value.type results in undefined behavior.
1382 Either define api.value.type, or use "%union":
1389 %token <ival> INT "integer"
1390 %token <sval> STRING "string"
1391 %printer { fprintf (yyo, "%d", $$); } <ival>
1392 %destructor { free ($$); } <sval>
1395 yylval.ival = 42; return INT;
1396 yylval.sval = "42"; return STRING;
1398 The %define variable api.value.type supports both keyword and code values.
1400 The keyword value 'union' means that the user provides genuine types, not
1401 union member names such as "ival" and "sval" above (WARNING: will fail if
1402 -y/--yacc/%yacc is enabled).
1404 %define api.value.type union
1405 %token <int> INT "integer"
1406 %token <char *> STRING "string"
1407 %printer { fprintf (yyo, "%d", $$); } <int>
1408 %destructor { free ($$); } <char *>
1411 yylval.INT = 42; return INT;
1412 yylval.STRING = "42"; return STRING;
1414 The keyword value variant is somewhat equivalent, but for C++ special
1415 provision is made to allow classes to be used (more about this below).
1417 %define api.value.type variant
1418 %token <int> INT "integer"
1419 %token <std::string> STRING "string"
1421 Code values (in braces) denote user defined types. This is where YYSTYPE
1439 %define api.value.type {struct my_value}
1440 %token <u.ival> INT "integer"
1441 %token <u.sval> STRING "string"
1442 %printer { fprintf (yyo, "%d", $$); } <u.ival>
1443 %destructor { free ($$); } <u.sval>
1446 yylval.u.ival = 42; return INT;
1447 yylval.u.sval = "42"; return STRING;
1449 ** Variable parse.error
1451 This variable controls the verbosity of error messages. The use of the
1452 %error-verbose directive is deprecated in favor of "%define parse.error
1455 ** Renamed %define variables
1457 The following variables have been renamed for consistency. Backward
1458 compatibility is ensured, but upgrading is recommended.
1460 lr.default-reductions -> lr.default-reduction
1461 lr.keep-unreachable-states -> lr.keep-unreachable-state
1462 namespace -> api.namespace
1463 stype -> api.value.type
1465 ** Semantic predicates
1467 Contributed by Paul Hilfinger.
1469 The new, experimental, semantic-predicate feature allows actions of the
1470 form "%?{ BOOLEAN-EXPRESSION }", which cause syntax errors (as for
1471 YYERROR) if the expression evaluates to 0, and are evaluated immediately
1472 in GLR parsers, rather than being deferred. The result is that they allow
1473 the programmer to prune possible parses based on the values of run-time
1476 ** The directive %expect-rr is now an error in non GLR mode
1478 It used to be an error only if used in non GLR mode, _and_ if there are
1479 reduce/reduce conflicts.
1481 ** Tokens are numbered in their order of appearance
1483 Contributed by Valentin Tolmer.
1485 With '%token A B', A had a number less than the one of B. However,
1486 precedence declarations used to generate a reversed order. This is now
1487 fixed, and introducing tokens with any of %token, %left, %right,
1488 %precedence, or %nonassoc yields the same result.
1490 When mixing declarations of tokens with a literal character (e.g., 'a') or
1491 with an identifier (e.g., B) in a precedence declaration, Bison numbered
1492 the literal characters first. For example
1496 would lead to the tokens declared in this order: 'c' 'd' A B. Again, the
1497 input order is now preserved.
1499 These changes were made so that one can remove useless precedence and
1500 associativity declarations (i.e., map %nonassoc, %left or %right to
1501 %precedence, or to %token) and get exactly the same output.
1503 ** Useless precedence and associativity
1505 Contributed by Valentin Tolmer.
1507 When developing and maintaining a grammar, useless associativity and
1508 precedence directives are common. They can be a nuisance: new ambiguities
1509 arising are sometimes masked because their conflicts are resolved due to
1510 the extra precedence or associativity information. Furthermore, it can
1511 hinder the comprehension of a new grammar: one will wonder about the role
1512 of a precedence, where in fact it is useless. The following changes aim
1513 at detecting and reporting these extra directives.
1515 *** Precedence warning category
1517 A new category of warning, -Wprecedence, was introduced. It flags the
1518 useless precedence and associativity directives.
1520 *** Useless associativity
1522 Bison now warns about symbols with a declared associativity that is never
1523 used to resolve conflicts. In that case, using %precedence is sufficient;
1524 the parsing tables will remain unchanged. Solving these warnings may raise
1525 useless precedence warnings, as the symbols no longer have associativity.
1539 warning: useless associativity for '+', use %precedence [-Wprecedence]
1543 *** Useless precedence
1545 Bison now warns about symbols with a declared precedence and no declared
1546 associativity (i.e., declared with %precedence), and whose precedence is
1547 never used. In that case, the symbol can be safely declared with %token
1548 instead, without modifying the parsing tables. For example:
1552 exp: "var" '=' "number";
1556 warning: useless precedence for '=' [-Wprecedence]
1560 *** Useless precedence and associativity
1562 In case of both useless precedence and associativity, the issue is flagged
1567 exp: "var" '=' "number";
1571 warning: useless precedence and associativity for '=' [-Wprecedence]
1577 With help from Joel E. Denny and Gabriel Rassoul.
1579 Empty rules (i.e., with an empty right-hand side) can now be explicitly
1580 marked by the new %empty directive. Using %empty on a non-empty rule is
1581 an error. The new -Wempty-rule warning reports empty rules without
1582 %empty. On the following grammar:
1592 3.4-5: warning: empty rule without %empty [-Wempty-rule]
1595 5.8-13: error: %empty on non-empty rule
1599 ** Java skeleton improvements
1601 The constants for token names were moved to the Lexer interface. Also, it
1602 is possible to add code to the parser's constructors using "%code init"
1603 and "%define init_throws".
1604 Contributed by Paolo Bonzini.
1606 The Java skeleton now supports push parsing.
1607 Contributed by Dennis Heimbigner.
1609 ** C++ skeletons improvements
1611 *** The parser header is no longer mandatory (lalr1.cc, glr.cc)
1613 Using %defines is now optional. Without it, the needed support classes
1614 are defined in the generated parser, instead of additional files (such as
1615 location.hh, position.hh and stack.hh).
1617 *** Locations are no longer mandatory (lalr1.cc, glr.cc)
1619 Both lalr1.cc and glr.cc no longer require %location.
1621 *** syntax_error exception (lalr1.cc)
1623 The C++ parser features a syntax_error exception, which can be
1624 thrown from the scanner or from user rules to raise syntax errors.
1625 This facilitates reporting errors caught in sub-functions (e.g.,
1626 rejecting too large integral literals from a conversion function
1627 used by the scanner, or rejecting invalid combinations from a
1628 factory invoked by the user actions).
1630 *** %define api.value.type variant
1632 This is based on a submission from Michiel De Wilde. With help
1633 from Théophile Ranquet.
1635 In this mode, complex C++ objects can be used as semantic values. For
1638 %token <::std::string> TEXT;
1639 %token <int> NUMBER;
1640 %token SEMICOLON ";"
1641 %type <::std::string> item;
1642 %type <::std::list<std::string>> list;
1645 list { std::cout << $1 << std::endl; }
1649 %empty { /* Generates an empty string list. */ }
1650 | list item ";" { std::swap ($$, $1); $$.push_back ($2); }
1654 TEXT { std::swap ($$, $1); }
1655 | NUMBER { $$ = string_cast ($1); }
1658 *** %define api.token.constructor
1660 When variants are enabled, Bison can generate functions to build the
1661 tokens. This guarantees that the token type (e.g., NUMBER) is consistent
1662 with the semantic value (e.g., int):
1664 parser::symbol_type yylex ()
1666 parser::location_type loc = ...;
1668 return parser::make_TEXT ("Hello, world!", loc);
1670 return parser::make_NUMBER (42, loc);
1672 return parser::make_SEMICOLON (loc);
1678 There are operator- and operator-= for 'location'. Negative line/column
1679 increments can no longer underflow the resulting value.
1681 * Noteworthy changes in release 2.7.1 (2013-04-15) [stable]
1685 *** Fix compiler attribute portability (yacc.c)
1687 With locations enabled, __attribute__ was used unprotected.
1689 *** Fix some compiler warnings (lalr1.cc)
1691 * Noteworthy changes in release 2.7 (2012-12-12) [stable]
1695 Warnings about uninitialized yylloc in yyparse have been fixed.
1697 Restored C90 compliance (yet no report was ever made).
1699 ** Diagnostics are improved
1701 Contributed by Théophile Ranquet.
1703 *** Changes in the format of error messages
1705 This used to be the format of many error reports:
1707 input.y:2.7-12: %type redeclaration for exp
1708 input.y:1.7-12: previous declaration
1712 input.y:2.7-12: error: %type redeclaration for exp
1713 input.y:1.7-12: previous declaration
1715 *** New format for error reports: carets
1717 Caret errors have been added to Bison:
1719 input.y:2.7-12: error: %type redeclaration for exp
1722 input.y:1.7-12: previous declaration
1728 input.y:3.20-23: error: ambiguous reference: '$exp'
1729 exp: exp '+' exp { $exp = $1 + $3; };
1731 input.y:3.1-3: refers to: $exp at $$
1732 exp: exp '+' exp { $exp = $1 + $3; };
1734 input.y:3.6-8: refers to: $exp at $1
1735 exp: exp '+' exp { $exp = $1 + $3; };
1737 input.y:3.14-16: refers to: $exp at $3
1738 exp: exp '+' exp { $exp = $1 + $3; };
1741 The default behavior for now is still not to display these unless
1742 explicitly asked with -fcaret (or -fall). However, in a later release, it
1743 will be made the default behavior (but may still be deactivated with
1746 ** New value for %define variable: api.pure full
1748 The %define variable api.pure requests a pure (reentrant) parser. However,
1749 for historical reasons, using it in a location-tracking Yacc parser
1750 resulted in a yyerror function that did not take a location as a
1751 parameter. With this new value, the user may request a better pure parser,
1752 where yyerror does take a location as a parameter (in location-tracking
1755 The use of "%define api.pure true" is deprecated in favor of this new
1756 "%define api.pure full".
1758 ** New %define variable: api.location.type (glr.cc, lalr1.cc, lalr1.java)
1760 The %define variable api.location.type defines the name of the type to use
1761 for locations. When defined, Bison no longer generates the position.hh
1762 and location.hh files, nor does the parser will include them: the user is
1763 then responsible to define her type.
1765 This can be used in programs with several parsers to factor their location
1766 and position files: let one of them generate them, and the others just use
1769 This feature was actually introduced, but not documented, in Bison 2.5,
1770 under the name "location_type" (which is maintained for backward
1773 For consistency, lalr1.java's %define variables location_type and
1774 position_type are deprecated in favor of api.location.type and
1777 ** Exception safety (lalr1.cc)
1779 The parse function now catches exceptions, uses the %destructors to
1780 release memory (the lookahead symbol and the symbols pushed on the stack)
1781 before re-throwing the exception.
1783 This feature is somewhat experimental. User feedback would be
1786 ** Graph improvements in DOT and XSLT
1788 Contributed by Théophile Ranquet.
1790 The graphical presentation of the states is more readable: their shape is
1791 now rectangular, the state number is clearly displayed, and the items are
1792 numbered and left-justified.
1794 The reductions are now explicitly represented as transitions to other
1795 diamond shaped nodes.
1797 These changes are present in both --graph output and xml2dot.xsl XSLT
1798 processing, with minor (documented) differences.
1800 ** %language is no longer an experimental feature.
1802 The introduction of this feature, in 2.4, was four years ago. The
1803 --language option and the %language directive are no longer experimental.
1807 The sections about shift/reduce and reduce/reduce conflicts resolution
1808 have been fixed and extended.
1810 Although introduced more than four years ago, XML and Graphviz reports
1811 were not properly documented.
1813 The translation of midrule actions is now described.
1815 * Noteworthy changes in release 2.6.5 (2012-11-07) [stable]
1817 We consider compiler warnings about Bison generated parsers to be bugs.
1818 Rather than working around them in your own project, please consider
1819 reporting them to us.
1823 Warnings about uninitialized yylval and/or yylloc for push parsers with a
1824 pure interface have been fixed for GCC 4.0 up to 4.8, and Clang 2.9 to
1827 Other issues in the test suite have been addressed.
1829 Null characters are correctly displayed in error messages.
1831 When possible, yylloc is correctly initialized before calling yylex. It
1832 is no longer necessary to initialize it in the %initial-action.
1834 * Noteworthy changes in release 2.6.4 (2012-10-23) [stable]
1836 Bison 2.6.3's --version was incorrect. This release fixes this issue.
1838 * Noteworthy changes in release 2.6.3 (2012-10-22) [stable]
1842 Bugs and portability issues in the test suite have been fixed.
1844 Some errors in translations have been addressed, and --help now directs
1845 users to the appropriate place to report them.
1847 Stray Info files shipped by accident are removed.
1849 Incorrect definitions of YY_, issued by yacc.c when no parser header is
1850 generated, are removed.
1852 All the generated headers are self-contained.
1854 ** Header guards (yacc.c, glr.c, glr.cc)
1856 In order to avoid collisions, the header guards are now
1857 YY_<PREFIX>_<FILE>_INCLUDED, instead of merely <PREFIX>_<FILE>.
1858 For instance the header generated from
1860 %define api.prefix "calc"
1861 %defines "lib/parse.h"
1863 will use YY_CALC_LIB_PARSE_H_INCLUDED as guard.
1865 ** Fix compiler warnings in the generated parser (yacc.c, glr.c)
1867 The compilation of pure parsers (%define api.pure) can trigger GCC
1870 input.c: In function 'yyparse':
1871 input.c:1503:12: warning: 'yylval' may be used uninitialized in this
1872 function [-Wmaybe-uninitialized]
1876 This is now fixed; pragmas to avoid these warnings are no longer needed.
1878 Warnings from clang ("equality comparison with extraneous parentheses" and
1879 "function declared 'noreturn' should not return") have also been
1882 * Noteworthy changes in release 2.6.2 (2012-08-03) [stable]
1886 Buffer overruns, complaints from Flex, and portability issues in the test
1887 suite have been fixed.
1889 ** Spaces in %lex- and %parse-param (lalr1.cc, glr.cc)
1891 Trailing end-of-lines in %parse-param or %lex-param would result in
1892 invalid C++. This is fixed.
1894 ** Spurious spaces and end-of-lines
1896 The generated files no longer end (nor start) with empty lines.
1898 * Noteworthy changes in release 2.6.1 (2012-07-30) [stable]
1900 Bison no longer executes user-specified M4 code when processing a grammar.
1904 In addition to the removal of the features announced in Bison 2.6, the
1905 next major release will remove the "Temporary hack for adding a semicolon
1906 to the user action", as announced in the release 2.5. Instead of:
1908 exp: exp "+" exp { $$ = $1 + $3 };
1912 exp: exp "+" exp { $$ = $1 + $3; };
1916 *** Type names are now properly escaped.
1918 *** glr.cc: set_debug_level and debug_level work as expected.
1920 *** Stray @ or $ in actions
1922 While Bison used to warn about stray $ or @ in action rules, it did not
1923 for other actions such as printers, destructors, or initial actions. It
1926 ** Type names in actions
1928 For consistency with rule actions, it is now possible to qualify $$ by a
1929 type-name in destructors, printers, and initial actions. For instance:
1931 %printer { fprintf (yyo, "(%d, %f)", $<ival>$, $<fval>$); } <*> <>;
1933 will display two values for each typed and untyped symbol (provided
1934 that YYSTYPE has both "ival" and "fval" fields).
1936 * Noteworthy changes in release 2.6 (2012-07-19) [stable]
1940 The next major release of Bison will drop support for the following
1941 deprecated features. Please report disagreements to bug-bison@gnu.org.
1945 Support for generating parsers in K&R C will be removed. Parsers
1946 generated for C support ISO C90, and are tested with ISO C99 and ISO C11
1949 *** Features deprecated since Bison 1.875
1951 The definitions of yystype and yyltype will be removed; use YYSTYPE and
1954 YYPARSE_PARAM and YYLEX_PARAM, deprecated in favor of %parse-param and
1955 %lex-param, will no longer be supported.
1957 Support for the preprocessor symbol YYERROR_VERBOSE will be removed, use
1960 *** The generated header will be included (yacc.c)
1962 Instead of duplicating the content of the generated header (definition of
1963 YYSTYPE, yyparse declaration etc.), the generated parser will include it,
1964 as is already the case for GLR or C++ parsers. This change is deferred
1965 because existing versions of ylwrap (e.g., Automake 1.12.1) do not support
1968 ** Generated Parser Headers
1970 *** Guards (yacc.c, glr.c, glr.cc)
1972 The generated headers are now guarded, as is already the case for C++
1973 parsers (lalr1.cc). For instance, with --defines=foo.h:
1978 #endif /* !YY_FOO_H */
1980 *** New declarations (yacc.c, glr.c)
1982 The generated header now declares yydebug and yyparse. Both honor
1983 --name-prefix=bar_, and yield
1985 int bar_parse (void);
1989 #define yyparse bar_parse
1992 in order to facilitate the inclusion of several parser headers inside a
1993 single compilation unit.
1995 *** Exported symbols in C++
1997 The symbols YYTOKEN_TABLE and YYERROR_VERBOSE, which were defined in the
1998 header, are removed, as they prevent the possibility of including several
1999 generated headers from a single compilation unit.
2003 For the same reasons, the undocumented and unused macro YYLSP_NEEDED is no
2006 ** New %define variable: api.prefix
2008 Now that the generated headers are more complete and properly protected
2009 against multiple inclusions, constant names, such as YYSTYPE are a
2010 problem. While yyparse and others are properly renamed by %name-prefix,
2011 YYSTYPE, YYDEBUG and others have never been affected by it. Because it
2012 would introduce backward compatibility issues in projects not expecting
2013 YYSTYPE to be renamed, instead of changing the behavior of %name-prefix,
2014 it is deprecated in favor of a new %define variable: api.prefix.
2016 The following examples compares both:
2018 %name-prefix "bar_" | %define api.prefix "bar_"
2019 %token <ival> FOO %token <ival> FOO
2020 %union { int ival; } %union { int ival; }
2026 #ifndef BAR_FOO_H #ifndef BAR_FOO_H
2027 # define BAR_FOO_H # define BAR_FOO_H
2029 /* Enabling traces. */ /* Enabling traces. */
2030 # ifndef YYDEBUG | # ifndef BAR_DEBUG
2031 > # if defined YYDEBUG
2033 > # define BAR_DEBUG 1
2035 > # define BAR_DEBUG 0
2038 # define YYDEBUG 0 | # define BAR_DEBUG 0
2042 # if YYDEBUG | # if BAR_DEBUG
2043 extern int bar_debug; extern int bar_debug;
2046 /* Tokens. */ /* Tokens. */
2047 # ifndef YYTOKENTYPE | # ifndef BAR_TOKENTYPE
2048 # define YYTOKENTYPE | # define BAR_TOKENTYPE
2049 enum yytokentype { | enum bar_tokentype {
2054 #if ! defined YYSTYPE \ | #if ! defined BAR_STYPE \
2055 && ! defined YYSTYPE_IS_DECLARED | && ! defined BAR_STYPE_IS_DECLARED
2056 typedef union YYSTYPE | typedef union BAR_STYPE
2059 } YYSTYPE; | } BAR_STYPE;
2060 # define YYSTYPE_IS_DECLARED 1 | # define BAR_STYPE_IS_DECLARED 1
2063 extern YYSTYPE bar_lval; | extern BAR_STYPE bar_lval;
2065 int bar_parse (void); int bar_parse (void);
2067 #endif /* !BAR_FOO_H */ #endif /* !BAR_FOO_H */
2069 * Noteworthy changes in release 2.5.1 (2012-06-05) [stable]
2073 The next major release will drop support for generating parsers in K&R C.
2075 ** yacc.c: YYBACKUP works as expected.
2077 ** glr.c improvements:
2079 *** Location support is eliminated when not requested:
2081 GLR parsers used to include location-related code even when locations were
2082 not requested, and therefore not even usable.
2084 *** __attribute__ is preserved:
2086 __attribute__ is no longer disabled when __STRICT_ANSI__ is defined (i.e.,
2087 when -std is passed to GCC).
2089 ** lalr1.java: several fixes:
2091 The Java parser no longer throws ArrayIndexOutOfBoundsException if the
2092 first token leads to a syntax error. Some minor clean ups.
2096 *** C++11 compatibility:
2098 C and C++ parsers use "nullptr" instead of "0" when __cplusplus is 201103L
2103 The header files such as "parser.hh", "location.hh", etc. used a constant
2104 name for preprocessor guards, for instance:
2106 #ifndef BISON_LOCATION_HH
2107 # define BISON_LOCATION_HH
2109 #endif // !BISON_LOCATION_HH
2111 The inclusion guard is now computed from "PREFIX/FILE-NAME", where lower
2112 case characters are converted to upper case, and series of
2113 non-alphanumerical characters are converted to an underscore.
2115 With "bison -o lang++/parser.cc", "location.hh" would now include:
2117 #ifndef YY_LANG_LOCATION_HH
2118 # define YY_LANG_LOCATION_HH
2120 #endif // !YY_LANG_LOCATION_HH
2124 The position and location constructors (and their initialize methods)
2125 accept new arguments for line and column. Several issues in the
2126 documentation were fixed.
2128 ** liby is no longer asking for "rpl_fprintf" on some platforms.
2130 ** Changes in the manual:
2132 *** %printer is documented
2134 The "%printer" directive, supported since at least Bison 1.50, is finally
2135 documented. The "mfcalc" example is extended to demonstrate it.
2137 For consistency with the C skeletons, the C++ parsers now also support
2138 "yyoutput" (as an alias to "debug_stream ()").
2140 *** Several improvements have been made:
2142 The layout for grammar excerpts was changed to a more compact scheme.
2143 Named references are motivated. The description of the automaton
2144 description file (*.output) is updated to the current format. Incorrect
2145 index entries were fixed. Some other errors were fixed.
2149 *** Conflicting prototypes with recent/modified Flex.
2151 Fixed build problems with the current, unreleased, version of Flex, and
2152 some modified versions of 2.5.35, which have modified function prototypes.
2154 *** Warnings during the build procedure have been eliminated.
2156 *** Several portability problems in the test suite have been fixed:
2158 This includes warnings with some compilers, unexpected behavior of tools
2159 such as diff, warning messages from the test suite itself, etc.
2161 *** The install-pdf target works properly:
2163 Running "make install-pdf" (or -dvi, -html, -info, and -ps) no longer
2164 halts in the middle of its course.
2166 * Changes in version 2.5 (2011-05-14):
2168 ** Grammar symbol names can now contain non-initial dashes:
2170 Consistently with directives (such as %error-verbose) and with
2171 %define variables (e.g. push-pull), grammar symbol names may contain
2172 dashes in any position except the beginning. This is a GNU
2173 extension over POSIX Yacc. Thus, use of this extension is reported
2174 by -Wyacc and rejected in Yacc mode (--yacc).
2176 ** Named references:
2178 Historically, Yacc and Bison have supported positional references
2179 ($n, $$) to allow access to symbol values from inside of semantic
2182 Starting from this version, Bison can also accept named references.
2183 When no ambiguity is possible, original symbol names may be used
2184 as named references:
2186 if_stmt : "if" cond_expr "then" then_stmt ';'
2187 { $if_stmt = mk_if_stmt($cond_expr, $then_stmt); }
2189 In the more common case, explicit names may be declared:
2191 stmt[res] : "if" expr[cond] "then" stmt[then] "else" stmt[else] ';'
2192 { $res = mk_if_stmt($cond, $then, $else); }
2194 Location information is also accessible using @name syntax. When
2195 accessing symbol names containing dots or dashes, explicit bracketing
2196 ($[sym.1]) must be used.
2198 These features are experimental in this version. More user feedback
2199 will help to stabilize them.
2200 Contributed by Alex Rozenman.
2202 ** IELR(1) and canonical LR(1):
2204 IELR(1) is a minimal LR(1) parser table generation algorithm. That
2205 is, given any context-free grammar, IELR(1) generates parser tables
2206 with the full language-recognition power of canonical LR(1) but with
2207 nearly the same number of parser states as LALR(1). This reduction
2208 in parser states is often an order of magnitude. More importantly,
2209 because canonical LR(1)'s extra parser states may contain duplicate
2210 conflicts in the case of non-LR(1) grammars, the number of conflicts
2211 for IELR(1) is often an order of magnitude less as well. This can
2212 significantly reduce the complexity of developing of a grammar.
2214 Bison can now generate IELR(1) and canonical LR(1) parser tables in
2215 place of its traditional LALR(1) parser tables, which remain the
2216 default. You can specify the type of parser tables in the grammar
2217 file with these directives:
2219 %define lr.type lalr
2220 %define lr.type ielr
2221 %define lr.type canonical-lr
2223 The default-reduction optimization in the parser tables can also be
2224 adjusted using "%define lr.default-reductions". For details on both
2225 of these features, see the new section "Tuning LR" in the Bison
2228 These features are experimental. More user feedback will help to
2231 ** LAC (Lookahead Correction) for syntax error handling
2233 Contributed by Joel E. Denny.
2235 Canonical LR, IELR, and LALR can suffer from a couple of problems
2236 upon encountering a syntax error. First, the parser might perform
2237 additional parser stack reductions before discovering the syntax
2238 error. Such reductions can perform user semantic actions that are
2239 unexpected because they are based on an invalid token, and they
2240 cause error recovery to begin in a different syntactic context than
2241 the one in which the invalid token was encountered. Second, when
2242 verbose error messages are enabled (with %error-verbose or the
2243 obsolete "#define YYERROR_VERBOSE"), the expected token list in the
2244 syntax error message can both contain invalid tokens and omit valid
2247 The culprits for the above problems are %nonassoc, default
2248 reductions in inconsistent states, and parser state merging. Thus,
2249 IELR and LALR suffer the most. Canonical LR can suffer only if
2250 %nonassoc is used or if default reductions are enabled for
2251 inconsistent states.
2253 LAC is a new mechanism within the parsing algorithm that solves
2254 these problems for canonical LR, IELR, and LALR without sacrificing
2255 %nonassoc, default reductions, or state merging. When LAC is in
2256 use, canonical LR and IELR behave almost exactly the same for both
2257 syntactically acceptable and syntactically unacceptable input.
2258 While LALR still does not support the full language-recognition
2259 power of canonical LR and IELR, LAC at least enables LALR's syntax
2260 error handling to correctly reflect LALR's language-recognition
2263 Currently, LAC is only supported for deterministic parsers in C.
2264 You can enable LAC with the following directive:
2266 %define parse.lac full
2268 See the new section "LAC" in the Bison manual for additional
2269 details including a few caveats.
2271 LAC is an experimental feature. More user feedback will help to
2274 ** %define improvements:
2276 *** Can now be invoked via the command line:
2278 Each of these command-line options
2281 --define=NAME[=VALUE]
2284 --force-define=NAME[=VALUE]
2286 is equivalent to this grammar file declaration
2288 %define NAME ["VALUE"]
2290 except that the manner in which Bison processes multiple definitions
2291 for the same NAME differs. Most importantly, -F and --force-define
2292 quietly override %define, but -D and --define do not. For further
2293 details, see the section "Bison Options" in the Bison manual.
2295 *** Variables renamed:
2297 The following %define variables
2300 lr.keep_unreachable_states
2302 have been renamed to
2305 lr.keep-unreachable-states
2307 The old names are now deprecated but will be maintained indefinitely
2308 for backward compatibility.
2310 *** Values no longer need to be quoted in the grammar file:
2312 If a %define value is an identifier, it no longer needs to be placed
2313 within quotations marks. For example,
2315 %define api.push-pull "push"
2319 %define api.push-pull push
2321 *** Unrecognized variables are now errors not warnings.
2323 *** Multiple invocations for any variable is now an error not a warning.
2325 ** Unrecognized %code qualifiers are now errors not warnings.
2327 ** Character literals not of length one:
2329 Previously, Bison quietly converted all character literals to length
2330 one. For example, without warning, Bison interpreted the operators in
2331 the following grammar to be the same token:
2337 Bison now warns when a character literal is not of length one. In
2338 some future release, Bison will start reporting an error instead.
2340 ** Destructor calls fixed for lookaheads altered in semantic actions:
2342 Previously for deterministic parsers in C, if a user semantic action
2343 altered yychar, the parser in some cases used the old yychar value to
2344 determine which destructor to call for the lookahead upon a syntax
2345 error or upon parser return. This bug has been fixed.
2347 ** C++ parsers use YYRHSLOC:
2349 Similarly to the C parsers, the C++ parsers now define the YYRHSLOC
2350 macro and use it in the default YYLLOC_DEFAULT. You are encouraged
2351 to use it. If, for instance, your location structure has "first"
2352 and "last" members, instead of
2354 # define YYLLOC_DEFAULT(Current, Rhs, N) \
2358 (Current).first = (Rhs)[1].location.first; \
2359 (Current).last = (Rhs)[N].location.last; \
2363 (Current).first = (Current).last = (Rhs)[0].location.last; \
2369 # define YYLLOC_DEFAULT(Current, Rhs, N) \
2373 (Current).first = YYRHSLOC (Rhs, 1).first; \
2374 (Current).last = YYRHSLOC (Rhs, N).last; \
2378 (Current).first = (Current).last = YYRHSLOC (Rhs, 0).last; \
2382 ** YYLLOC_DEFAULT in C++:
2384 The default implementation of YYLLOC_DEFAULT used to be issued in
2385 the header file. It is now output in the implementation file, after
2386 the user %code sections so that its #ifndef guard does not try to
2387 override the user's YYLLOC_DEFAULT if provided.
2389 ** YYFAIL now produces warnings and Java parsers no longer implement it:
2391 YYFAIL has existed for many years as an undocumented feature of
2392 deterministic parsers in C generated by Bison. More recently, it was
2393 a documented feature of Bison's experimental Java parsers. As
2394 promised in Bison 2.4.2's NEWS entry, any appearance of YYFAIL in a
2395 semantic action now produces a deprecation warning, and Java parsers
2396 no longer implement YYFAIL at all. For further details, including a
2397 discussion of how to suppress C preprocessor warnings about YYFAIL
2398 being unused, see the Bison 2.4.2 NEWS entry.
2400 ** Temporary hack for adding a semicolon to the user action:
2402 Previously, Bison appended a semicolon to every user action for
2403 reductions when the output language defaulted to C (specifically, when
2404 neither %yacc, %language, %skeleton, or equivalent command-line
2405 options were specified). This allowed actions such as
2407 exp: exp "+" exp { $$ = $1 + $3 };
2411 exp: exp "+" exp { $$ = $1 + $3; };
2413 As a first step in removing this misfeature, Bison now issues a
2414 warning when it appends a semicolon. Moreover, in cases where Bison
2415 cannot easily determine whether a semicolon is needed (for example, an
2416 action ending with a cpp directive or a braced compound initializer),
2417 it no longer appends one. Thus, the C compiler might now complain
2418 about a missing semicolon where it did not before. Future releases of
2419 Bison will cease to append semicolons entirely.
2421 ** Verbose syntax error message fixes:
2423 When %error-verbose or the obsolete "#define YYERROR_VERBOSE" is
2424 specified, syntax error messages produced by the generated parser
2425 include the unexpected token as well as a list of expected tokens.
2426 The effect of %nonassoc on these verbose messages has been corrected
2427 in two ways, but a more complete fix requires LAC, described above:
2429 *** When %nonassoc is used, there can exist parser states that accept no
2430 tokens, and so the parser does not always require a lookahead token
2431 in order to detect a syntax error. Because no unexpected token or
2432 expected tokens can then be reported, the verbose syntax error
2433 message described above is suppressed, and the parser instead
2434 reports the simpler message, "syntax error". Previously, this
2435 suppression was sometimes erroneously triggered by %nonassoc when a
2436 lookahead was actually required. Now verbose messages are
2437 suppressed only when all previous lookaheads have already been
2438 shifted or discarded.
2440 *** Previously, the list of expected tokens erroneously included tokens
2441 that would actually induce a syntax error because conflicts for them
2442 were resolved with %nonassoc in the current parser state. Such
2443 tokens are now properly omitted from the list.
2445 *** Expected token lists are still often wrong due to state merging
2446 (from LALR or IELR) and default reductions, which can both add
2447 invalid tokens and subtract valid tokens. Canonical LR almost
2448 completely fixes this problem by eliminating state merging and
2449 default reductions. However, there is one minor problem left even
2450 when using canonical LR and even after the fixes above. That is,
2451 if the resolution of a conflict with %nonassoc appears in a later
2452 parser state than the one at which some syntax error is
2453 discovered, the conflicted token is still erroneously included in
2454 the expected token list. Bison's new LAC implementation,
2455 described above, eliminates this problem and the need for
2456 canonical LR. However, LAC is still experimental and is disabled
2459 ** Java skeleton fixes:
2461 *** A location handling bug has been fixed.
2463 *** The top element of each of the value stack and location stack is now
2464 cleared when popped so that it can be garbage collected.
2466 *** Parser traces now print the top element of the stack.
2468 ** -W/--warnings fixes:
2470 *** Bison now properly recognizes the "no-" versions of categories:
2472 For example, given the following command line, Bison now enables all
2473 warnings except warnings for incompatibilities with POSIX Yacc:
2475 bison -Wall,no-yacc gram.y
2477 *** Bison now treats S/R and R/R conflicts like other warnings:
2479 Previously, conflict reports were independent of Bison's normal
2480 warning system. Now, Bison recognizes the warning categories
2481 "conflicts-sr" and "conflicts-rr". This change has important
2482 consequences for the -W and --warnings command-line options. For
2485 bison -Wno-conflicts-sr gram.y # S/R conflicts not reported
2486 bison -Wno-conflicts-rr gram.y # R/R conflicts not reported
2487 bison -Wnone gram.y # no conflicts are reported
2488 bison -Werror gram.y # any conflict is an error
2490 However, as before, if the %expect or %expect-rr directive is
2491 specified, an unexpected number of conflicts is an error, and an
2492 expected number of conflicts is not reported, so -W and --warning
2493 then have no effect on the conflict report.
2495 *** The "none" category no longer disables a preceding "error":
2497 For example, for the following command line, Bison now reports
2498 errors instead of warnings for incompatibilities with POSIX Yacc:
2500 bison -Werror,none,yacc gram.y
2502 *** The "none" category now disables all Bison warnings:
2504 Previously, the "none" category disabled only Bison warnings for
2505 which there existed a specific -W/--warning category. However,
2506 given the following command line, Bison is now guaranteed to
2507 suppress all warnings:
2511 ** Precedence directives can now assign token number 0:
2513 Since Bison 2.3b, which restored the ability of precedence
2514 directives to assign token numbers, doing so for token number 0 has
2515 produced an assertion failure. For example:
2519 This bug has been fixed.
2521 * Changes in version 2.4.3 (2010-08-05):
2523 ** Bison now obeys -Werror and --warnings=error for warnings about
2524 grammar rules that are useless in the parser due to conflicts.
2526 ** Problems with spawning M4 on at least FreeBSD 8 and FreeBSD 9 have
2529 ** Failures in the test suite for GCC 4.5 have been fixed.
2531 ** Failures in the test suite for some versions of Sun Studio C++ have
2534 ** Contrary to Bison 2.4.2's NEWS entry, it has been decided that
2535 warnings about undefined %prec identifiers will not be converted to
2536 errors in Bison 2.5. They will remain warnings, which should be
2537 sufficient for POSIX while avoiding backward compatibility issues.
2539 ** Minor documentation fixes.
2541 * Changes in version 2.4.2 (2010-03-20):
2543 ** Some portability problems that resulted in failures and livelocks
2544 in the test suite on some versions of at least Solaris, AIX, HP-UX,
2545 RHEL4, and Tru64 have been addressed. As a result, fatal Bison
2546 errors should no longer cause M4 to report a broken pipe on the
2549 ** "%prec IDENTIFIER" requires IDENTIFIER to be defined separately.
2551 POSIX specifies that an error be reported for any identifier that does
2552 not appear on the LHS of a grammar rule and that is not defined by
2553 %token, %left, %right, or %nonassoc. Bison 2.3b and later lost this
2554 error report for the case when an identifier appears only after a
2555 %prec directive. It is now restored. However, for backward
2556 compatibility with recent Bison releases, it is only a warning for
2557 now. In Bison 2.5 and later, it will return to being an error.
2558 [Between the 2.4.2 and 2.4.3 releases, it was decided that this
2559 warning will not be converted to an error in Bison 2.5.]
2561 ** Detection of GNU M4 1.4.6 or newer during configure is improved.
2563 ** Warnings from gcc's -Wundef option about undefined YYENABLE_NLS,
2564 YYLTYPE_IS_TRIVIAL, and __STRICT_ANSI__ in C/C++ parsers are now
2567 ** %code is now a permanent feature.
2569 A traditional Yacc prologue directive is written in the form:
2573 To provide a more flexible alternative, Bison 2.3b introduced the
2574 %code directive with the following forms for C/C++:
2577 %code requires {CODE}
2578 %code provides {CODE}
2581 These forms are now considered permanent features of Bison. See the
2582 %code entries in the section "Bison Declaration Summary" in the Bison
2583 manual for a summary of their functionality. See the section
2584 "Prologue Alternatives" for a detailed discussion including the
2585 advantages of %code over the traditional Yacc prologue directive.
2587 Bison's Java feature as a whole including its current usage of %code
2588 is still considered experimental.
2590 ** YYFAIL is deprecated and will eventually be removed.
2592 YYFAIL has existed for many years as an undocumented feature of
2593 deterministic parsers in C generated by Bison. Previously, it was
2594 documented for Bison's experimental Java parsers. YYFAIL is no longer
2595 documented for Java parsers and is formally deprecated in both cases.
2596 Users are strongly encouraged to migrate to YYERROR, which is
2599 Like YYERROR, you can invoke YYFAIL from a semantic action in order to
2600 induce a syntax error. The most obvious difference from YYERROR is
2601 that YYFAIL will automatically invoke yyerror to report the syntax
2602 error so that you don't have to. However, there are several other
2603 subtle differences between YYERROR and YYFAIL, and YYFAIL suffers from
2604 inherent flaws when %error-verbose or "#define YYERROR_VERBOSE" is
2605 used. For a more detailed discussion, see:
2607 http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html
2609 The upcoming Bison 2.5 will remove YYFAIL from Java parsers, but
2610 deterministic parsers in C will continue to implement it. However,
2611 because YYFAIL is already flawed, it seems futile to try to make new
2612 Bison features compatible with it. Thus, during parser generation,
2613 Bison 2.5 will produce a warning whenever it discovers YYFAIL in a
2614 rule action. In a later release, YYFAIL will be disabled for
2615 %error-verbose and "#define YYERROR_VERBOSE". Eventually, YYFAIL will
2616 be removed altogether.
2618 There exists at least one case where Bison 2.5's YYFAIL warning will
2619 be a false positive. Some projects add phony uses of YYFAIL and other
2620 Bison-defined macros for the sole purpose of suppressing C
2621 preprocessor warnings (from GCC cpp's -Wunused-macros, for example).
2622 To avoid Bison's future warning, such YYFAIL uses can be moved to the
2623 epilogue (that is, after the second "%%") in the Bison input file. In
2624 this release (2.4.2), Bison already generates its own code to suppress
2625 C preprocessor warnings for YYFAIL, so projects can remove their own
2626 phony uses of YYFAIL if compatibility with Bison releases prior to
2627 2.4.2 is not necessary.
2629 ** Internationalization.
2631 Fix a regression introduced in Bison 2.4: Under some circumstances,
2632 message translations were not installed although supported by the
2635 * Changes in version 2.4.1 (2008-12-11):
2637 ** In the GLR defines file, unexpanded M4 macros in the yylval and yylloc
2638 declarations have been fixed.
2640 ** Temporary hack for adding a semicolon to the user action.
2642 Bison used to prepend a trailing semicolon at the end of the user
2643 action for reductions. This allowed actions such as
2645 exp: exp "+" exp { $$ = $1 + $3 };
2649 exp: exp "+" exp { $$ = $1 + $3; };
2651 Some grammars still depend on this "feature". Bison 2.4.1 restores
2652 the previous behavior in the case of C output (specifically, when
2653 neither %language or %skeleton or equivalent command-line options
2654 are used) to leave more time for grammars depending on the old
2655 behavior to be adjusted. Future releases of Bison will disable this
2658 ** A few minor improvements to the Bison manual.
2660 * Changes in version 2.4 (2008-11-02):
2662 ** %language is an experimental feature.
2664 We first introduced this feature in test release 2.3b as a cleaner
2665 alternative to %skeleton. Since then, we have discussed the possibility of
2666 modifying its effect on Bison's output file names. Thus, in this release,
2667 we consider %language to be an experimental feature that will likely evolve
2670 ** Forward compatibility with GNU M4 has been improved.
2672 ** Several bugs in the C++ skeleton and the experimental Java skeleton have been
2675 * Changes in version 2.3b (2008-05-27):
2677 ** The quotes around NAME that used to be required in the following directive
2680 %define NAME "VALUE"
2682 ** The directive "%pure-parser" is now deprecated in favor of:
2686 which has the same effect except that Bison is more careful to warn about
2687 unreasonable usage in the latter case.
2691 Bison can now generate an LALR(1) parser in C with a push interface. That
2692 is, instead of invoking "yyparse", which pulls tokens from "yylex", you can
2693 push one token at a time to the parser using "yypush_parse", which will
2694 return to the caller after processing each token. By default, the push
2695 interface is disabled. Either of the following directives will enable it:
2697 %define api.push_pull "push" // Just push; does not require yylex.
2698 %define api.push_pull "both" // Push and pull; requires yylex.
2700 See the new section "A Push Parser" in the Bison manual for details.
2702 The current push parsing interface is experimental and may evolve. More user
2703 feedback will help to stabilize it.
2705 ** The -g and --graph options now output graphs in Graphviz DOT format,
2706 not VCG format. Like --graph, -g now also takes an optional FILE argument
2707 and thus cannot be bundled with other short options.
2711 Bison can now generate an LALR(1) parser in Java. The skeleton is
2712 "data/lalr1.java". Consider using the new %language directive instead of
2713 %skeleton to select it.
2715 See the new section "Java Parsers" in the Bison manual for details.
2717 The current Java interface is experimental and may evolve. More user
2718 feedback will help to stabilize it.
2719 Contributed by Paolo Bonzini.
2723 This new directive specifies the programming language of the generated
2724 parser, which can be C (the default), C++, or Java. Besides the skeleton
2725 that Bison uses, the directive affects the names of the generated files if
2726 the grammar file's name ends in ".y".
2728 ** XML Automaton Report
2730 Bison can now generate an XML report of the LALR(1) automaton using the new
2731 "--xml" option. The current XML schema is experimental and may evolve. More
2732 user feedback will help to stabilize it.
2733 Contributed by Wojciech Polak.
2735 ** The grammar file may now specify the name of the parser header file using
2736 %defines. For example:
2740 ** When reporting useless rules, useless nonterminals, and unused terminals,
2741 Bison now employs the terms "useless in grammar" instead of "useless",
2742 "useless in parser" instead of "never reduced", and "unused in grammar"
2743 instead of "unused".
2745 ** Unreachable State Removal
2747 Previously, Bison sometimes generated parser tables containing unreachable
2748 states. A state can become unreachable during conflict resolution if Bison
2749 disables a shift action leading to it from a predecessor state. Bison now:
2751 1. Removes unreachable states.
2753 2. Does not report any conflicts that appeared in unreachable states.
2754 WARNING: As a result, you may need to update %expect and %expect-rr
2755 directives in existing grammar files.
2757 3. For any rule used only in such states, Bison now reports the rule as
2758 "useless in parser due to conflicts".
2760 This feature can be disabled with the following directive:
2762 %define lr.keep_unreachable_states
2764 See the %define entry in the "Bison Declaration Summary" in the Bison manual
2765 for further discussion.
2767 ** Lookahead Set Correction in the ".output" Report
2769 When instructed to generate a ".output" file including lookahead sets
2770 (using "--report=lookahead", for example), Bison now prints each reduction's
2771 lookahead set only next to the associated state's one item that (1) is
2772 associated with the same rule as the reduction and (2) has its dot at the end
2773 of its RHS. Previously, Bison also erroneously printed the lookahead set
2774 next to all of the state's other items associated with the same rule. This
2775 bug affected only the ".output" file and not the generated parser source
2778 ** --report-file=FILE is a new option to override the default ".output" file
2781 ** The "=" that used to be required in the following directives is now
2784 %file-prefix "parser"
2788 ** An Alternative to "%{...%}" -- "%code QUALIFIER {CODE}"
2790 Bison 2.3a provided a new set of directives as a more flexible alternative to
2791 the traditional Yacc prologue blocks. Those have now been consolidated into
2792 a single %code directive with an optional qualifier field, which identifies
2793 the purpose of the code and thus the location(s) where Bison should generate
2796 1. "%code {CODE}" replaces "%after-header {CODE}"
2797 2. "%code requires {CODE}" replaces "%start-header {CODE}"
2798 3. "%code provides {CODE}" replaces "%end-header {CODE}"
2799 4. "%code top {CODE}" replaces "%before-header {CODE}"
2801 See the %code entries in section "Bison Declaration Summary" in the Bison
2802 manual for a summary of the new functionality. See the new section "Prologue
2803 Alternatives" for a detailed discussion including the advantages of %code
2804 over the traditional Yacc prologues.
2806 The prologue alternatives are experimental. More user feedback will help to
2807 determine whether they should become permanent features.
2809 ** Revised warning: unset or unused midrule values
2811 Since Bison 2.2, Bison has warned about midrule values that are set but not
2812 used within any of the actions of the parent rule. For example, Bison warns
2815 exp: '1' { $$ = 1; } '+' exp { $$ = $1 + $4; };
2817 Now, Bison also warns about midrule values that are used but not set. For
2818 example, Bison warns about unset $$ in the midrule action in:
2820 exp: '1' { $1 = 1; } '+' exp { $$ = $2 + $4; };
2822 However, Bison now disables both of these warnings by default since they
2823 sometimes prove to be false alarms in existing grammars employing the Yacc
2824 constructs $0 or $-N (where N is some positive integer).
2826 To enable these warnings, specify the option "--warnings=midrule-values" or
2827 "-W", which is a synonym for "--warnings=all".
2829 ** Default %destructor or %printer with "<*>" or "<>"
2831 Bison now recognizes two separate kinds of default %destructor's and
2834 1. Place "<*>" in a %destructor/%printer symbol list to define a default
2835 %destructor/%printer for all grammar symbols for which you have formally
2836 declared semantic type tags.
2838 2. Place "<>" in a %destructor/%printer symbol list to define a default
2839 %destructor/%printer for all grammar symbols without declared semantic
2842 Bison no longer supports the "%symbol-default" notation from Bison 2.3a.
2843 "<*>" and "<>" combined achieve the same effect with one exception: Bison no
2844 longer applies any %destructor to a midrule value if that midrule value is
2845 not actually ever referenced using either $$ or $n in a semantic action.
2847 The default %destructor's and %printer's are experimental. More user
2848 feedback will help to determine whether they should become permanent
2851 See the section "Freeing Discarded Symbols" in the Bison manual for further
2854 ** %left, %right, and %nonassoc can now declare token numbers. This is required
2855 by POSIX. However, see the end of section "Operator Precedence" in the Bison
2856 manual for a caveat concerning the treatment of literal strings.
2858 ** The nonfunctional --no-parser, -n, and %no-parser options have been
2859 completely removed from Bison.
2861 * Changes in version 2.3a, 2006-09-13:
2863 ** Instead of %union, you can define and use your own union type
2864 YYSTYPE if your grammar contains at least one <type> tag.
2865 Your YYSTYPE need not be a macro; it can be a typedef.
2866 This change is for compatibility with other Yacc implementations,
2867 and is required by POSIX.
2869 ** Locations columns and lines start at 1.
2870 In accordance with the GNU Coding Standards and Emacs.
2872 ** You may now declare per-type and default %destructor's and %printer's:
2876 %union { char *string; }
2877 %token <string> STRING1
2878 %token <string> STRING2
2879 %type <string> string1
2880 %type <string> string2
2881 %union { char character; }
2882 %token <character> CHR
2883 %type <character> chr
2884 %destructor { free ($$); } %symbol-default
2885 %destructor { free ($$); printf ("%d", @$.first_line); } STRING1 string1
2886 %destructor { } <character>
2888 guarantees that, when the parser discards any user-defined symbol that has a
2889 semantic type tag other than "<character>", it passes its semantic value to
2890 "free". However, when the parser discards a "STRING1" or a "string1", it
2891 also prints its line number to "stdout". It performs only the second
2892 "%destructor" in this case, so it invokes "free" only once.
2894 [Although we failed to mention this here in the 2.3a release, the default
2895 %destructor's and %printer's were experimental, and they were rewritten in
2898 ** Except for LALR(1) parsers in C with POSIX Yacc emulation enabled (with "-y",
2899 "--yacc", or "%yacc"), Bison no longer generates #define statements for
2900 associating token numbers with token names. Removing the #define statements
2901 helps to sanitize the global namespace during preprocessing, but POSIX Yacc
2902 requires them. Bison still generates an enum for token names in all cases.
2904 ** Handling of traditional Yacc prologue blocks is now more consistent but
2905 potentially incompatible with previous releases of Bison.
2907 As before, you declare prologue blocks in your grammar file with the
2908 "%{ ... %}" syntax. To generate the pre-prologue, Bison concatenates all
2909 prologue blocks that you've declared before the first %union. To generate
2910 the post-prologue, Bison concatenates all prologue blocks that you've
2911 declared after the first %union.
2913 Previous releases of Bison inserted the pre-prologue into both the header
2914 file and the code file in all cases except for LALR(1) parsers in C. In the
2915 latter case, Bison inserted it only into the code file. For parsers in C++,
2916 the point of insertion was before any token definitions (which associate
2917 token numbers with names). For parsers in C, the point of insertion was
2918 after the token definitions.
2920 Now, Bison never inserts the pre-prologue into the header file. In the code
2921 file, it always inserts it before the token definitions.
2923 ** Bison now provides a more flexible alternative to the traditional Yacc
2924 prologue blocks: %before-header, %start-header, %end-header, and
2927 For example, the following declaration order in the grammar file reflects the
2928 order in which Bison will output these code blocks. However, you are free to
2929 declare these code blocks in your grammar file in whatever order is most
2933 /* Bison treats this block like a pre-prologue block: it inserts it into
2934 * the code file before the contents of the header file. It does *not*
2935 * insert it into the header file. This is a good place to put
2936 * #include's that you want at the top of your code file. A common
2937 * example is '#include "system.h"'. */
2940 /* Bison inserts this block into both the header file and the code file.
2941 * In both files, the point of insertion is before any Bison-generated
2942 * token, semantic type, location type, and class definitions. This is a
2943 * good place to define %union dependencies, for example. */
2946 /* Unlike the traditional Yacc prologue blocks, the output order for the
2947 * new %*-header blocks is not affected by their declaration position
2948 * relative to any %union in the grammar file. */
2951 /* Bison inserts this block into both the header file and the code file.
2952 * In both files, the point of insertion is after the Bison-generated
2953 * definitions. This is a good place to declare or define public
2954 * functions or data structures that depend on the Bison-generated
2958 /* Bison treats this block like a post-prologue block: it inserts it into
2959 * the code file after the contents of the header file. It does *not*
2960 * insert it into the header file. This is a good place to declare or
2961 * define internal functions or data structures that depend on the
2962 * Bison-generated definitions. */
2965 If you have multiple occurrences of any one of the above declarations, Bison
2966 will concatenate the contents in declaration order.
2968 [Although we failed to mention this here in the 2.3a release, the prologue
2969 alternatives were experimental, and they were rewritten in future versions.]
2971 ** The option "--report=look-ahead" has been changed to "--report=lookahead".
2972 The old spelling still works, but is not documented and may be removed
2973 in a future release.
2975 * Changes in version 2.3, 2006-06-05:
2977 ** GLR grammars should now use "YYRECOVERING ()" instead of "YYRECOVERING",
2978 for compatibility with LALR(1) grammars.
2980 ** It is now documented that any definition of YYSTYPE or YYLTYPE should
2981 be to a type name that does not contain parentheses or brackets.
2983 * Changes in version 2.2, 2006-05-19:
2985 ** The distribution terms for all Bison-generated parsers now permit
2986 using the parsers in nonfree programs. Previously, this permission
2987 was granted only for Bison-generated LALR(1) parsers in C.
2989 ** %name-prefix changes the namespace name in C++ outputs.
2991 ** The C++ parsers export their token_type.
2993 ** Bison now allows multiple %union declarations, and concatenates
2994 their contents together.
2996 ** New warning: unused values
2997 Right-hand side symbols whose values are not used are reported,
2998 if the symbols have destructors. For instance:
3000 exp: exp "?" exp ":" exp { $1 ? $1 : $3; }
3004 will trigger a warning about $$ and $5 in the first rule, and $3 in
3005 the second ($1 is copied to $$ by the default rule). This example
3006 most likely contains three errors, and could be rewritten as:
3008 exp: exp "?" exp ":" exp
3009 { $$ = $1 ? $3 : $5; free ($1 ? $5 : $3); free ($1); }
3011 { $$ = $1 ? $1 : $3; if ($1) free ($3); }
3014 However, if the original actions were really intended, memory leaks
3015 and all, the warnings can be suppressed by letting Bison believe the
3016 values are used, e.g.:
3018 exp: exp "?" exp ":" exp { $1 ? $1 : $3; (void) ($$, $5); }
3019 | exp "+" exp { $$ = $1; (void) $3; }
3022 If there are midrule actions, the warning is issued if no action
3023 uses it. The following triggers no warning: $1 and $3 are used.
3025 exp: exp { push ($1); } '+' exp { push ($3); sum (); };
3027 The warning is intended to help catching lost values and memory leaks.
3028 If a value is ignored, its associated memory typically is not reclaimed.
3030 ** %destructor vs. YYABORT, YYACCEPT, and YYERROR.
3031 Destructors are now called when user code invokes YYABORT, YYACCEPT,
3032 and YYERROR, for all objects on the stack, other than objects
3033 corresponding to the right-hand side of the current rule.
3035 ** %expect, %expect-rr
3036 Incorrect numbers of expected conflicts are now actual errors,
3037 instead of warnings.
3039 ** GLR, YACC parsers.
3040 The %parse-params are available in the destructors (and the
3041 experimental printers) as per the documentation.
3043 ** Bison now warns if it finds a stray "$" or "@" in an action.
3045 ** %require "VERSION"
3046 This specifies that the grammar file depends on features implemented
3047 in Bison version VERSION or higher.
3049 ** lalr1.cc: The token and value types are now class members.
3050 The tokens were defined as free form enums and cpp macros. YYSTYPE
3051 was defined as a free form union. They are now class members:
3052 tokens are enumerations of the "yy::parser::token" struct, and the
3053 semantic values have the "yy::parser::semantic_type" type.
3055 If you do not want or can update to this scheme, the directive
3056 '%define "global_tokens_and_yystype" "1"' triggers the global
3057 definition of tokens and YYSTYPE. This change is suitable both
3058 for previous releases of Bison, and this one.
3060 If you wish to update, then make sure older version of Bison will
3061 fail using '%require "2.2"'.
3063 ** DJGPP support added.
3065 * Changes in version 2.1, 2005-09-16:
3067 ** The C++ lalr1.cc skeleton supports %lex-param.
3069 ** Bison-generated parsers now support the translation of diagnostics like
3070 "syntax error" into languages other than English. The default
3071 language is still English. For details, please see the new
3072 Internationalization section of the Bison manual. Software
3073 distributors should also see the new PACKAGING file. Thanks to
3074 Bruno Haible for this new feature.
3076 ** Wording in the Bison-generated parsers has been changed slightly to
3077 simplify translation. In particular, the message "memory exhausted"
3078 has replaced "parser stack overflow", as the old message was not
3079 always accurate for modern Bison-generated parsers.
3081 ** Destructors are now called when the parser aborts, for all symbols left
3082 behind on the stack. Also, the start symbol is now destroyed after a
3083 successful parse. In both cases, the behavior was formerly inconsistent.
3085 ** When generating verbose diagnostics, Bison-generated parsers no longer
3086 quote the literal strings associated with tokens. For example, for
3087 a syntax error associated with '%token NUM "number"' they might
3088 print 'syntax error, unexpected number' instead of 'syntax error,
3089 unexpected "number"'.
3091 * Changes in version 2.0, 2004-12-25:
3093 ** Possibly-incompatible changes
3095 - Bison-generated parsers no longer default to using the alloca function
3096 (when available) to extend the parser stack, due to widespread
3097 problems in unchecked stack-overflow detection. You can "#define
3098 YYSTACK_USE_ALLOCA 1" to require the use of alloca, but please read
3099 the manual to determine safe values for YYMAXDEPTH in that case.
3101 - Error token location.
3102 During error recovery, the location of the syntax error is updated
3103 to cover the whole sequence covered by the error token: it includes
3104 the shifted symbols thrown away during the first part of the error
3105 recovery, and the lookahead rejected during the second part.
3107 - Semicolon changes:
3108 . Stray semicolons are no longer allowed at the start of a grammar.
3109 . Semicolons are now required after in-grammar declarations.
3111 - Unescaped newlines are no longer allowed in character constants or
3112 string literals. They were never portable, and GCC 3.4.0 has
3113 dropped support for them. Better diagnostics are now generated if
3114 forget a closing quote.
3116 - NUL bytes are no longer allowed in Bison string literals, unfortunately.
3120 - GLR grammars now support locations.
3122 - New directive: %initial-action.
3123 This directive allows the user to run arbitrary code (including
3124 initializing @$) from yyparse before parsing starts.
3126 - A new directive "%expect-rr N" specifies the expected number of
3127 reduce/reduce conflicts in GLR parsers.
3129 - %token numbers can now be hexadecimal integers, e.g., "%token FOO 0x12d".
3130 This is a GNU extension.
3132 - The option "--report=lookahead" was changed to "--report=look-ahead".
3133 [However, this was changed back after 2.3.]
3135 - Experimental %destructor support has been added to lalr1.cc.
3137 - New configure option --disable-yacc, to disable installation of the
3138 yacc command and -ly library introduced in 1.875 for POSIX conformance.
3142 - For now, %expect-count violations are now just warnings, not errors.
3143 This is for compatibility with Bison 1.75 and earlier (when there are
3144 reduce/reduce conflicts) and with Bison 1.30 and earlier (when there
3145 are too many or too few shift/reduce conflicts). However, in future
3146 versions of Bison we plan to improve the %expect machinery so that
3147 these violations will become errors again.
3149 - Within Bison itself, numbers (e.g., goto numbers) are no longer
3150 arbitrarily limited to 16-bit counts.
3152 - Semicolons are now allowed before "|" in grammar rules, as POSIX requires.
3154 * Changes in version 1.875, 2003-01-01:
3156 ** The documentation license has been upgraded to version 1.2
3157 of the GNU Free Documentation License.
3159 ** syntax error processing
3161 - In Yacc-style parsers YYLLOC_DEFAULT is now used to compute error
3162 locations too. This fixes bugs in error-location computation.
3165 It is now possible to reclaim the memory associated to symbols
3166 discarded during error recovery. This feature is still experimental.
3169 This new directive is preferred over YYERROR_VERBOSE.
3171 - #defining yyerror to steal internal variables is discouraged.
3172 It is not guaranteed to work forever.
3174 ** POSIX conformance
3176 - Semicolons are once again optional at the end of grammar rules.
3177 This reverts to the behavior of Bison 1.33 and earlier, and improves
3178 compatibility with Yacc.
3180 - "parse error" -> "syntax error"
3181 Bison now uniformly uses the term "syntax error"; formerly, the code
3182 and manual sometimes used the term "parse error" instead. POSIX
3183 requires "syntax error" in diagnostics, and it was thought better to
3186 - The documentation now emphasizes that yylex and yyerror must be
3187 declared before use. C99 requires this.
3189 - Bison now parses C99 lexical constructs like UCNs and
3190 backslash-newline within C escape sequences, as POSIX 1003.1-2001 requires.
3192 - File names are properly escaped in C output. E.g., foo\bar.y is
3193 output as "foo\\bar.y".
3195 - Yacc command and library now available
3196 The Bison distribution now installs a "yacc" command, as POSIX requires.
3197 Also, Bison now installs a small library liby.a containing
3198 implementations of Yacc-compatible yyerror and main functions.
3199 This library is normally not useful, but POSIX requires it.
3201 - Type clashes now generate warnings, not errors.
3203 - If the user does not define YYSTYPE as a macro, Bison now declares it
3204 using typedef instead of defining it as a macro.
3205 For consistency, YYLTYPE is also declared instead of defined.
3207 ** Other compatibility issues
3209 - %union directives can now have a tag before the "{", e.g., the
3210 directive "%union foo {...}" now generates the C code
3211 "typedef union foo { ... } YYSTYPE;"; this is for Yacc compatibility.
3212 The default union tag is "YYSTYPE", for compatibility with Solaris 9 Yacc.
3213 For consistency, YYLTYPE's struct tag is now "YYLTYPE" not "yyltype".
3214 This is for compatibility with both Yacc and Bison 1.35.
3216 - ";" is output before the terminating "}" of an action, for
3217 compatibility with Bison 1.35.
3219 - Bison now uses a Yacc-style format for conflict reports, e.g.,
3220 "conflicts: 2 shift/reduce, 1 reduce/reduce".
3222 - "yystype" and "yyltype" are now obsolescent macros instead of being
3223 typedefs or tags; they are no longer documented and are planned to be
3224 withdrawn in a future release.
3229 Users of Bison have to decide how they handle the portability of the
3232 - "parsing stack overflow..." -> "parser stack overflow"
3233 GLR parsers now report "parser stack overflow" as per the Bison manual.
3235 ** %parse-param and %lex-param
3236 The macros YYPARSE_PARAM and YYLEX_PARAM provide a means to pass
3237 additional context to yyparse and yylex. They suffer from several
3240 - a single argument only can be added,
3241 - their types are weak (void *),
3242 - this context is not passed to ancillary functions such as yyerror,
3243 - only yacc.c parsers support them.
3245 The new %parse-param/%lex-param directives provide a more precise control.
3248 %parse-param {int *nastiness}
3249 %lex-param {int *nastiness}
3250 %parse-param {int *randomness}
3252 results in the following signatures:
3254 int yylex (int *nastiness);
3255 int yyparse (int *nastiness, int *randomness);
3257 or, if both %pure-parser and %locations are used:
3259 int yylex (YYSTYPE *lvalp, YYLTYPE *llocp, int *nastiness);
3260 int yyparse (int *nastiness, int *randomness);
3262 ** Bison now warns if it detects conflicting outputs to the same file,
3263 e.g., it generates a warning for "bison -d -o foo.h foo.y" since
3264 that command outputs both code and header to foo.h.
3266 ** #line in output files
3267 - --no-line works properly.
3269 ** Bison can no longer be built by a K&R C compiler; it requires C89 or
3270 later to be built. This change originally took place a few versions
3271 ago, but nobody noticed until we recently asked someone to try
3272 building Bison with a K&R C compiler.
3274 * Changes in version 1.75, 2002-10-14:
3276 ** Bison should now work on 64-bit hosts.
3278 ** Indonesian translation thanks to Tedi Heriyanto.
3281 Fix spurious parse errors.
3284 Some people redefine yyerror to steal yyparse' private variables.
3285 Reenable this trick until an official feature replaces it.
3288 In agreement with POSIX and with other Yaccs, leaving a default
3289 action is valid when $$ is untyped, and $1 typed:
3293 but the converse remains an error:
3297 ** Values of midrule actions
3300 foo: { ... } { $$ = $1; } ...
3302 was incorrectly rejected: $1 is defined in the second midrule
3303 action, and is equal to the $$ of the first midrule action.
3305 * Changes in version 1.50, 2002-10-04:
3310 causes Bison to produce a Generalized LR (GLR) parser, capable of handling
3311 almost any context-free grammar, ambiguous or not. The new declarations
3312 %dprec and %merge on grammar rules allow parse-time resolution of
3313 ambiguities. Contributed by Paul Hilfinger.
3315 Unfortunately Bison 1.50 does not work properly on 64-bit hosts
3316 like the Alpha, so please stick to 32-bit hosts for now.
3319 When not in Yacc compatibility mode, when the output file was not
3320 specified, running "bison foo/bar.y" created "foo/bar.c". It
3321 now creates "bar.c".
3324 The undefined token was systematically mapped to 2 which prevented
3325 the use of 2 by the user. This is no longer the case.
3327 ** Unknown token numbers
3328 If yylex returned an out of range value, yyparse could die. This is
3332 According to POSIX, the error token must be 256.
3333 Bison extends this requirement by making it a preference: *if* the
3334 user specified that one of her tokens is numbered 256, then error
3335 will be mapped onto another number.
3337 ** Verbose error messages
3338 They no longer report "..., expecting error or..." for states where
3339 error recovery is possible.
3342 Defaults to "$end" instead of "$".
3344 ** Error recovery now conforms to documentation and to POSIX
3345 When a Bison-generated parser encounters a syntax error, it now pops
3346 the stack until it finds a state that allows shifting the error
3347 token. Formerly, it popped the stack until it found a state that
3348 allowed some non-error action other than a default reduction on the
3349 error token. The new behavior has long been the documented behavior,
3350 and has long been required by POSIX. For more details, please see
3351 Paul Eggert, "Reductions during Bison error handling" (2002-05-20)
3352 <http://lists.gnu.org/archive/html/bug-bison/2002-05/msg00038.html>.
3355 Popped tokens and nonterminals are now reported.
3358 Larger grammars are now supported (larger token numbers, larger grammar
3359 size (= sum of the LHS and RHS lengths), larger LALR tables).
3360 Formerly, many of these numbers ran afoul of 16-bit limits;
3361 now these limits are 32 bits on most hosts.
3363 ** Explicit initial rule
3364 Bison used to play hacks with the initial rule, which the user does
3365 not write. It is now explicit, and visible in the reports and
3369 Before, Bison reported the useless rules, but, although not used,
3370 included them in the parsers. They are now actually removed.
3372 ** Useless rules, useless nonterminals
3373 They are now reported, as a warning, with their locations.
3375 ** Rules never reduced
3376 Rules that can never be reduced because of conflicts are now
3379 ** Incorrect "Token not used"
3380 On a grammar such as
3382 %token useless useful
3384 exp: '0' %prec useful;
3386 where a token was used to set the precedence of the last rule,
3387 bison reported both "useful" and "useless" as useless tokens.
3389 ** Revert the C++ namespace changes introduced in 1.31
3390 as they caused too many portability hassles.
3392 ** Default locations
3393 By an accident of design, the default computation of @$ was
3394 performed after another default computation was performed: @$ = @1.
3395 The latter is now removed: YYLLOC_DEFAULT is fully responsible of
3396 the computation of @$.
3398 ** Token end-of-file
3399 The token end of file may be specified by the user, in which case,
3400 the user symbol is used in the reports, the graphs, and the verbose
3401 error messages instead of "$end", which remains being the default.
3405 %token MYEOF 0 "end of file"
3408 This old option, which has been broken for ages, is removed.
3411 Brazilian Portuguese, thanks to Alexandre Folle de Menezes.
3412 Croatian, thanks to Denis Lackovic.
3414 ** Incorrect token definitions
3417 bison used to output
3420 ** Token definitions as enums
3421 Tokens are output both as the traditional #define's, and, provided
3422 the compiler supports ANSI C or is a C++ compiler, as enums.
3423 This lets debuggers display names instead of integers.
3426 In addition to --verbose, bison supports --report=THINGS, which
3427 produces additional information:
3429 complete the core item sets with their closure
3430 - lookahead [changed to "look-ahead" in 1.875e through 2.3, but changed back]
3431 explicitly associate lookahead tokens to items
3433 describe shift/reduce conflicts solving.
3434 Bison used to systematically output this information on top of
3435 the report. Solved conflicts are now attached to their states.
3438 Previous versions don't complain when there is a type clash on
3439 the default action if the rule has a midrule action, such as in:
3447 ** GNU M4 is now required when using Bison.
3449 * Changes in version 1.35, 2002-03-25:
3452 Some projects use Bison's C parser with C++ compilers, and define
3453 YYSTYPE as a class. The recent adjustment of C parsers for data
3454 alignment and 64 bit architectures made this impossible.
3456 Because for the time being no real solution for C++ parser
3457 generation exists, kludges were implemented in the parser to
3458 maintain this use. In the future, when Bison has C++ parsers, this
3459 kludge will be disabled.
3461 This kludge also addresses some C++ problems when the stack was
3464 * Changes in version 1.34, 2002-03-12:
3466 ** File name clashes are detected
3467 $ bison foo.y -d -o foo.x
3468 fatal error: header and parser would both be named "foo.x"
3470 ** A missing ";" at the end of a rule triggers a warning
3471 In accordance with POSIX, and in agreement with other
3472 Yacc implementations, Bison will mandate this semicolon in the near
3473 future. This eases the implementation of a Bison parser of Bison
3474 grammars by making this grammar LALR(1) instead of LR(2). To
3475 facilitate the transition, this release introduces a warning.
3477 ** Revert the C++ namespace changes introduced in 1.31, as they caused too
3478 many portability hassles.
3480 ** DJGPP support added.
3482 ** Fix test suite portability problems.
3484 * Changes in version 1.33, 2002-02-07:
3487 Groff could not be compiled for the definition of size_t was lacking
3488 under some conditions.
3493 * Changes in version 1.32, 2002-01-23:
3495 ** Fix Yacc output file names
3497 ** Portability fixes
3499 ** Italian, Dutch translations
3501 * Changes in version 1.31, 2002-01-14:
3505 ** GNU Gettext and %expect
3506 GNU Gettext asserts 10 s/r conflicts, but there are 7. Now that
3507 Bison dies on incorrect %expectations, we fear there will be
3508 too many bug reports for Gettext, so _for the time being_, %expect
3509 does not trigger an error when the input file is named "plural.y".
3511 ** Use of alloca in parsers
3512 If YYSTACK_USE_ALLOCA is defined to 0, then the parsers will use
3513 malloc exclusively. Since 1.29, but was not NEWS'ed.
3515 alloca is used only when compiled with GCC, to avoid portability
3518 ** yyparse now returns 2 if memory is exhausted; formerly it dumped core.
3520 ** When the generated parser lacks debugging code, YYDEBUG is now 0
3521 (as POSIX requires) instead of being undefined.
3524 Bison has always permitted actions such as { $$ = $1 }: it adds the
3525 ending semicolon. Now if in Yacc compatibility mode, the semicolon
3526 is no longer output: one has to write { $$ = $1; }.
3528 ** Better C++ compliance
3529 The output parsers try to respect C++ namespaces.
3530 [This turned out to be a failed experiment, and it was reverted later.]
3533 Fixed bugs when reporting useless nonterminals.
3536 The parsers work properly on 64 bit hosts.
3539 Some calls to strerror resulted in scrambled or missing error messages.
3542 When the number of shift/reduce conflicts is correct, don't issue
3545 ** The verbose report includes the rule line numbers.
3547 ** Rule line numbers are fixed in traces.
3549 ** Swedish translation
3552 Verbose parse error messages from the parsers are better looking.
3553 Before: parse error: unexpected `'/'', expecting `"number"' or `'-'' or `'(''
3554 Now: parse error: unexpected '/', expecting "number" or '-' or '('
3556 ** Fixed parser memory leaks.
3557 When the generated parser was using malloc to extend its stacks, the
3558 previous allocations were not freed.
3560 ** Fixed verbose output file.
3561 Some newlines were missing.
3562 Some conflicts in state descriptions were missing.
3564 ** Fixed conflict report.
3565 Option -v was needed to get the result.
3569 Mismatches are errors, not warnings.
3571 ** Fixed incorrect processing of some invalid input.
3573 ** Fixed CPP guards: 9foo.h uses BISON_9FOO_H instead of 9FOO_H.
3575 ** Fixed some typos in the documentation.
3577 ** %token MY_EOF 0 is supported.
3578 Before, MY_EOF was silently renumbered as 257.
3580 ** doc/refcard.tex is updated.
3582 ** %output, %file-prefix, %name-prefix.
3586 New, aliasing "--output-file".
3588 * Changes in version 1.30, 2001-10-26:
3590 ** "--defines" and "--graph" have now an optional argument which is the
3591 output file name. "-d" and "-g" do not change; they do not take any
3594 ** "%source_extension" and "%header_extension" are removed, failed
3597 ** Portability fixes.
3599 * Changes in version 1.29, 2001-09-07:
3601 ** The output file does not define const, as this caused problems when used
3602 with common autoconfiguration schemes. If you still use ancient compilers
3603 that lack const, compile with the equivalent of the C compiler option
3604 "-Dconst=". Autoconf's AC_C_CONST macro provides one way to do this.
3606 ** Added "-g" and "--graph".
3608 ** The Bison manual is now distributed under the terms of the GNU FDL.
3610 ** The input and the output files has automatically a similar extension.
3612 ** Russian translation added.
3614 ** NLS support updated; should hopefully be less troublesome.
3616 ** Added the old Bison reference card.
3618 ** Added "--locations" and "%locations".
3620 ** Added "-S" and "--skeleton".
3622 ** "%raw", "-r", "--raw" is disabled.
3624 ** Special characters are escaped when output. This solves the problems
3625 of the #line lines with path names including backslashes.
3628 "%yacc", "%fixed_output_files", "%defines", "%no_parser", "%verbose",
3629 "%debug", "%source_extension" and "%header_extension".
3632 Automatic location tracking.
3634 * Changes in version 1.28, 1999-07-06:
3636 ** Should compile better now with K&R compilers.
3640 ** Fixed a problem with escaping the double quote character.
3642 ** There is now a FAQ.
3644 * Changes in version 1.27:
3646 ** The make rule which prevented bison.simple from being created on
3647 some systems has been fixed.
3649 * Changes in version 1.26:
3651 ** Bison now uses Automake.
3653 ** New mailing lists: <bug-bison@gnu.org> and <help-bison@gnu.org>.
3655 ** Token numbers now start at 257 as previously documented, not 258.
3657 ** Bison honors the TMPDIR environment variable.
3659 ** A couple of buffer overruns have been fixed.
3661 ** Problems when closing files should now be reported.
3663 ** Generated parsers should now work even on operating systems which do
3664 not provide alloca().
3666 * Changes in version 1.25, 1995-10-16:
3668 ** Errors in the input grammar are not fatal; Bison keeps reading
3669 the grammar file, and reports all the errors found in it.
3671 ** Tokens can now be specified as multiple-character strings: for
3672 example, you could use "<=" for a token which looks like <=, instead
3673 of choosing a name like LESSEQ.
3675 ** The %token_table declaration says to write a table of tokens (names
3676 and numbers) into the parser file. The yylex function can use this
3677 table to recognize multiple-character string tokens, or for other
3680 ** The %no_lines declaration says not to generate any #line preprocessor
3681 directives in the parser file.
3683 ** The %raw declaration says to use internal Bison token numbers, not
3684 Yacc-compatible token numbers, when token names are defined as macros.
3686 ** The --no-parser option produces the parser tables without including
3687 the parser engine; a project can now use its own parser engine.
3688 The actions go into a separate file called NAME.act, in the form of
3689 a switch statement body.
3691 * Changes in version 1.23:
3693 The user can define YYPARSE_PARAM as the name of an argument to be
3694 passed into yyparse. The argument should have type void *. It should
3695 actually point to an object. Grammar actions can access the variable
3696 by casting it to the proper pointer type.
3698 Line numbers in output file corrected.
3700 * Changes in version 1.22:
3702 --help option added.
3704 * Changes in version 1.20:
3706 Output file does not redefine const for C++.
3710 Copyright (C) 1995-2015, 2018-2019 Free Software Foundation, Inc.
3712 This file is part of Bison, the GNU Parser Generator.
3714 This program is free software: you can redistribute it and/or modify
3715 it under the terms of the GNU General Public License as published by
3716 the Free Software Foundation, either version 3 of the License, or
3717 (at your option) any later version.
3719 This program is distributed in the hope that it will be useful,
3720 but WITHOUT ANY WARRANTY; without even the implied warranty of
3721 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3722 GNU General Public License for more details.
3724 You should have received a copy of the GNU General Public License
3725 along with this program. If not, see <http://www.gnu.org/licenses/>.
3727 LocalWords: yacc YYBACKUP glr GCC lalr ArrayIndexOutOfBoundsException nullptr
3728 LocalWords: cplusplus liby rpl fprintf mfcalc Wyacc stmt cond expr mk sym lr
3729 LocalWords: IELR ielr Lookahead YYERROR nonassoc LALR's api lookaheads yychar
3730 LocalWords: destructor lookahead YYRHSLOC YYLLOC Rhs ifndef YYFAIL cpp sr rr
3731 LocalWords: preprocessor initializer Wno Wnone Werror FreeBSD prec livelocks
3732 LocalWords: Solaris AIX UX RHEL Tru LHS gcc's Wundef YYENABLE NLS YYLTYPE VCG
3733 LocalWords: yyerror cpp's Wunused yylval yylloc prepend yyparse yylex yypush
3734 LocalWords: Graphviz xml nonterminals midrule destructor's YYSTYPE typedef ly
3735 LocalWords: CHR chr printf stdout namespace preprocessing enum pre include's
3736 LocalWords: YYRECOVERING nonfree destructors YYABORT YYACCEPT params enums de
3737 LocalWords: struct yystype DJGPP lex param Haible NUM alloca YYSTACK NUL goto
3738 LocalWords: YYMAXDEPTH Unescaped UCNs YYLTYPE's yyltype typedefs inline Yaccs
3739 LocalWords: Heriyanto Reenable dprec Hilfinger Eggert MYEOF Folle Menezes EOF
3740 LocalWords: Lackovic define's itemset Groff Gettext malloc NEWS'ed YYDEBUG YY
3741 LocalWords: namespaces strerror const autoconfiguration Dconst Autoconf's FDL
3742 LocalWords: Automake TMPDIR LESSEQ ylwrap endif yydebug YYTOKEN YYLSP ival hh
3743 LocalWords: extern YYTOKENTYPE TOKENTYPE yytokentype tokentype STYPE lval pdf
3744 LocalWords: lang yyoutput dvi html ps POSIX lvalp llocp Wother nterm arg init
3745 LocalWords: TOK calc yyo fval Wconflicts parsers yystackp yyval yynerrs
3746 LocalWords: Théophile Ranquet Santet fno fnone stype associativity Tolmer
3747 LocalWords: Wprecedence Rassoul Wempty Paolo Bonzini parser's Michiel loc
3748 LocalWords: redeclaration sval fcaret reentrant XSLT xsl Wmaybe yyvsp Tedi
3749 LocalWords: pragmas noreturn untyped Rozenman unexpanded Wojciech Polak
3750 LocalWords: Alexandre MERCHANTABILITY yytype emplace ptr automove lvalues
3751 LocalWords: nonterminal yy args Pragma dereference yyformat rhs docdir bw
3752 LocalWords: Redeclarations rpcalc Autoconf YFLAGS Makefiles PROG DECL num
3753 LocalWords: Heimbigner AST src ast Makefile srcdir MinGW xxlex XXSTYPE
3754 LocalWords: XXLTYPE strictfp IDEs ffixit fdiagnostics parseable fixits
3755 LocalWords: Wdeprecated yytext Variadic variadic yyrhs yyphrs RCS README
3756 LocalWords: noexcept constexpr ispell american deprecations backend
3759 ispell-dictionary: "american"