4 * Changes in version 2.5 (????-??-??):
8 Historically, Yacc and Bison have supported positional references
9 ($n, $$) to allow access to symbol values from inside of semantic
12 Starting from this version, Bison can also accept named references.
13 When no ambiguity is possible, original symbol names may be used
16 if_stmt : 'if' cond_expr 'then' then_stmt ';'
17 { $if_stmt = mk_if_stmt($cond_expr, $then_stmt); }
19 In the more common case, explicit names may be declared:
21 stmt[res] : 'if' expr[cond] 'then' stmt[then] 'else' stmt[else] ';'
22 { $res = mk_if_stmt($cond, $then, $else); }
24 Location information is also accessible using @name syntax. When
25 accessing symbol names containing dots or dashes, explicit bracketing
26 ($[sym.1]) must be used.
28 These features are experimental in this version. More user feedback
29 will help to stabilize them.
31 ** IELR(1) and canonical LR(1):
33 IELR(1) is a minimal LR(1) parser table generation algorithm. That
34 is, given any context-free grammar, IELR(1) generates parser tables
35 with the full language recognition power of canonical LR(1) but with
36 nearly the same number of parser states as LALR(1). This reduction
37 in parser states is often an order of magnitude. More importantly,
38 because canonical LR(1)'s extra parser states may contain duplicate
39 conflicts in the case of non-LR(1) grammars, the number of conflicts
40 for IELR(1) is often an order of magnitude less as well. This can
41 significantly reduce the complexity of developing of a grammar.
43 Bison can now generate IELR(1) and canonical LR(1) parser tables in
44 place of its traditional LALR(1) parser tables, which remain the
45 default. You can specify the type of parser tables in the grammar
46 file with these directives:
50 %define lr.type canonical-lr
52 The default reduction optimization in the parser tables can also be
53 adjusted using `%define lr.default-reductions'. See the documentation
54 for `%define lr.type' and `%define lr.default-reductions' in the
55 section `Bison Declaration Summary' in the Bison manual for the
58 These features are experimental. More user feedback will help to
61 ** LAC (lookahead correction) for syntax error handling:
63 Canonical LR, IELR, and LALR can suffer from a couple of problems
64 upon encountering a syntax error. First, the parser might perform
65 additional parser stack reductions before discovering the syntax
66 error. Such reductions perform user semantic actions that are
67 unexpected because they are based on an invalid token, and they
68 cause error recovery to begin in a different syntactic context than
69 the one in which the invalid token was encountered. Second, when
70 verbose error messages are enabled (with %error-verbose or `#define
71 YYERROR_VERBOSE'), the expected token list in the syntax error
72 message can both contain invalid tokens and omit valid tokens.
74 The culprits for the above problems are %nonassoc, default
75 reductions in inconsistent states, and parser state merging. Thus,
76 IELR and LALR suffer the most. Canonical LR can suffer only if
77 %nonassoc is used or if default reductions are enabled for
80 LAC is a new mechanism within the parsing algorithm that completely
81 solves these problems for canonical LR, IELR, and LALR without
82 sacrificing %nonassoc, default reductions, or state mering. When
83 LAC is in use, canonical LR and IELR behave exactly the same for
84 both syntactically acceptable and syntactically unacceptable input.
85 While LALR still does not support the full language-recognition
86 power of canonical LR and IELR, LAC at least enables LALR's syntax
87 error handling to correctly reflect LALR's language-recognition
90 Currently, LAC is only supported for deterministic parsers in C.
91 You can enable LAC with the following directive:
93 %define parse.lac full
95 See the documentation for `%define parse.lac' in the section `Bison
96 Declaration Summary' in the Bison manual for additional details.
98 LAC is an experimental feature. More user feedback will help to
101 ** Grammar symbol names can now contain dashes:
103 Consistently with directives (such as %error-verbose) and variables
104 (e.g. push-pull), grammar symbol names may include dashes in any
105 position, similarly to periods and underscores. This is GNU
106 extension over POSIX Yacc whose use is reported by -Wyacc, and
107 rejected in Yacc mode (--yacc).
109 ** %define improvements:
111 *** Can now be invoked via the command line:
113 Each of these command-line options
116 --define=NAME[=VALUE]
119 --force-define=NAME[=VALUE]
121 is equivalent to this grammar file declaration
123 %define NAME ["VALUE"]
125 except that the manner in which Bison processes multiple definitions
126 for the same NAME differs. Most importantly, -F and --force-define
127 quietly override %define, but -D and --define do not. For further
128 details, see the section "Bison Options" in the Bison manual.
130 *** Variables renamed:
132 The following %define variables
135 lr.keep_unreachable_states
140 lr.keep-unreachable-states
142 The old names are now deprecated but will be maintained indefinitely
143 for backward compatibility.
145 *** Values no longer need to be quoted in grammar file:
147 If a %define value is an identifier, it no longer needs to be placed
148 within quotations marks. For example,
150 %define api.push-pull "push"
154 %define api.push-pull push
156 *** Unrecognized variables are now errors not warnings.
158 *** Multiple invocations for any variable is now an error not a warning.
160 ** Unrecognized %code qualifiers are now errors not warnings.
162 ** Character literals not of length one:
164 Previously, Bison quietly converted all character literals to length
165 one. For example, without warning, Bison interpreted the operators in
166 the following grammar to be the same token:
172 Bison now warns when a character literal is not of length one. In
173 some future release, Bison will start reporting an error instead.
175 ** Destructor calls fixed for lookaheads altered in semantic actions:
177 Previously for deterministic parsers in C, if a user semantic action
178 altered yychar, the parser in some cases used the old yychar value to
179 determine which destructor to call for the lookahead upon a syntax
180 error or upon parser return. This bug has been fixed.
182 ** C++ parsers use YYRHSLOC:
184 Similarly to the C parsers, the C++ parsers now define the YYRHSLOC
185 macro and use it in the default YYLLOC_DEFAULT. You are encouraged
186 to use it. If, for instance, your location structure has "first"
187 and "last" members, instead of
189 # define YYLLOC_DEFAULT(Current, Rhs, N) \
193 (Current).first = (Rhs)[1].location.first; \
194 (Current).last = (Rhs)[N].location.last; \
198 (Current).first = (Current).last = (Rhs)[0].location.last; \
204 # define YYLLOC_DEFAULT(Current, Rhs, N) \
208 (Current).first = YYRHSLOC (Rhs, 1).first; \
209 (Current).last = YYRHSLOC (Rhs, N).last; \
213 (Current).first = (Current).last = YYRHSLOC (Rhs, 0).last; \
217 ** YYLLOC_DEFAULT in C++:
219 The default implementation of YYLLOC_DEFAULT used to be issued in
220 the header file. It is now output in the implementation file, after
221 the user %code sections so that its #ifndef guard does not try to
222 override the user's YYLLOC_DEFAULT if provided.
224 ** YYFAIL now produces warnings and Java parsers no longer implement it:
226 YYFAIL has existed for many years as an undocumented feature of
227 deterministic parsers in C generated by Bison. More recently, it was
228 a documented feature of Bison's experimental Java parsers. As
229 promised in Bison 2.4.2's NEWS entry, any appearance of YYFAIL in a
230 semantic action now produces a deprecation warning, and Java parsers
231 no longer implement YYFAIL at all. For further details, including a
232 discussion of how to suppress C preprocessor warnings about YYFAIL
233 being unused, see the Bison 2.4.2 NEWS entry.
235 ** Temporary hack for adding a semicolon to the user action:
237 Previously, Bison appended a semicolon to every user action for
238 reductions when the output language defaulted to C (specifically, when
239 neither %yacc, %language, %skeleton, or equivalent command-line
240 options were specified). This allowed actions such as
242 exp: exp "+" exp { $$ = $1 + $3 };
246 exp: exp "+" exp { $$ = $1 + $3; };
248 As a first step in removing this misfeature, Bison now issues a
249 warning when it appends a semicolon. Moreover, in cases where Bison
250 cannot easily determine whether a semicolon is needed (for example, an
251 action ending with a cpp directive or a braced compound initializer),
252 it no longer appends one. Thus, the C compiler might now complain
253 about a missing semicolon where it did not before. Future releases of
254 Bison will cease to append semicolons entirely.
256 ** Verbose syntax error message fixes:
258 When %error-verbose or `#define YYERROR_VERBOSE' is specified,
259 syntax error messages produced by the generated parser include the
260 unexpected token as well as a list of expected tokens. The effect
261 of %nonassoc on these verbose messages has been corrected in two
262 ways, but a complete fix requires LAC, described above:
264 *** When %nonassoc is used, there can exist parser states that accept no
265 tokens, and so the parser does not always require a lookahead token
266 in order to detect a syntax error. Because no unexpected token or
267 expected tokens can then be reported, the verbose syntax error
268 message described above is suppressed, and the parser instead
269 reports the simpler message, "syntax error". Previously, this
270 suppression was sometimes erroneously triggered by %nonassoc when a
271 lookahead was actually required. Now verbose messages are
272 suppressed only when all previous lookaheads have already been
273 shifted or discarded.
275 *** Previously, the list of expected tokens erroneously included tokens
276 that would actually induce a syntax error because conflicts for them
277 were resolved with %nonassoc in the current parser state. Such
278 tokens are now properly omitted from the list.
280 *** Expected token lists are still often wrong due to state merging
281 (from LALR or IELR) and default reductions, which can both add
282 invalid tokens and subtract valid tokens. Canonical LR almost
283 completely fixes this problem by eliminating state merging and
284 default reductions. However, there is one minor problem left even
285 when using canonical LR and even after the fixes above. That is,
286 if the resolution of a conflict with %nonassoc appears in a later
287 parser state than the one at which some syntax error is
288 discovered, the conflicted token is still erroneously included in
289 the expected token list. Bison's new LAC implementation,
290 described above, eliminates this problem and the need for
291 canonical LR. However, LAC is still experimental and is disabled
294 * Changes in version 2.4.3 (2010-08-05):
296 ** Bison now obeys -Werror and --warnings=error for warnings about
297 grammar rules that are useless in the parser due to conflicts.
299 ** Problems with spawning M4 on at least FreeBSD 8 and FreeBSD 9 have
302 ** Failures in the test suite for GCC 4.5 have been fixed.
304 ** Failures in the test suite for some versions of Sun Studio C++ have
307 ** Contrary to Bison 2.4.2's NEWS entry, it has been decided that
308 warnings about undefined %prec identifiers will not be converted to
309 errors in Bison 2.5. They will remain warnings, which should be
310 sufficient for POSIX while avoiding backward compatibility issues.
312 ** Minor documentation fixes.
314 * Changes in version 2.4.2 (2010-03-20):
316 ** Some portability problems that resulted in failures and livelocks
317 in the test suite on some versions of at least Solaris, AIX, HP-UX,
318 RHEL4, and Tru64 have been addressed. As a result, fatal Bison
319 errors should no longer cause M4 to report a broken pipe on the
322 ** `%prec IDENTIFIER' requires IDENTIFIER to be defined separately.
324 POSIX specifies that an error be reported for any identifier that does
325 not appear on the LHS of a grammar rule and that is not defined by
326 %token, %left, %right, or %nonassoc. Bison 2.3b and later lost this
327 error report for the case when an identifier appears only after a
328 %prec directive. It is now restored. However, for backward
329 compatibility with recent Bison releases, it is only a warning for
330 now. In Bison 2.5 and later, it will return to being an error.
331 [Between the 2.4.2 and 2.4.3 releases, it was decided that this
332 warning will not be converted to an error in Bison 2.5.]
334 ** Detection of GNU M4 1.4.6 or newer during configure is improved.
336 ** Warnings from gcc's -Wundef option about undefined YYENABLE_NLS,
337 YYLTYPE_IS_TRIVIAL, and __STRICT_ANSI__ in C/C++ parsers are now
340 ** %code is now a permanent feature.
342 A traditional Yacc prologue directive is written in the form:
346 To provide a more flexible alternative, Bison 2.3b introduced the
347 %code directive with the following forms for C/C++:
350 %code requires {CODE}
351 %code provides {CODE}
354 These forms are now considered permanent features of Bison. See the
355 %code entries in the section "Bison Declaration Summary" in the Bison
356 manual for a summary of their functionality. See the section
357 "Prologue Alternatives" for a detailed discussion including the
358 advantages of %code over the traditional Yacc prologue directive.
360 Bison's Java feature as a whole including its current usage of %code
361 is still considered experimental.
363 ** YYFAIL is deprecated and will eventually be removed.
365 YYFAIL has existed for many years as an undocumented feature of
366 deterministic parsers in C generated by Bison. Previously, it was
367 documented for Bison's experimental Java parsers. YYFAIL is no longer
368 documented for Java parsers and is formally deprecated in both cases.
369 Users are strongly encouraged to migrate to YYERROR, which is
372 Like YYERROR, you can invoke YYFAIL from a semantic action in order to
373 induce a syntax error. The most obvious difference from YYERROR is
374 that YYFAIL will automatically invoke yyerror to report the syntax
375 error so that you don't have to. However, there are several other
376 subtle differences between YYERROR and YYFAIL, and YYFAIL suffers from
377 inherent flaws when %error-verbose or `#define YYERROR_VERBOSE' is
378 used. For a more detailed discussion, see:
380 http://lists.gnu.org/archive/html/bison-patches/2009-12/msg00024.html
382 The upcoming Bison 2.5 will remove YYFAIL from Java parsers, but
383 deterministic parsers in C will continue to implement it. However,
384 because YYFAIL is already flawed, it seems futile to try to make new
385 Bison features compatible with it. Thus, during parser generation,
386 Bison 2.5 will produce a warning whenever it discovers YYFAIL in a
387 rule action. In a later release, YYFAIL will be disabled for
388 %error-verbose and `#define YYERROR_VERBOSE'. Eventually, YYFAIL will
389 be removed altogether.
391 There exists at least one case where Bison 2.5's YYFAIL warning will
392 be a false positive. Some projects add phony uses of YYFAIL and other
393 Bison-defined macros for the sole purpose of suppressing C
394 preprocessor warnings (from GCC cpp's -Wunused-macros, for example).
395 To avoid Bison's future warning, such YYFAIL uses can be moved to the
396 epilogue (that is, after the second `%%') in the Bison input file. In
397 this release (2.4.2), Bison already generates its own code to suppress
398 C preprocessor warnings for YYFAIL, so projects can remove their own
399 phony uses of YYFAIL if compatibility with Bison releases prior to
400 2.4.2 is not necessary.
402 ** Internationalization.
404 Fix a regression introduced in Bison 2.4: Under some circumstances,
405 message translations were not installed although supported by the
408 * Changes in version 2.4.1 (2008-12-11):
410 ** In the GLR defines file, unexpanded M4 macros in the yylval and yylloc
411 declarations have been fixed.
413 ** Temporary hack for adding a semicolon to the user action.
415 Bison used to prepend a trailing semicolon at the end of the user
416 action for reductions. This allowed actions such as
418 exp: exp "+" exp { $$ = $1 + $3 };
422 exp: exp "+" exp { $$ = $1 + $3; };
424 Some grammars still depend on this `feature'. Bison 2.4.1 restores
425 the previous behavior in the case of C output (specifically, when
426 neither %language or %skeleton or equivalent command-line options
427 are used) to leave more time for grammars depending on the old
428 behavior to be adjusted. Future releases of Bison will disable this
431 ** A few minor improvements to the Bison manual.
433 * Changes in version 2.4 (2008-11-02):
435 ** %language is an experimental feature.
437 We first introduced this feature in test release 2.3b as a cleaner
438 alternative to %skeleton. Since then, we have discussed the possibility of
439 modifying its effect on Bison's output file names. Thus, in this release,
440 we consider %language to be an experimental feature that will likely evolve
443 ** Forward compatibility with GNU M4 has been improved.
445 ** Several bugs in the C++ skeleton and the experimental Java skeleton have been
448 * Changes in version 2.3b (2008-05-27):
450 ** The quotes around NAME that used to be required in the following directive
455 ** The directive `%pure-parser' is now deprecated in favor of:
459 which has the same effect except that Bison is more careful to warn about
460 unreasonable usage in the latter case.
464 Bison can now generate an LALR(1) parser in C with a push interface. That
465 is, instead of invoking `yyparse', which pulls tokens from `yylex', you can
466 push one token at a time to the parser using `yypush_parse', which will
467 return to the caller after processing each token. By default, the push
468 interface is disabled. Either of the following directives will enable it:
470 %define api.push_pull "push" // Just push; does not require yylex.
471 %define api.push_pull "both" // Push and pull; requires yylex.
473 See the new section `A Push Parser' in the Bison manual for details.
475 The current push parsing interface is experimental and may evolve. More user
476 feedback will help to stabilize it.
478 ** The -g and --graph options now output graphs in Graphviz DOT format,
479 not VCG format. Like --graph, -g now also takes an optional FILE argument
480 and thus cannot be bundled with other short options.
484 Bison can now generate an LALR(1) parser in Java. The skeleton is
485 `data/lalr1.java'. Consider using the new %language directive instead of
486 %skeleton to select it.
488 See the new section `Java Parsers' in the Bison manual for details.
490 The current Java interface is experimental and may evolve. More user
491 feedback will help to stabilize it.
495 This new directive specifies the programming language of the generated
496 parser, which can be C (the default), C++, or Java. Besides the skeleton
497 that Bison uses, the directive affects the names of the generated files if
498 the grammar file's name ends in ".y".
500 ** XML Automaton Report
502 Bison can now generate an XML report of the LALR(1) automaton using the new
503 `--xml' option. The current XML schema is experimental and may evolve. More
504 user feedback will help to stabilize it.
506 ** The grammar file may now specify the name of the parser header file using
507 %defines. For example:
511 ** When reporting useless rules, useless nonterminals, and unused terminals,
512 Bison now employs the terms "useless in grammar" instead of "useless",
513 "useless in parser" instead of "never reduced", and "unused in grammar"
516 ** Unreachable State Removal
518 Previously, Bison sometimes generated parser tables containing unreachable
519 states. A state can become unreachable during conflict resolution if Bison
520 disables a shift action leading to it from a predecessor state. Bison now:
522 1. Removes unreachable states.
524 2. Does not report any conflicts that appeared in unreachable states.
525 WARNING: As a result, you may need to update %expect and %expect-rr
526 directives in existing grammar files.
528 3. For any rule used only in such states, Bison now reports the rule as
529 "useless in parser due to conflicts".
531 This feature can be disabled with the following directive:
533 %define lr.keep_unreachable_states
535 See the %define entry in the `Bison Declaration Summary' in the Bison manual
536 for further discussion.
538 ** Lookahead Set Correction in the `.output' Report
540 When instructed to generate a `.output' file including lookahead sets
541 (using `--report=lookahead', for example), Bison now prints each reduction's
542 lookahead set only next to the associated state's one item that (1) is
543 associated with the same rule as the reduction and (2) has its dot at the end
544 of its RHS. Previously, Bison also erroneously printed the lookahead set
545 next to all of the state's other items associated with the same rule. This
546 bug affected only the `.output' file and not the generated parser source
549 ** --report-file=FILE is a new option to override the default `.output' file
552 ** The `=' that used to be required in the following directives is now
555 %file-prefix "parser"
559 ** An Alternative to `%{...%}' -- `%code QUALIFIER {CODE}'
561 Bison 2.3a provided a new set of directives as a more flexible alternative to
562 the traditional Yacc prologue blocks. Those have now been consolidated into
563 a single %code directive with an optional qualifier field, which identifies
564 the purpose of the code and thus the location(s) where Bison should generate
567 1. `%code {CODE}' replaces `%after-header {CODE}'
568 2. `%code requires {CODE}' replaces `%start-header {CODE}'
569 3. `%code provides {CODE}' replaces `%end-header {CODE}'
570 4. `%code top {CODE}' replaces `%before-header {CODE}'
572 See the %code entries in section `Bison Declaration Summary' in the Bison
573 manual for a summary of the new functionality. See the new section `Prologue
574 Alternatives' for a detailed discussion including the advantages of %code
575 over the traditional Yacc prologues.
577 The prologue alternatives are experimental. More user feedback will help to
578 determine whether they should become permanent features.
580 ** Revised warning: unset or unused mid-rule values
582 Since Bison 2.2, Bison has warned about mid-rule values that are set but not
583 used within any of the actions of the parent rule. For example, Bison warns
586 exp: '1' { $$ = 1; } '+' exp { $$ = $1 + $4; };
588 Now, Bison also warns about mid-rule values that are used but not set. For
589 example, Bison warns about unset $$ in the mid-rule action in:
591 exp: '1' { $1 = 1; } '+' exp { $$ = $2 + $4; };
593 However, Bison now disables both of these warnings by default since they
594 sometimes prove to be false alarms in existing grammars employing the Yacc
595 constructs $0 or $-N (where N is some positive integer).
597 To enable these warnings, specify the option `--warnings=midrule-values' or
598 `-W', which is a synonym for `--warnings=all'.
600 ** Default %destructor or %printer with `<*>' or `<>'
602 Bison now recognizes two separate kinds of default %destructor's and
605 1. Place `<*>' in a %destructor/%printer symbol list to define a default
606 %destructor/%printer for all grammar symbols for which you have formally
607 declared semantic type tags.
609 2. Place `<>' in a %destructor/%printer symbol list to define a default
610 %destructor/%printer for all grammar symbols without declared semantic
613 Bison no longer supports the `%symbol-default' notation from Bison 2.3a.
614 `<*>' and `<>' combined achieve the same effect with one exception: Bison no
615 longer applies any %destructor to a mid-rule value if that mid-rule value is
616 not actually ever referenced using either $$ or $n in a semantic action.
618 The default %destructor's and %printer's are experimental. More user
619 feedback will help to determine whether they should become permanent
622 See the section `Freeing Discarded Symbols' in the Bison manual for further
625 ** %left, %right, and %nonassoc can now declare token numbers. This is required
626 by POSIX. However, see the end of section `Operator Precedence' in the Bison
627 manual for a caveat concerning the treatment of literal strings.
629 ** The nonfunctional --no-parser, -n, and %no-parser options have been
630 completely removed from Bison.
632 * Changes in version 2.3a, 2006-09-13:
634 ** Instead of %union, you can define and use your own union type
635 YYSTYPE if your grammar contains at least one <type> tag.
636 Your YYSTYPE need not be a macro; it can be a typedef.
637 This change is for compatibility with other Yacc implementations,
638 and is required by POSIX.
640 ** Locations columns and lines start at 1.
641 In accordance with the GNU Coding Standards and Emacs.
643 ** You may now declare per-type and default %destructor's and %printer's:
647 %union { char *string; }
648 %token <string> STRING1
649 %token <string> STRING2
650 %type <string> string1
651 %type <string> string2
652 %union { char character; }
653 %token <character> CHR
654 %type <character> chr
655 %destructor { free ($$); } %symbol-default
656 %destructor { free ($$); printf ("%d", @$.first_line); } STRING1 string1
657 %destructor { } <character>
659 guarantees that, when the parser discards any user-defined symbol that has a
660 semantic type tag other than `<character>', it passes its semantic value to
661 `free'. However, when the parser discards a `STRING1' or a `string1', it
662 also prints its line number to `stdout'. It performs only the second
663 `%destructor' in this case, so it invokes `free' only once.
665 [Although we failed to mention this here in the 2.3a release, the default
666 %destructor's and %printer's were experimental, and they were rewritten in
669 ** Except for LALR(1) parsers in C with POSIX Yacc emulation enabled (with `-y',
670 `--yacc', or `%yacc'), Bison no longer generates #define statements for
671 associating token numbers with token names. Removing the #define statements
672 helps to sanitize the global namespace during preprocessing, but POSIX Yacc
673 requires them. Bison still generates an enum for token names in all cases.
675 ** Handling of traditional Yacc prologue blocks is now more consistent but
676 potentially incompatible with previous releases of Bison.
678 As before, you declare prologue blocks in your grammar file with the
679 `%{ ... %}' syntax. To generate the pre-prologue, Bison concatenates all
680 prologue blocks that you've declared before the first %union. To generate
681 the post-prologue, Bison concatenates all prologue blocks that you've
682 declared after the first %union.
684 Previous releases of Bison inserted the pre-prologue into both the header
685 file and the code file in all cases except for LALR(1) parsers in C. In the
686 latter case, Bison inserted it only into the code file. For parsers in C++,
687 the point of insertion was before any token definitions (which associate
688 token numbers with names). For parsers in C, the point of insertion was
689 after the token definitions.
691 Now, Bison never inserts the pre-prologue into the header file. In the code
692 file, it always inserts it before the token definitions.
694 ** Bison now provides a more flexible alternative to the traditional Yacc
695 prologue blocks: %before-header, %start-header, %end-header, and
698 For example, the following declaration order in the grammar file reflects the
699 order in which Bison will output these code blocks. However, you are free to
700 declare these code blocks in your grammar file in whatever order is most
704 /* Bison treats this block like a pre-prologue block: it inserts it into
705 * the code file before the contents of the header file. It does *not*
706 * insert it into the header file. This is a good place to put
707 * #include's that you want at the top of your code file. A common
708 * example is `#include "system.h"'. */
711 /* Bison inserts this block into both the header file and the code file.
712 * In both files, the point of insertion is before any Bison-generated
713 * token, semantic type, location type, and class definitions. This is a
714 * good place to define %union dependencies, for example. */
717 /* Unlike the traditional Yacc prologue blocks, the output order for the
718 * new %*-header blocks is not affected by their declaration position
719 * relative to any %union in the grammar file. */
722 /* Bison inserts this block into both the header file and the code file.
723 * In both files, the point of insertion is after the Bison-generated
724 * definitions. This is a good place to declare or define public
725 * functions or data structures that depend on the Bison-generated
729 /* Bison treats this block like a post-prologue block: it inserts it into
730 * the code file after the contents of the header file. It does *not*
731 * insert it into the header file. This is a good place to declare or
732 * define internal functions or data structures that depend on the
733 * Bison-generated definitions. */
736 If you have multiple occurrences of any one of the above declarations, Bison
737 will concatenate the contents in declaration order.
739 [Although we failed to mention this here in the 2.3a release, the prologue
740 alternatives were experimental, and they were rewritten in future versions.]
742 ** The option `--report=look-ahead' has been changed to `--report=lookahead'.
743 The old spelling still works, but is not documented and may be removed
746 * Changes in version 2.3, 2006-06-05:
748 ** GLR grammars should now use `YYRECOVERING ()' instead of `YYRECOVERING',
749 for compatibility with LALR(1) grammars.
751 ** It is now documented that any definition of YYSTYPE or YYLTYPE should
752 be to a type name that does not contain parentheses or brackets.
754 * Changes in version 2.2, 2006-05-19:
756 ** The distribution terms for all Bison-generated parsers now permit
757 using the parsers in nonfree programs. Previously, this permission
758 was granted only for Bison-generated LALR(1) parsers in C.
760 ** %name-prefix changes the namespace name in C++ outputs.
762 ** The C++ parsers export their token_type.
764 ** Bison now allows multiple %union declarations, and concatenates
765 their contents together.
767 ** New warning: unused values
768 Right-hand side symbols whose values are not used are reported,
769 if the symbols have destructors. For instance:
771 exp: exp "?" exp ":" exp { $1 ? $1 : $3; }
775 will trigger a warning about $$ and $5 in the first rule, and $3 in
776 the second ($1 is copied to $$ by the default rule). This example
777 most likely contains three errors, and could be rewritten as:
779 exp: exp "?" exp ":" exp
780 { $$ = $1 ? $3 : $5; free ($1 ? $5 : $3); free ($1); }
782 { $$ = $1 ? $1 : $3; if ($1) free ($3); }
785 However, if the original actions were really intended, memory leaks
786 and all, the warnings can be suppressed by letting Bison believe the
787 values are used, e.g.:
789 exp: exp "?" exp ":" exp { $1 ? $1 : $3; (void) ($$, $5); }
790 | exp "+" exp { $$ = $1; (void) $3; }
793 If there are mid-rule actions, the warning is issued if no action
794 uses it. The following triggers no warning: $1 and $3 are used.
796 exp: exp { push ($1); } '+' exp { push ($3); sum (); };
798 The warning is intended to help catching lost values and memory leaks.
799 If a value is ignored, its associated memory typically is not reclaimed.
801 ** %destructor vs. YYABORT, YYACCEPT, and YYERROR.
802 Destructors are now called when user code invokes YYABORT, YYACCEPT,
803 and YYERROR, for all objects on the stack, other than objects
804 corresponding to the right-hand side of the current rule.
806 ** %expect, %expect-rr
807 Incorrect numbers of expected conflicts are now actual errors,
810 ** GLR, YACC parsers.
811 The %parse-params are available in the destructors (and the
812 experimental printers) as per the documentation.
814 ** Bison now warns if it finds a stray `$' or `@' in an action.
816 ** %require "VERSION"
817 This specifies that the grammar file depends on features implemented
818 in Bison version VERSION or higher.
820 ** lalr1.cc: The token and value types are now class members.
821 The tokens were defined as free form enums and cpp macros. YYSTYPE
822 was defined as a free form union. They are now class members:
823 tokens are enumerations of the `yy::parser::token' struct, and the
824 semantic values have the `yy::parser::semantic_type' type.
826 If you do not want or can update to this scheme, the directive
827 `%define "global_tokens_and_yystype" "1"' triggers the global
828 definition of tokens and YYSTYPE. This change is suitable both
829 for previous releases of Bison, and this one.
831 If you wish to update, then make sure older version of Bison will
832 fail using `%require "2.2"'.
834 ** DJGPP support added.
836 * Changes in version 2.1, 2005-09-16:
838 ** The C++ lalr1.cc skeleton supports %lex-param.
840 ** Bison-generated parsers now support the translation of diagnostics like
841 "syntax error" into languages other than English. The default
842 language is still English. For details, please see the new
843 Internationalization section of the Bison manual. Software
844 distributors should also see the new PACKAGING file. Thanks to
845 Bruno Haible for this new feature.
847 ** Wording in the Bison-generated parsers has been changed slightly to
848 simplify translation. In particular, the message "memory exhausted"
849 has replaced "parser stack overflow", as the old message was not
850 always accurate for modern Bison-generated parsers.
852 ** Destructors are now called when the parser aborts, for all symbols left
853 behind on the stack. Also, the start symbol is now destroyed after a
854 successful parse. In both cases, the behavior was formerly inconsistent.
856 ** When generating verbose diagnostics, Bison-generated parsers no longer
857 quote the literal strings associated with tokens. For example, for
858 a syntax error associated with '%token NUM "number"' they might
859 print 'syntax error, unexpected number' instead of 'syntax error,
860 unexpected "number"'.
862 * Changes in version 2.0, 2004-12-25:
864 ** Possibly-incompatible changes
866 - Bison-generated parsers no longer default to using the alloca function
867 (when available) to extend the parser stack, due to widespread
868 problems in unchecked stack-overflow detection. You can "#define
869 YYSTACK_USE_ALLOCA 1" to require the use of alloca, but please read
870 the manual to determine safe values for YYMAXDEPTH in that case.
872 - Error token location.
873 During error recovery, the location of the syntax error is updated
874 to cover the whole sequence covered by the error token: it includes
875 the shifted symbols thrown away during the first part of the error
876 recovery, and the lookahead rejected during the second part.
879 . Stray semicolons are no longer allowed at the start of a grammar.
880 . Semicolons are now required after in-grammar declarations.
882 - Unescaped newlines are no longer allowed in character constants or
883 string literals. They were never portable, and GCC 3.4.0 has
884 dropped support for them. Better diagnostics are now generated if
885 forget a closing quote.
887 - NUL bytes are no longer allowed in Bison string literals, unfortunately.
891 - GLR grammars now support locations.
893 - New directive: %initial-action.
894 This directive allows the user to run arbitrary code (including
895 initializing @$) from yyparse before parsing starts.
897 - A new directive "%expect-rr N" specifies the expected number of
898 reduce/reduce conflicts in GLR parsers.
900 - %token numbers can now be hexadecimal integers, e.g., `%token FOO 0x12d'.
901 This is a GNU extension.
903 - The option `--report=lookahead' was changed to `--report=look-ahead'.
904 [However, this was changed back after 2.3.]
906 - Experimental %destructor support has been added to lalr1.cc.
908 - New configure option --disable-yacc, to disable installation of the
909 yacc command and -ly library introduced in 1.875 for POSIX conformance.
913 - For now, %expect-count violations are now just warnings, not errors.
914 This is for compatibility with Bison 1.75 and earlier (when there are
915 reduce/reduce conflicts) and with Bison 1.30 and earlier (when there
916 are too many or too few shift/reduce conflicts). However, in future
917 versions of Bison we plan to improve the %expect machinery so that
918 these violations will become errors again.
920 - Within Bison itself, numbers (e.g., goto numbers) are no longer
921 arbitrarily limited to 16-bit counts.
923 - Semicolons are now allowed before "|" in grammar rules, as POSIX requires.
925 * Changes in version 1.875, 2003-01-01:
927 ** The documentation license has been upgraded to version 1.2
928 of the GNU Free Documentation License.
930 ** syntax error processing
932 - In Yacc-style parsers YYLLOC_DEFAULT is now used to compute error
933 locations too. This fixes bugs in error-location computation.
936 It is now possible to reclaim the memory associated to symbols
937 discarded during error recovery. This feature is still experimental.
940 This new directive is preferred over YYERROR_VERBOSE.
942 - #defining yyerror to steal internal variables is discouraged.
943 It is not guaranteed to work forever.
947 - Semicolons are once again optional at the end of grammar rules.
948 This reverts to the behavior of Bison 1.33 and earlier, and improves
949 compatibility with Yacc.
951 - `parse error' -> `syntax error'
952 Bison now uniformly uses the term `syntax error'; formerly, the code
953 and manual sometimes used the term `parse error' instead. POSIX
954 requires `syntax error' in diagnostics, and it was thought better to
957 - The documentation now emphasizes that yylex and yyerror must be
958 declared before use. C99 requires this.
960 - Bison now parses C99 lexical constructs like UCNs and
961 backslash-newline within C escape sequences, as POSIX 1003.1-2001 requires.
963 - File names are properly escaped in C output. E.g., foo\bar.y is
964 output as "foo\\bar.y".
966 - Yacc command and library now available
967 The Bison distribution now installs a `yacc' command, as POSIX requires.
968 Also, Bison now installs a small library liby.a containing
969 implementations of Yacc-compatible yyerror and main functions.
970 This library is normally not useful, but POSIX requires it.
972 - Type clashes now generate warnings, not errors.
974 - If the user does not define YYSTYPE as a macro, Bison now declares it
975 using typedef instead of defining it as a macro.
976 For consistency, YYLTYPE is also declared instead of defined.
978 ** Other compatibility issues
980 - %union directives can now have a tag before the `{', e.g., the
981 directive `%union foo {...}' now generates the C code
982 `typedef union foo { ... } YYSTYPE;'; this is for Yacc compatibility.
983 The default union tag is `YYSTYPE', for compatibility with Solaris 9 Yacc.
984 For consistency, YYLTYPE's struct tag is now `YYLTYPE' not `yyltype'.
985 This is for compatibility with both Yacc and Bison 1.35.
987 - `;' is output before the terminating `}' of an action, for
988 compatibility with Bison 1.35.
990 - Bison now uses a Yacc-style format for conflict reports, e.g.,
991 `conflicts: 2 shift/reduce, 1 reduce/reduce'.
993 - `yystype' and `yyltype' are now obsolescent macros instead of being
994 typedefs or tags; they are no longer documented and are planned to be
995 withdrawn in a future release.
1000 Users of Bison have to decide how they handle the portability of the
1003 - `parsing stack overflow...' -> `parser stack overflow'
1004 GLR parsers now report `parser stack overflow' as per the Bison manual.
1006 ** Bison now warns if it detects conflicting outputs to the same file,
1007 e.g., it generates a warning for `bison -d -o foo.h foo.y' since
1008 that command outputs both code and header to foo.h.
1010 ** #line in output files
1011 - --no-line works properly.
1013 ** Bison can no longer be built by a K&R C compiler; it requires C89 or
1014 later to be built. This change originally took place a few versions
1015 ago, but nobody noticed until we recently asked someone to try
1016 building Bison with a K&R C compiler.
1018 * Changes in version 1.75, 2002-10-14:
1020 ** Bison should now work on 64-bit hosts.
1022 ** Indonesian translation thanks to Tedi Heriyanto.
1025 Fix spurious parse errors.
1028 Some people redefine yyerror to steal yyparse' private variables.
1029 Reenable this trick until an official feature replaces it.
1032 In agreement with POSIX and with other Yaccs, leaving a default
1033 action is valid when $$ is untyped, and $1 typed:
1037 but the converse remains an error:
1041 ** Values of mid-rule actions
1044 foo: { ... } { $$ = $1; } ...
1046 was incorrectly rejected: $1 is defined in the second mid-rule
1047 action, and is equal to the $$ of the first mid-rule action.
1049 * Changes in version 1.50, 2002-10-04:
1054 causes Bison to produce a Generalized LR (GLR) parser, capable of handling
1055 almost any context-free grammar, ambiguous or not. The new declarations
1056 %dprec and %merge on grammar rules allow parse-time resolution of
1057 ambiguities. Contributed by Paul Hilfinger.
1059 Unfortunately Bison 1.50 does not work properly on 64-bit hosts
1060 like the Alpha, so please stick to 32-bit hosts for now.
1063 When not in Yacc compatibility mode, when the output file was not
1064 specified, running `bison foo/bar.y' created `foo/bar.c'. It
1065 now creates `bar.c'.
1068 The undefined token was systematically mapped to 2 which prevented
1069 the use of 2 by the user. This is no longer the case.
1071 ** Unknown token numbers
1072 If yylex returned an out of range value, yyparse could die. This is
1076 According to POSIX, the error token must be 256.
1077 Bison extends this requirement by making it a preference: *if* the
1078 user specified that one of her tokens is numbered 256, then error
1079 will be mapped onto another number.
1081 ** Verbose error messages
1082 They no longer report `..., expecting error or...' for states where
1083 error recovery is possible.
1086 Defaults to `$end' instead of `$'.
1088 ** Error recovery now conforms to documentation and to POSIX
1089 When a Bison-generated parser encounters a syntax error, it now pops
1090 the stack until it finds a state that allows shifting the error
1091 token. Formerly, it popped the stack until it found a state that
1092 allowed some non-error action other than a default reduction on the
1093 error token. The new behavior has long been the documented behavior,
1094 and has long been required by POSIX. For more details, please see
1095 Paul Eggert, "Reductions during Bison error handling" (2002-05-20)
1096 <http://lists.gnu.org/archive/html/bug-bison/2002-05/msg00038.html>.
1099 Popped tokens and nonterminals are now reported.
1102 Larger grammars are now supported (larger token numbers, larger grammar
1103 size (= sum of the LHS and RHS lengths), larger LALR tables).
1104 Formerly, many of these numbers ran afoul of 16-bit limits;
1105 now these limits are 32 bits on most hosts.
1107 ** Explicit initial rule
1108 Bison used to play hacks with the initial rule, which the user does
1109 not write. It is now explicit, and visible in the reports and
1113 Before, Bison reported the useless rules, but, although not used,
1114 included them in the parsers. They are now actually removed.
1116 ** Useless rules, useless nonterminals
1117 They are now reported, as a warning, with their locations.
1119 ** Rules never reduced
1120 Rules that can never be reduced because of conflicts are now
1123 ** Incorrect `Token not used'
1124 On a grammar such as
1126 %token useless useful
1128 exp: '0' %prec useful;
1130 where a token was used to set the precedence of the last rule,
1131 bison reported both `useful' and `useless' as useless tokens.
1133 ** Revert the C++ namespace changes introduced in 1.31
1134 as they caused too many portability hassles.
1136 ** Default locations
1137 By an accident of design, the default computation of @$ was
1138 performed after another default computation was performed: @$ = @1.
1139 The latter is now removed: YYLLOC_DEFAULT is fully responsible of
1140 the computation of @$.
1142 ** Token end-of-file
1143 The token end of file may be specified by the user, in which case,
1144 the user symbol is used in the reports, the graphs, and the verbose
1145 error messages instead of `$end', which remains being the default.
1149 %token MYEOF 0 "end of file"
1152 This old option, which has been broken for ages, is removed.
1155 Brazilian Portuguese, thanks to Alexandre Folle de Menezes.
1156 Croatian, thanks to Denis Lackovic.
1158 ** Incorrect token definitions
1159 When given `%token 'a' "A"', Bison used to output `#define 'a' 65'.
1161 ** Token definitions as enums
1162 Tokens are output both as the traditional #define's, and, provided
1163 the compiler supports ANSI C or is a C++ compiler, as enums.
1164 This lets debuggers display names instead of integers.
1167 In addition to --verbose, bison supports --report=THINGS, which
1168 produces additional information:
1170 complete the core item sets with their closure
1171 - lookahead [changed to `look-ahead' in 1.875e through 2.3, but changed back]
1172 explicitly associate lookahead tokens to items
1174 describe shift/reduce conflicts solving.
1175 Bison used to systematically output this information on top of
1176 the report. Solved conflicts are now attached to their states.
1179 Previous versions don't complain when there is a type clash on
1180 the default action if the rule has a mid-rule action, such as in:
1188 ** GNU M4 is now required when using Bison.
1190 * Changes in version 1.35, 2002-03-25:
1193 Some projects use Bison's C parser with C++ compilers, and define
1194 YYSTYPE as a class. The recent adjustment of C parsers for data
1195 alignment and 64 bit architectures made this impossible.
1197 Because for the time being no real solution for C++ parser
1198 generation exists, kludges were implemented in the parser to
1199 maintain this use. In the future, when Bison has C++ parsers, this
1200 kludge will be disabled.
1202 This kludge also addresses some C++ problems when the stack was
1205 * Changes in version 1.34, 2002-03-12:
1207 ** File name clashes are detected
1208 $ bison foo.y -d -o foo.x
1209 fatal error: header and parser would both be named `foo.x'
1211 ** A missing `;' at the end of a rule triggers a warning
1212 In accordance with POSIX, and in agreement with other
1213 Yacc implementations, Bison will mandate this semicolon in the near
1214 future. This eases the implementation of a Bison parser of Bison
1215 grammars by making this grammar LALR(1) instead of LR(2). To
1216 facilitate the transition, this release introduces a warning.
1218 ** Revert the C++ namespace changes introduced in 1.31, as they caused too
1219 many portability hassles.
1221 ** DJGPP support added.
1223 ** Fix test suite portability problems.
1225 * Changes in version 1.33, 2002-02-07:
1228 Groff could not be compiled for the definition of size_t was lacking
1229 under some conditions.
1234 * Changes in version 1.32, 2002-01-23:
1236 ** Fix Yacc output file names
1238 ** Portability fixes
1240 ** Italian, Dutch translations
1242 * Changes in version 1.31, 2002-01-14:
1246 ** GNU Gettext and %expect
1247 GNU Gettext asserts 10 s/r conflicts, but there are 7. Now that
1248 Bison dies on incorrect %expectations, we fear there will be
1249 too many bug reports for Gettext, so _for the time being_, %expect
1250 does not trigger an error when the input file is named `plural.y'.
1252 ** Use of alloca in parsers
1253 If YYSTACK_USE_ALLOCA is defined to 0, then the parsers will use
1254 malloc exclusively. Since 1.29, but was not NEWS'ed.
1256 alloca is used only when compiled with GCC, to avoid portability
1259 ** yyparse now returns 2 if memory is exhausted; formerly it dumped core.
1261 ** When the generated parser lacks debugging code, YYDEBUG is now 0
1262 (as POSIX requires) instead of being undefined.
1265 Bison has always permitted actions such as { $$ = $1 }: it adds the
1266 ending semicolon. Now if in Yacc compatibility mode, the semicolon
1267 is no longer output: one has to write { $$ = $1; }.
1269 ** Better C++ compliance
1270 The output parsers try to respect C++ namespaces.
1271 [This turned out to be a failed experiment, and it was reverted later.]
1274 Fixed bugs when reporting useless nonterminals.
1277 The parsers work properly on 64 bit hosts.
1280 Some calls to strerror resulted in scrambled or missing error messages.
1283 When the number of shift/reduce conflicts is correct, don't issue
1286 ** The verbose report includes the rule line numbers.
1288 ** Rule line numbers are fixed in traces.
1290 ** Swedish translation
1293 Verbose parse error messages from the parsers are better looking.
1294 Before: parse error: unexpected `'/'', expecting `"number"' or `'-'' or `'(''
1295 Now: parse error: unexpected '/', expecting "number" or '-' or '('
1297 ** Fixed parser memory leaks.
1298 When the generated parser was using malloc to extend its stacks, the
1299 previous allocations were not freed.
1301 ** Fixed verbose output file.
1302 Some newlines were missing.
1303 Some conflicts in state descriptions were missing.
1305 ** Fixed conflict report.
1306 Option -v was needed to get the result.
1310 Mismatches are errors, not warnings.
1312 ** Fixed incorrect processing of some invalid input.
1314 ** Fixed CPP guards: 9foo.h uses BISON_9FOO_H instead of 9FOO_H.
1316 ** Fixed some typos in the documentation.
1318 ** %token MY_EOF 0 is supported.
1319 Before, MY_EOF was silently renumbered as 257.
1321 ** doc/refcard.tex is updated.
1323 ** %output, %file-prefix, %name-prefix.
1327 New, aliasing `--output-file'.
1329 * Changes in version 1.30, 2001-10-26:
1331 ** `--defines' and `--graph' have now an optional argument which is the
1332 output file name. `-d' and `-g' do not change; they do not take any
1335 ** `%source_extension' and `%header_extension' are removed, failed
1338 ** Portability fixes.
1340 * Changes in version 1.29, 2001-09-07:
1342 ** The output file does not define const, as this caused problems when used
1343 with common autoconfiguration schemes. If you still use ancient compilers
1344 that lack const, compile with the equivalent of the C compiler option
1345 `-Dconst='. autoconf's AC_C_CONST macro provides one way to do this.
1347 ** Added `-g' and `--graph'.
1349 ** The Bison manual is now distributed under the terms of the GNU FDL.
1351 ** The input and the output files has automatically a similar extension.
1353 ** Russian translation added.
1355 ** NLS support updated; should hopefully be less troublesome.
1357 ** Added the old Bison reference card.
1359 ** Added `--locations' and `%locations'.
1361 ** Added `-S' and `--skeleton'.
1363 ** `%raw', `-r', `--raw' is disabled.
1365 ** Special characters are escaped when output. This solves the problems
1366 of the #line lines with path names including backslashes.
1369 `%yacc', `%fixed_output_files', `%defines', `%no_parser', `%verbose',
1370 `%debug', `%source_extension' and `%header_extension'.
1373 Automatic location tracking.
1375 * Changes in version 1.28, 1999-07-06:
1377 ** Should compile better now with K&R compilers.
1381 ** Fixed a problem with escaping the double quote character.
1383 ** There is now a FAQ.
1385 * Changes in version 1.27:
1387 ** The make rule which prevented bison.simple from being created on
1388 some systems has been fixed.
1390 * Changes in version 1.26:
1392 ** Bison now uses automake.
1394 ** New mailing lists: <bug-bison@gnu.org> and <help-bison@gnu.org>.
1396 ** Token numbers now start at 257 as previously documented, not 258.
1398 ** Bison honors the TMPDIR environment variable.
1400 ** A couple of buffer overruns have been fixed.
1402 ** Problems when closing files should now be reported.
1404 ** Generated parsers should now work even on operating systems which do
1405 not provide alloca().
1407 * Changes in version 1.25, 1995-10-16:
1409 ** Errors in the input grammar are not fatal; Bison keeps reading
1410 the grammar file, and reports all the errors found in it.
1412 ** Tokens can now be specified as multiple-character strings: for
1413 example, you could use "<=" for a token which looks like <=, instead
1414 of chosing a name like LESSEQ.
1416 ** The %token_table declaration says to write a table of tokens (names
1417 and numbers) into the parser file. The yylex function can use this
1418 table to recognize multiple-character string tokens, or for other
1421 ** The %no_lines declaration says not to generate any #line preprocessor
1422 directives in the parser file.
1424 ** The %raw declaration says to use internal Bison token numbers, not
1425 Yacc-compatible token numbers, when token names are defined as macros.
1427 ** The --no-parser option produces the parser tables without including
1428 the parser engine; a project can now use its own parser engine.
1429 The actions go into a separate file called NAME.act, in the form of
1430 a switch statement body.
1432 * Changes in version 1.23:
1434 The user can define YYPARSE_PARAM as the name of an argument to be
1435 passed into yyparse. The argument should have type void *. It should
1436 actually point to an object. Grammar actions can access the variable
1437 by casting it to the proper pointer type.
1439 Line numbers in output file corrected.
1441 * Changes in version 1.22:
1443 --help option added.
1445 * Changes in version 1.20:
1447 Output file does not redefine const for C++.
1455 Copyright (C) 1995-2011 Free Software Foundation, Inc.
1457 This file is part of Bison, the GNU Parser Generator.
1459 This program is free software: you can redistribute it and/or modify
1460 it under the terms of the GNU General Public License as published by
1461 the Free Software Foundation, either version 3 of the License, or
1462 (at your option) any later version.
1464 This program is distributed in the hope that it will be useful,
1465 but WITHOUT ANY WARRANTY; without even the implied warranty of
1466 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1467 GNU General Public License for more details.
1469 You should have received a copy of the GNU General Public License
1470 along with this program. If not, see <http://www.gnu.org/licenses/>.