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


9.1.2 Diagnostics

Options controlling the diagnostics.

-W [category]
--warnings[=category]

Output warnings falling in category. category can be one of:

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.

counterexamples
cex

Provide counterexamples for conflicts. See section Generation of Counterexamples. Counterexamples take time to compute. The option -Wcex should be used by the developer when working on the grammar; it hardly makes sense to use it in a CI.

dangling-alias

Report string literals that are not bound to a token symbol.

String literals, which allow for better error messages, are (too) liberally accepted by Bison, which might result in silent errors. For instance

%type <exVal> cond "condition"

does not define “condition” as a string alias to cond—nonterminal symbols do not have string aliases. It is rather equivalent to

%nterm <exVal> cond
%token <exVal> "condition"

i.e., it gives the ‘"condition"’ token the type exVal.

Also, because string aliases do not need to be defined, typos such as ‘"baz"’ instead of ‘"bar"’ will be not reported.

The option -Wdangling-alias catches these situations. On

%token BAR "bar"
%type <ival> foo "foo"
%%
foo: "baz" {}

bison -Wdangling-alias reports

warning: string literal not attached to a symbol
      | %type <ival> foo "foo"
      |                  ^~~~~
warning: string literal not attached to a symbol
      | foo: "baz" {}
      |      ^~~~~
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.

midrule-values

Warn about midrule 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 midrule values that are used but not set. For example, warn about unset $$ in the midrule 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).

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 "*" "number"
| "(" exp ")"
| "number"
;

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 "*"
yacc

Incompatibilities with POSIX Yacc.

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 counterexamples, dangling-alias and 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.

-Werror

Turn enabled warnings for every category into errors, unless they are explicitly disabled by -Wno-error=category.

-Werror=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
-Wno-error

Do not turn enabled warnings for every category into errors, unless they are explicitly enabled by -Werror=category.

-Wno-error=category

Deactivate the error treatment for this category. However, the warning itself won’t be disabled, or enabled, by this option.

--color

Equivalent to --color=always.

--color=when

Control whether diagnostics are colorized, depending on when:

always
yes

Enable colorized diagnostics.

never
no

Disable colorized diagnostics.

auto (default)
tty

Diagnostics will be colorized if the output device is a tty, i.e. when the output goes directly to a text screen or terminal emulator window.

--style=file

Specifies the CSS style file to use when colorizing. It has an effect only when the --color option is effective. The bison-default.css file provide a good example from which to define your own style file. See the documentation of libtextstyle for more details.


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