%{ #include uint32_t line_count = 0; uint32_t word_count = 0; %} %% ^[[:blank:]]*\n [[:blank:]]+$ ^[[:blank:]]+ [[:blank:]]+ { putchar(' '); } \n { line_count += 1; ECHO; } [[:^space:]]+ { word_count += 1; ECHO; } . { ECHO; } %% // https://westes.github.io/flex/manual/Patterns.html #include int main(void) { yylex(); printf("%d %d\n", line_count, word_count); return EXIT_SUCCESS; }