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


9.1.1 Operation Modes

Options controlling the global behavior of bison.

-h
--help

Print a summary of the command-line options to Bison and exit.

-V
--version

Print the version number of Bison and exit.

--print-localedir

Print the name of the directory containing locale-dependent data.

--print-datadir

Print the name of the directory containing skeletons, CSS and XSLT.

-u
--update

Update the grammar file (remove duplicates, update deprecated directives, etc.) and exit (i.e., do not generate any of the output files). Leaves a backup of the original file with a ~ appended. For instance:

$ cat foo.y
%error-verbose
%define parse.error verbose
%%
exp:;
$ bison -u foo.y
foo.y:1.1-14: warning: deprecated directive, use '%define parse.error verbose' [-Wdeprecated]
    1 | %error-verbose
      | ^~~~~~~~~~~~~~
foo.y:2.1-27: warning: %define variable 'parse.error' redefined [-Wother]
    2 | %define parse.error verbose
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~
foo.y:1.1-14:     previous definition
    1 | %error-verbose
      | ^~~~~~~~~~~~~~
bison: file 'foo.y' was updated (backup: 'foo.y~')
$ cat foo.y
%define parse.error verbose
%%
exp:;

See the documentation of --feature=fixit below for more details.

-f [feature]
--feature[=feature]

Activate miscellaneous features. 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-diagnostics. 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:

%nterm <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'
    3 | exp: exp '+' exp { $exp = $1 + $2; };
      |                    ^~~~
in.y:3.1-3:       refers to: $exp at $$
    3 | exp: exp '+' exp { $exp = $1 + $2; };
      | ^~~
in.y:3.6-8:       refers to: $exp at $1
    3 | exp: exp '+' exp { $exp = $1 + $2; };
      |      ^~~
in.y:3.14-16:     refers to: $exp at $3
    3 | exp: exp '+' exp { $exp = $1 + $2; };
      |              ^~~
in.y:3.32-33: error: $2 of 'exp' has no declared type
    3 | 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.

fixit
diagnostics-parseable-fixits

Show machine-readable fixes, in a manner similar to GCC’s and Clang’s -fdiagnostics-parseable-fixits.

Fix-its are generated for duplicate directives:

$ cat foo.y
%define api.prefix {foo}
%define api.prefix {bar}
%%
exp:;

$ bison -ffixit foo.y
foo.y:2.1-24: error: %define variable 'api.prefix' redefined
    2 | %define api.prefix {bar}
      | ^~~~~~~~~~~~~~~~~~~~~~~~
foo.y:1.1-24:     previous definition
    1 | %define api.prefix {foo}
      | ^~~~~~~~~~~~~~~~~~~~~~~~
fix-it:"foo.y":{2:1-2:25}:""
foo.y: warning: fix-its can be applied.  Rerun with option '--update'. [-Wother]

They are also generated to update deprecated directives, unless -Wno-deprecated was given:

$ cat /tmp/foo.yy
%error-verbose
%name-prefix "foo"
%%
exp:;
$ bison foo.y
foo.y:1.1-14: warning: deprecated directive, use '%define parse.error verbose' [-Wdeprecated]
    1 | %error-verbose
      | ^~~~~~~~~~~~~~
foo.y:2.1-18: warning: deprecated directive, use '%define api.prefix {foo}' [-Wdeprecated]
    2 | %name-prefix "foo"
      | ^~~~~~~~~~~~~~~~~~
foo.y: warning: fix-its can be applied.  Rerun with option '--update'. [-Wother]

The fix-its are applied by bison itself when given the option -u/--update. See its documentation above.

syntax-only

Do not generate the output files. The name of this feature is somewhat misleading as more than just checking the syntax is done: every stage is run (including checking for conflicts for instance), except the generation of the output files.


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