%{
#include <stdio.h>
int line_count = 0;
int tab_count = 0;
int space_count = 0;
int word_count = 0;
int char_count = 0;
int in_word = 0;
%}
%%
\n { line_count++; char_count++; }
\t { tab_count++; char_count++; }
" " { space_count++; char_count++; in_word = 0; }
[^ \t\n]+ { word_count += !in_word; in_word = 1; char_count += yyleng; }
. { char_count++; }
%%
int main(int argc, char *argv[]) {
if (argc < 2) {
fprintf(stderr, "Usage: %s <input_file>\n", argv[0]);
return 1;
}
FILE *file = fopen(argv[1], "r");
if (!file) {
perror("Error opening file");
return 1;
}
yyin = file;
yylex();
fclose(file);
printf("Lines: %d\n", line_count);
printf("Tabs: %d\n", tab_count);
printf("Spaces: %d\n", space_count);
printf("Words: %d\n", word_count);
printf("Characters: %d\n", char_count);
return 0;
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbGluZV9jb3VudCA9IDA7CmludCB0YWJfY291bnQgPSAwOwppbnQgc3BhY2VfY291bnQgPSAwOwppbnQgd29yZF9jb3VudCA9IDA7CmludCBjaGFyX2NvdW50ID0gMDsKaW50IGluX3dvcmQgPSAwOwolfQoKJSUKXG4gICAgICB7IGxpbmVfY291bnQrKzsgY2hhcl9jb3VudCsrOyB9Clx0ICAgICAgeyB0YWJfY291bnQrKzsgY2hhcl9jb3VudCsrOyB9CiIgIiAgICAgeyBzcGFjZV9jb3VudCsrOyBjaGFyX2NvdW50Kys7IGluX3dvcmQgPSAwOyB9ClteIFx0XG5dKyB7IHdvcmRfY291bnQgKz0gIWluX3dvcmQ7IGluX3dvcmQgPSAxOyBjaGFyX2NvdW50ICs9IHl5bGVuZzsgfQouICAgICAgIHsgY2hhcl9jb3VudCsrOyB9CgolJQoKaW50IG1haW4oaW50IGFyZ2MsIGNoYXIgKmFyZ3ZbXSkgewogICAgaWYgKGFyZ2MgPCAyKSB7CiAgICAgICAgZnByaW50ZihzdGRlcnIsICJVc2FnZTogJXMgPGlucHV0X2ZpbGU+XG4iLCBhcmd2WzBdKTsKICAgICAgICBy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