Search code examples
bisonflex-lexerlex

why i got this warning "rule cannot be matched" in my Lexer Program


I have this code in flex program ".l"

"if" {return IF;}
"else" {return ELSE;}
"For" {return FOR;}
. {printf("SYNTAX ERROR .. EXIT ..");exit(0);}

and this code in bison program ".y"

%token IF ELSE FOR

but i got that error of

warning, rule cannot be matched
warning, rule cannot be matched
warning, rule cannot be matched

Solution

  • i found the problem

    i needed to write the code on a single line like this

    "if" { return IF; }
    

    and not like this

    "if" {
        return IF;
    }