jftt/l2/1.lex

30 lines
470 B
Text
Raw Permalink Normal View History

2024-11-03 22:05:19 +01:00
%{
#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;
}