Next: Tuning the Parser, Previous: Operation Modes, Up: Bison Options [Contents][Index]
Options controlling the diagnostics.
-W [category]--warnings[=category]Output warnings falling in category. category can be one of:
conflicts-srconflicts-rrS/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.
dangling-aliasReport 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" {}
| ^~~~~
deprecatedDeprecated constructs whose support will be removed in future versions of Bison.
empty-ruleEmpty rules without %empty. See Empty Rules. Disabled by
default, but enabled by uses of %empty, unless
-Wno-empty-rule was specified.
midrule-valuesWarn 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).
precedenceUseless 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 "*"
yaccIncompatibilities with POSIX Yacc.
otherAll 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.
allAll the warnings except dangling-alias and yacc.
noneTurn off all the warnings.
errorSee -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.
-WerrorTurn enabled warnings for every category into errors, unless they are explicitly disabled by -Wno-error=category.
-Werror=categoryEnable 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-errorDo not turn enabled warnings for every category into errors, unless they are explicitly enabled by -Werror=category.
-Wno-error=categoryDeactivate the error treatment for this category. However, the warning itself won’t be disabled, or enabled, by this option.
--colorEquivalent to --color=always.
--color=whenControl whether diagnostics are colorized, depending on when:
alwaysyesEnable colorized diagnostics.
nevernoDisable colorized diagnostics.
auto (default)ttyDiagnostics 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=fileSpecifies 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: Tuning the Parser, Previous: Operation Modes, Up: Bison Options [Contents][Index]