Flex yylineno set to 1

I am writing a simple parser for tcpdump logs, could you tell me why I cannot get the correct line number?

%{ char str[80]; %} %option yylineno ... %% ^{HOURS}:{MINUTES}:{MINUTES} if(input()=='.') { strcpy(str, yytext); BEGIN(A); } else {printf("Wrong hour %d", yylineno); } <A>({NDPS}|{DPS})\.({NDPS}|{DPS})\.({NDPS}|{DPS})|\.{NDPS} printf("Wrong IP!, %d", yylineno); <A>[ ]{DPS}\.{DPS}\.{DPS}\.{DPS} strcat(str, " from "); strcat(str, yytext+1); BEGIN(B); ... 
+7
source share
1 answer

When I tried this, it turned out that I should have a rule that actually matches the new line for updating yylineno. It worked with the following rule, and without it yylineno never changed:

 \n { } 
+11
source

All Articles