29 lines
470 B
Text
29 lines
470 B
Text
%{
|
|
#include <stdint.h>
|
|
|
|
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 <stdlib.h>
|
|
|
|
int main(void) {
|
|
|
|
yylex();
|
|
|
|
printf("%d %d\n", line_count, word_count);
|
|
|
|
return EXIT_SUCCESS;
|
|
}
|