jftt/l2/1.l
2024-11-03 22:05:19 +01:00

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;
}