%{ // based on the flex manual, chapter 4, count bytes and lines // using yylineno to count the lines // extern int fileno(FILE *); /* to avoid gcc warning */ int num_chars = 0; %} %option yylineno %% .|\n ++num_chars; %% void (*jj_junk)(int,char *) = yyunput; /* avoid gcc warnings */ int (*jj2_junk)(void) = input; int main( void) { yylex(); printf( "# of lines = %d, # of chars = %d\n", yylineno-1, num_chars ); return 0; }