Bison supports both traditional single-letter options and mnemonic long option names. Long option names are indicated with ‘--’ instead of ‘-’. Abbreviations for option names are allowed as long as they are unique. When a long option takes an argument, like ‘--file-prefix’, connect the option name and the argument with ‘=’.
Here is a list of options that can be used with Bison, alphabetized by short option. It is followed by a cross key alphabetized by long option.
Operations modes:
#define
statements in addition to an enum
to associate
token numbers with token names. Thus, the following shell script can
substitute for Yacc, and the Bison distribution contains such a script
for compatibility with POSIX:
#! /bin/sh bison -y "$@"
The -y/--yacc option is intended for use with
traditional Yacc grammars. If your grammar uses a Bison extension
like ‘%glr-parser’, Bison might not be Yacc-compatible even if
this option is specified.
midrule-values
$2
in:
exp: '1' { $$ = 1; } '+' exp { $$ = $1 + $4; };
Also warn about mid-rule values that are used but not set.
For example, warn about unset $$
in the mid-rule action in:
exp: '1' { $1 = 1; } '+' exp { $$ = $2 + $4; };
These warnings are not enabled by default since they sometimes prove to
be false alarms in existing grammars employing the Yacc constructs
$0
or $-
n (where n is some positive integer).
yacc
conflicts-sr
conflicts-rr
%expect
or %expect-rr
directive is specified, an
unexpected number of conflicts is an error, and an expected number of
conflicts is not reported, so -W and --warning then have
no effect on the conflict report.
other
This category is provided merely for the sake of completeness. Future
releases of Bison may move warnings from this category to new, more specific
categories.
all
none
error
A category can be turned off by prefixing its name with ‘no-’. For
instance, -Wno-yacc will hide the warnings about
POSIX Yacc incompatibilities.
caret
diagnostics-show-caret
%type <ival> exp %% exp: exp '+' exp { $exp = $1 + $2; };
When invoked with -fcaret, Bison will report:
in.y:3.20-23: error: ambiguous reference: '$exp' exp: exp '+' exp { $exp = $1 + $2; }; ^^^^ in.y:3.1-3: refers to: $exp at $$ exp: exp '+' exp { $exp = $1 + $2; }; ^^^ in.y:3.6-8: refers to: $exp at $1 exp: exp '+' exp { $exp = $1 + $2; }; ^^^ in.y:3.14-16: refers to: $exp at $3 exp: exp '+' exp { $exp = $1 + $2; }; ^^^ in.y:3.32-33: error: $2 of 'exp' has no declared type exp: exp '+' exp { $exp = $1 + $2; }; ^^
Tuning the parser:
YYDEBUG
to
1 if it is not already defined, so that the debugging facilities are
compiled. See Tracing Your Parser.
-D
or
--define
, Bison reports an error for any %define
definition for name.
-F
or
--force-define
instead, Bison quietly ignores all %define
definitions for name.
%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.
%language
was specified (see Bison Declaration Summary). Currently supported languages include C, C++, and Java.
language is case-insensitive.
%locations
was specified. See Decl Summary.
%name-prefix "
prefix"
was specified (see Decl Summary). Obsoleted by -Dapi.prefix=
prefix. See Multiple Parsers in the Same Program.
#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.
%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.
%token-table
was specified. See Decl Summary.
Adjust the output:
%defines
was specified, i.e., write an extra output
file containing macro definitions for the token type names defined in
the grammar, as well as a few other declarations. See Decl Summary.
--defines
except -d
does not accept a
file argument since POSIX Yacc requires that -d
can be bundled
with other short options.
%file-prefix
was specified, i.e., specify prefix to use
for all Bison output file names. See Decl Summary.
state
itemset
state
and augments the description of the automaton with
the full set of items for each state, instead of its core only.
lookahead
state
and augments the description of the automaton with
each rule's lookahead set.
solved
state
. Explain how conflicts were solved thanks to
precedence and associativity directives.
all
none
%verbose
was specified, i.e., write an extra output
file containing verbose descriptions of the grammar and
parser. See Decl Summary.
The other output files' names are constructed from file as
described under the ‘-v’ and ‘-d’ options.