%% %class CountComments %standalone %state COMMENT %{ int ziffern, bezeichner, lines, codeL, commL; %} %eof{ System.out.println("Bezeichner:"+bezeichner); System.out.println("Ziffern:"+ziffern); System.out.println("Lines (total):"+lines); System.out.println("Code Lines:"+codeL); System.out.println("Comment Lines:"+commL); %eof} %% { "/*" {yybegin(COMMENT); System.out.println("[begin of comment]");} [a-zA-Z]+ {bezeichner++; System.out.println("Bezeichner: " + yytext());} [0-9] {ziffern++;} \n {codeL++;lines++;} . {} } { \n {commL++;lines++;} "*/" {yybegin(YYINITIAL); System.out.println("[end of comment]");} . {} }