private static int driver() // This is the driver of the FA. // If a valid token is found, assigns it to "t" and returns 1. // If an invalid token is found, assigns it to "t" and returns 0. // If end-of-stream is reached without finding any non-whitespace character, returns -1. { State nextSt; // the next state of the FA t = ""; state = State.Start; if (Character.isWhitespace((char) a)) a = getChar(); // get the next non-whitespace character if (a == -1) // end-of-stream is reached return -1; while (a != -1) // do the body if "a" is not end-of-stream { c = (char) a; nextSt = nextState[state.ordinal()][a]; if (nextSt == State.UNDEF) // The FA will halt. { if (isFinal(state)) return 1; // valid token extracted else // "c" is an unexpected character { t = t + c; a = getNextChar(); return 0; // invalid token found } } else // The FA will go on. { state = nextSt; t = t + c; a = getNextChar(); } } // end-of-stream is reached while a token is being extracted if (isFinal(state)) return 1; // valid token extracted else return 0; // invalid token found } // end driver