%{ #include using namespace std; int charCount = 0, wordCount = 0, lineCount = 0; %} word [^ \t\n]+ %% {word} {wordCount++; charCount += yyleng; } [\n] {charCount++; lineCount++; } . {charCount++; } %% main() { yylex(); cout << "Characters: " << charCount; cout << " Words: " << wordCount; cout << " Lines: " << lineCount << endl; }