Next: Start Decl, Previous: Printer Decl, Up: Declarations [Contents][Index]
Bison normally warns if there are any conflicts in the grammar
(see Shift/Reduce Conflicts), but most real grammars
have harmless shift/reduce conflicts which are resolved in a predictable
way and would be difficult to eliminate. It is desirable to suppress
the warning about these conflicts unless the number of conflicts
changes. You can do this with the %expect
declaration.
The declaration looks like this:
%expect n
Here n is a decimal integer. The declaration says there should be n shift/reduce conflicts and no reduce/reduce conflicts. Bison reports an error if the number of shift/reduce conflicts differs from n, or if there are any reduce/reduce conflicts.
For deterministic parsers, reduce/reduce conflicts are more serious, and should be eliminated entirely. Bison will always report reduce/reduce conflicts for these parsers. With GLR parsers, however, both kinds of conflicts are routine; otherwise, there would be no need to use GLR parsing. Therefore, it is also possible to specify an expected number of reduce/reduce conflicts in GLR parsers, using the declaration:
%expect-rr n
In general, using %expect
involves these steps:
%expect
. Use the ‘-v’ option
to get a verbose list of where the conflicts occur. Bison will also
print the number of conflicts.
%expect
declaration, copying the number n from the
number which Bison printed. With GLR parsers, add an
%expect-rr
declaration as well.
Now Bison will report an error if you introduce an unexpected conflict, but will keep silent otherwise.
Next: Start Decl, Previous: Printer Decl, Up: Declarations [Contents][Index]