%{ #include int codeLines = 0, commentLines = 0, blankLines = 0; int currCodeLine = 0, currCommentLine = 0; %} %option noyywrap %x COMMENT %% "/*" { BEGIN COMMENT; currCommentLine = 1; } "*/" { BEGIN INITIAL; currCommentLine = 1; } <*>[ \t] { /* Blank, Tab ignorieren */ } . { currCodeLine = 1; } . { currCommentLine = 1; } <*>"\n" { if(currCodeLine) codeLines++; else if(currCommentLine) commentLines++; else blankLines++; currCodeLine = 0; currCommentLine = 0; } /* Die letzte Zeile muss mit einem Newline abgeschlossen sein. */ %% int main() { yylex(); printf( "%d Code-Zeilen, %d Nur-Kommentar-Zeilen, %d ganz leere Zeilen\n", codeLines, commentLines, blankLines); }