[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The usual way to invoke Bison is as follows:
bison infile |
Here infile is the grammar file name, which usually ends in ‘.y’. The parser implementation file’s name is made by replacing the ‘.y’ with ‘.tab.c’ and removing any leading directory. Thus, the ‘bison foo.y’ file name yields ‘foo.tab.c’, and the ‘bison hack/foo.y’ file name yields ‘foo.tab.c’. It’s also possible, in case you are writing C++ code instead of C in your grammar file, to name it ‘foo.ypp’ or ‘foo.y++’. Then, the output files will take an extension like the given one as input (respectively ‘foo.tab.cpp’ and ‘foo.tab.c++’). This feature takes effect with all options that manipulate file names like ‘-o’ or ‘-d’.
For example :
bison -d infile.yxx |
will produce ‘infile.tab.cxx’ and ‘infile.tab.hxx’, and
bison -d -o output.c++ infile.y |
will produce ‘output.c++’ and ‘outfile.h++’.
For compatibility with POSIX, the standard Bison
distribution also contains a shell script called yacc
that
invokes Bison with the ‘-y’ option.
9.1 Bison Options | All the options described in detail, in alphabetical order by short options. | |
9.2 Option Cross Key | Alphabetical list of long options. | |
9.3 Yacc Library | Yacc-compatible yylex and main .
|
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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:
Print a summary of the command-line options to Bison and exit.
Print the version number of Bison and exit.
Print the name of the directory containing locale-dependent data.
Print the name of the directory containing skeletons and XSLT.
Act more like the traditional Yacc command. This can cause different
diagnostics to be generated, and may change behavior in other minor
ways. Most importantly, imitate Yacc’s output file name conventions,
so that the parser implementation file is called ‘y.tab.c’, and
the other outputs are called ‘y.output’ and ‘y.tab.h’.
Also, if generating a deterministic parser in C, generate
#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.
Output warnings falling in category. category can be one of:
midrule-values
Warn about mid-rule values that are set but not used within any of the actions
of the parent rule.
For example, warn about unused $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
Incompatibilities with POSIX Yacc.
conflicts-sr
conflicts-rr
S/R and R/R conflicts. These warnings are enabled by default. However, if
the %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.
deprecated
Deprecated constructs whose support will be removed in future versions of Bison.
empty-rule
Empty rules without %empty
. See section Empty Rules. Disabled by
default, but enabled by uses of %empty
, unless
‘-Wno-empty-rule’ was specified.
precedence
Useless precedence and associativity directives. Disabled by default.
Consider for instance the following grammar:
%nonassoc "=" %left "+" %left "*" %precedence "(" %% stmt: exp | "var" "=" exp ; exp: exp "+" exp | exp "*" "num" | "(" exp ")" | "num" ; |
Bison reports:
warning: useless precedence and associativity for "=" %nonassoc "=" ^^^ warning: useless associativity for "*", use %precedence %left "*" ^^^ warning: useless precedence for "(" %precedence "(" ^^^ |
One would get the exact same parser with the following directives instead:
%left "+" %precedence "*" |
other
All warnings not categorized above. These warnings are enabled by default.
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
All the warnings except yacc
.
none
Turn off all the warnings.
error
See ‘-Werror’, below.
A category can be turned off by prefixing its name with ‘no-’. For instance, ‘-Wno-yacc’ will hide the warnings about POSIX Yacc incompatibilities.
Turn enabled warnings for every category into errors, unless they are explicitly disabled by ‘-Wno-error=category’.
Enable warnings falling in category, and treat them as errors.
category is the same as for ‘--warnings’, with the exception that it may not be prefixed with ‘no-’ (see above).
Note that the precedence of the ‘=’ and ‘,’ operators is such that the following commands are not equivalent, as the first will not treat S/R conflicts as errors.
$ bison -Werror=yacc,conflicts-sr input.y $ bison -Werror=yacc,error=conflicts-sr input.y |
Do not turn enabled warnings for every category into errors, unless they are explicitly enabled by ‘-Werror=category’.
Deactivate the error treatment for this category. However, the warning itself won’t be disabled, or enabled, by this option.
Activate miscellaneous feature. feature can be one of:
caret
diagnostics-show-caret
Show caret errors, in a manner similar to GCC’s ‘-fdiagnostics-show-caret’, or Clang’s ‘-fcaret-diagnotics’. The location provided with the message is used to quote the corresponding line of the source file, underlining the important part of it with carets (^). Here is an example, using the following file ‘in.y’:
%type <ival> exp %% exp: exp '+' exp { $exp = $1 + $2; }; |
When invoked with ‘-fcaret’ (or nothing), 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; }; ^^ |
Whereas, when invoked with ‘-fno-caret’, Bison will only report:
in.y:3.20-23: error: ambiguous reference: ‘$exp’ in.y:3.1-3: refers to: $exp at $$ in.y:3.6-8: refers to: $exp at $1 in.y:3.14-16: refers to: $exp at $3 in.y:3.32-33: error: $2 of ‘exp’ has no declared type |
This option is activated by default.
Tuning the parser:
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 section Tracing Your Parser.
Each of these is equivalent to ‘%define name "value"’ (see section %define Summary) except that Bison processes multiple definitions for the same name as follows:
-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.
Specify the programming language for the generated parser, as if
%language
was specified (see section Bison Declaration Summary). Currently supported languages include C, C++, and Java.
language is case-insensitive.
Pretend that %locations
was specified. See section Bison Declaration Summary.
Pretend that %name-prefix "prefix"
was specified (see section Bison Declaration Summary). Obsoleted by -Dapi.prefix=prefix
. See section 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.
Specify the skeleton to use, similar to %skeleton
(see section 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 section Bison Declaration Summary.
Adjust the output:
Pretend that %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 section Bison Declaration Summary.
This is the same as --defines
except -d
does not accept a
file argument since POSIX Yacc requires that -d
can be bundled
with other short options.
Pretend that %file-prefix
was specified, i.e., specify prefix to use
for all Bison output file names. See section Bison Declaration Summary.
Write an extra output file containing verbose description of the comma separated list of things among:
state
Description of the grammar, conflicts (resolved and unresolved), and parser’s automaton.
itemset
Implies state
and augments the description of the automaton with
the full set of items for each state, instead of its core only.
lookahead
Implies state
and augments the description of the automaton with
each rule’s lookahead set.
solved
Implies state
. Explain how conflicts were solved thanks to
precedence and associativity directives.
all
Enable all the items.
none
Do not generate the report.
Specify the file for the verbose description.
Pretend that %verbose
was specified, i.e., write an extra output
file containing verbose descriptions of the grammar and
parser. See section Bison Declaration Summary.
Specify the file for the parser implementation file.
The other output files’ names are constructed from file as described under the ‘-v’ and ‘-d’ options.
Output a graphical representation of the parser’s
automaton computed by Bison, in Graphviz
DOT format.
file
is optional.
If omitted and the grammar file is ‘foo.y’, the output file will be
‘foo.dot’.
Output an XML report of the parser’s automaton computed by Bison.
file
is optional.
If omitted and the grammar file is ‘foo.y’, the output file will be
‘foo.xml’.
(The current XML schema is experimental and may evolve.
More user feedback will help to stabilize it.)
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Here is a list of options, alphabetized by long option, to help you find the corresponding short option and directive.
Long Option | Short Option | Bison Directive |
---|---|---|
‘--debug’ | ‘-t’ | %debug |
‘--define=name[=value]’ | ‘-D name[=value]’ | %define name ["value"] |
‘--defines[=file]’ | ‘-d’ | %defines ["file"] |
‘--feature[=feature]’ | ‘-f [feature]’ | |
‘--file-prefix=prefix’ | ‘-b prefix’ | %file-prefix "prefix" |
‘--force-define=name[=value]’ | ‘-F name[=value]’ | %define name ["value"] |
‘--graph[=file]’ | ‘-g [file]’ | |
‘--help’ | ‘-h’ | |
‘--language=language’ | ‘-L language’ | %language "language" |
‘--locations’ | %locations | |
‘--name-prefix=prefix’ | ‘-p prefix’ | %name-prefix "prefix" |
‘--no-lines’ | ‘-l’ | %no-lines |
‘--output=file’ | ‘-o file’ | %output "file" |
‘--print-datadir’ | ||
‘--print-localedir’ | ||
‘--report-file=file’ | ||
‘--report=things’ | ‘-r things’ | |
‘--skeleton=file’ | ‘-S file’ | %skeleton "file" |
‘--token-table’ | ‘-k’ | %token-table |
‘--verbose’ | ‘-v’ | %verbose |
‘--version’ | ‘-V’ | |
‘--warnings[=category]’ | ‘-W [category]’ | |
‘--xml[=file]’ | ‘-x [file]’ | |
‘--yacc’ | ‘-y’ | %yacc |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The Yacc library contains default implementations of the
yyerror
and main
functions. These default
implementations are normally not useful, but POSIX requires
them. To use the Yacc library, link your program with the
‘-ly’ option. Note that Bison’s implementation of the Yacc
library is distributed under the terms of the GNU General
Public License (see section GNU GENERAL PUBLIC LICENSE).
If you use the Yacc library’s yyerror
function, you should
declare yyerror
as follows:
int yyerror (char const *); |
Bison ignores the int
value returned by this yyerror
.
If you use the Yacc library’s main
function, your
yyparse
function should have the following type signature:
int yyparse (void); |
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated by Rick Perry on December 29, 2013 using texi2html 1.82.