%{ #include #include int codecount = 0; int commcount = 0; int blankcount = 0; int linecount = 0; int comments = 0; int code = 0; %} %option noyywrap %option main %x COMMENT %% "/*" { BEGIN COMMENT; comments = 1; } "*/" /* zählt nicht! */ [^[:space:]] code = 1; \n { linecount++; if (comments) {commcount++;} if (code) {codecount++;} if (!comments && !code) {blankcount++;} comments = 0; code = 0; } . /* nix */ { "*/" BEGIN INITIAL; \n { linecount++; commcount++; if (code) {codecount++;} code = 0; } . /* nix */ } <> { printf("%d Zeilen insgesamt, davon\n%d Zeilen mit Code,\n%d Zeilen mit Kommentaren, und\n%d Leerzeilen.\n", linecount, codecount, commcount, blankcount); exit(0); }