public class Lex { public Lex() { input = nextInput(); state = 1; } // inputs final int ZERO = 0; final int ONE = 1; final int TWO = 2; final int POINT = 3; final int STAR = 4; // actions final int NEXT = 0; final int RETURN = 1; final int BACK = 2; final int ERROR = 3; // lexemes final int REAL = 0; final int MULT = 1; final int EXP = 2; private int state; private int table1 [] []; // first index is current state, second is input private int table2 [] []; // first index is current state, second is input private int input; private int nextInput(){ . . . } // assigns the next character to c //initialize table1 and table2 public int nextLexeme() { state = 1; // reading loop while (true) { switch (table1[state][input]) { case NEXT: state = table2[state][input]; input = nextInput(); // a normal state transition case RETURN: input = nextInput(); return (table2[state][input]); // a lexical category is completed (including the last character read) case BACK: return (table2[state][input]); // a lexical category is completed (the last character read is not included) case ERROR: return(0); // the last character read represents an error } } } }