Next: , Previous: , Up: Bison Options   [Contents][Index]

9.1.3 Tuning the Parser

Options changing the generated parsers.


In the parser implementation file, define the macro YYDEBUG to 1 if it is not already defined, so that the debugging facilities are compiled. See Tracing Your Parser.

-D name[=value]
-F name[=value]

Each of these is equivalent to ‘%define name value’ (see %define Summary). Note that the delimiters are part of value: -Dapi.value.type=union, -Dapi.value.type={union} and -Dapi.value.type="union" correspond to ‘%define api.value.type union’, ‘%define api.value.type {union}’ and ‘%define api.value.type "union"’.

Bison processes multiple definitions for the same name as follows:

  • Bison quietly ignores all command-line definitions for name except the last.
  • If that command-line definition is specified by a -D or --define, Bison reports an error for any %define definition for name.
  • If that command-line definition is specified by a -F or --force-define instead, Bison quietly ignores all %define definitions for name.
  • Otherwise, Bison reports an error if there are multiple %define definitions for name.

You should avoid using -F and --force-define in your make files unless you are confident that it is safe to quietly ignore any conflicting %define that may be added to the grammar file.

-L language

Specify the programming language for the generated parser, as if %language was specified (see Bison Declaration Summary). Currently supported languages include C, C++, D and Java. language is case-insensitive.


Pretend that %locations was specified. See Bison Declaration Summary.

-p prefix

Pretend that %name-prefix "prefix" was specified (see Bison Declaration Summary). The option -p is specified by POSIX. When POSIX compatibility is not a requirement, -Dapi.prefix=prefix is a better option (see Multiple Parsers in the Same Program).


Don’t put any #line preprocessor commands in the parser implementation file. Ordinarily Bison puts them in the parser implementation file so that the C compiler and debuggers will associate errors with your source file, the grammar file. This option causes them to associate errors with the parser implementation file, treating it as an independent source file in its own right.

-S file

Specify the skeleton to use, similar to %skeleton (see Bison Declaration Summary).

If file does not contain a /, file is the name of a skeleton file in the Bison installation directory. If it does, file is an absolute file name or a file name relative to the current working directory. This is similar to how most shells resolve commands.


Pretend that %token-table was specified. See Bison Declaration Summary.


Act more like the traditional yacc command:

  • Generate different diagnostics (it implies -Wyacc).
  • Generate #define statements in addition to an enum to associate token codes with token kind names.
  • If the POSIXLY_CORRECT environment variable is defined, generate prototypes for yyerror and yylex6 (since Bison 3.8):
    int yylex (void);
    void yyerror (const char *);

    As a Bison extension, additional arguments required by %pure-parser, %locations, %lex-param and %parse-param are taken into account. You may disable yyerror’s prototype with ‘#define yyerror yyerror’ (as specified by POSIX), or with ‘#define YYERROR_IS_DECLARED’ (a Bison extension). Likewise for yylex.

  • Imitate Yacc’s output file name conventions, so that the parser implementation file is called, and the other outputs are called y.output and Do not use --yacc just to change the output file names since it also triggers all the aforementioned behavior changes; rather use ‘-o’.

The -y/--yacc option is intended for use with traditional Yacc grammars. This option only makes sense for the default C skeleton, yacc.c. If your grammar uses Bison extensions Bison cannot be Yacc-compatible, even if this option is specified.

Thus, the following shell script can substitute for Yacc, and the Bison distribution contains such a yacc script for compatibility with POSIX:

#! /bin/sh
bison -y "$@"




Next: Output Files, Previous: Diagnostics, Up: Bison Options   [Contents][Index]