Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flex yylineno set to 1

Tags:

flex-lexer

I'm writing a simple parser for tcpdump logs, could you please tell me why I can't get proper 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);
...
like image 972
Wojciech Reszelewski Avatar asked Nov 09 '12 23:11

Wojciech Reszelewski


1 Answers

When I tried this, it turned out that I had to have a rule that actually matches newline for yylineno to be updated. With the following rule it worked, and without it yylineno never changed:

\n { }
like image 121
Thomas Padron-McCarthy Avatar answered Oct 25 '22 14:10

Thomas Padron-McCarthy