%{ // from the flex manual, chapter 4, count bytes and lines // extern int fileno(FILE *); /* to avoid gcc warning */ %} int num_lines = 0, num_chars = 0; %% \n ++num_lines; ++num_chars; . ++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", num_lines, num_chars ); return 0; }