//main method from Parse/Main.java //java.io.IOException takes care of going off end of line with a //token construct public static void main(String argv[]) throws java.io.IOException { String filename = argv[0]; //puts command line arg into filename //creates new ErrorMsg object for this file ErrorMsg errorMsg = new ErrorMsg(filename); //creates new input stream corresponding to file input java.io.InputStream inp=new java.io.FileInputStream(filename); //creates new scanner object and stores reference to it //each scanner has its own ErrorMsgg object, errorMsg //and input stream inp //in reference to interface Lexer. this promises the nextToken() //method is implemented for object referred to by lexer. Lexer lexer = new Yylex(inp,errorMsg); //Main.java uses java_cup.runtime class Symbol //you need the right CLASSPATH to have access to this class; //the class is used to report tokens to the parser java_cup.runtime.Symbol tok; //loop to read the tokens in the file do { tok=lexer.nextToken(); //prints out symbolic name for token, and staring character //the input stream "123 A5" returns INT 0 (newline) ID 4 //since string positions start at position 0 System.out.println(symnames[tok.sym] + " " + tok.left); } while (tok.sym != sym.EOF); //look ends when see end of file character //cleanup stream by closing it inp.close(); }