import java.io.*; %% %class ex1 %unicode %line %column %{ //these variables are defined static because they will be referenced in main, a static method static int charCount = 0, wordCount = 0, lineCount = 0; public static void main(String [] args) throws IOException { //create a scanner and use the scanner's yylex function //if you want standard input, System.in instead of new FileReader(args[0]) ex1 lexer = new ex1(new FileReader(args[0])); lexer.yylex(); System.out.println("Characters: " + charCount + " Words: " + wordCount +" Lines: " +lineCount); } %} %type Object //this line changes the return type of yylex into Object word = [^ \t\n\r]+ %% {word} {wordCount++; charCount += yytext().length(); } [\n] {charCount++; lineCount++; } [\r] {} . {charCount++; }