%{
#include <stdio.h>
int lines
= 0; // To count the
number of lines
int spaces
= 0; // To count the
number of spaces
int tabs
= 0; // To count the
number of tab characters
int others
= 0; // To count the
number of other characters
%}
%%
\n { lines++; } // Count a new line
" " { spaces++; } // Count a space
"\t" { tabs++; } // Count a tab
. { others++; } // Count all other characters
%%
int main() {
yylex
(); // Call the Lex scanner
// Print the results
printf
("The
number of lines are
: %d\n", lines); printf
("The
number of spaces are
: %d\n", spaces); printf
("The
number of tab
-meta characters are
: %d\n", tabs); printf("The rest of the characters are: %d\n", others);
return 0;
}
JXsKI2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbGluZXMgPSAwOyAgICAvLyBUbyBjb3VudCB0aGUgbnVtYmVyIG9mIGxpbmVzCmludCBzcGFjZXMgPSAwOyAgIC8vIFRvIGNvdW50IHRoZSBudW1iZXIgb2Ygc3BhY2VzCmludCB0YWJzID0gMDsgICAgIC8vIFRvIGNvdW50IHRoZSBudW1iZXIgb2YgdGFiIGNoYXJhY3RlcnMKaW50IG90aGVycyA9IDA7ICAgLy8gVG8gY291bnQgdGhlIG51bWJlciBvZiBvdGhlciBjaGFyYWN0ZXJzCiV9CgolJQpcbiAgICAgICAgICAgICAgeyBsaW5lcysrOyB9ICAgICAgICAgICAgIC8vIENvdW50IGEgbmV3IGxpbmUKIiAiICAgICAgICAgICAgIHsgc3BhY2VzKys7IH0gICAgICAgICAgICAvLyBDb3VudCBhIHNwYWNlCiJcdCIgICAgICAgICAgICB7IHRhYnMrKzsgfSAgICAgICAgICAgICAgLy8gQ291bnQgYSB0YWIKLiAgICAgICAgICAgICAgIHsgb3RoZXJzKys7IH0gICAgICAgICAgICAvLyBDb3VudCBhbGwgb3RoZXIgY2hhcmFjdGVycwoKJSUKCmludCBtYWluKCkgewogICAgeXlsZXgoKTsgLy8gQ2FsbCB0aGUgTGV4IHNjYW5uZXIKICAgIC8vIFByaW50IHRoZSByZXN1bHRzCiAgICBwcmludGYoIlRoZSBudW1iZXIgb2YgbGluZX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