Search code examples
warningsyaccbisonlex

Bison build warning: "-s option given but default rule can be matched"


I get the warning

warning, -s option given but default rule can be matched

if you google "option given but default rule can be matched", you'll find the Flex manual's chapter on Diagnostics and this entry in an old Flex manpage in the Diagnostics section:

warning, '-s option given but default rule can be matched' means that it is possible (perhaps only in a particular start condition) that the default rule (match any single character) is the only one that will match a particular input. Since -s was given, presumably this is not intended.

My build file doesn't have a -s option. I wrote

bison -y -d calc1.y
flex calc1.l
gcc code...

How do I fix this warning?

Here is a tiny version of my lex file. This file also triggers the warning

%{
#include "y.tab.h"
%}
%option noyywrap nodefault yylineno

%%

[0-9]+      {
                return INTEGER;
            }

[-+()=/*{},;\n] { return *yytext; }

[ \t]       /* skip whitespace */

[a-zA-Z0-9_]* { printf("lex Unknown character = '%s'", yytext); yyerror("lex Unknown character"); }

%%

Solution

  • %option nodefault is equivalent to -s