user7191645
user7191645

Reputation: 19

F(Lex) WARNING , rule cannot be matched

    EOL \n
    WS(" "|\t|\n)
    WSS {WS}*
    NEWSS {WSS}+
    NAME [a-zA-z_][a-zA-z0-9_-]*
    WORD [^;]+
    IMPORT {NEWSS}'{NAME}'{WSS};
    VAL [a-zA-z0-9]+
    CONTENT [^}]+
    MIX {NEWSS}{NAME}{WSS}[(]
    INCLUDE {WSS}{NAME}{WSS}[{]

    %s DOTAIM
    %s NAMESTATE
    %s NAMER
    %s CONTENT
    %s VALUE
    %s INC

    %%
    ${NAME} {key=yytext;BEGIN(NAMESTATE);}
    . {output+=yytext;}
    \n {output+=yytext;} 
  45)  <NAMESTATE>; {if(var.find(key)==var.end()){output="Unknown variable";return 1;};output+=(var[key]+yytext);BEGIN(INITIAL);}
    <NAMESTATE>{WSS}:{WSS} {BEGIN(DOTAIM);}
    <DOTAIM>{WORD}{WSS} {val=trim(yytext); var[key]=val;}
   48) <DOTAIM>; {BEGIN(INITIAL);}

This is my code and I keep getting this warning:

hello.lex:45: warning, rule cannot be matched
hello.lex:48: warning, rule cannot be matched

Does anyone know why? Because these are in states and line 43 is not preventing them to match.

Upvotes: 0

Views: 1478

Answers (1)

rici
rici

Reputation: 241741

You declare your start conditions as inclusive (%s): as the manual indicates, "If the start condition is inclusive, then rules with no start conditions at all will also be active."

So the . at line 43 will be active and prevent the ; from matching.

Moving the fallback rule to the end of the rules would fix the problem, and it is generally best style even if you have start conditions.

Upvotes: 0

Related Questions