import java.util.StringTokenizer; /** * Implements the lexical analysis of our programs. The * implementation uses a StringTokenizer from Java's library. * * @author Marcel Turcotte */ class Reader { // instance variable private StringTokenizer st; /** * Create a Reader object for the parameter string. */ Reader( String s ) { st = new StringTokenizer( s ); } /** * Tests if the end of the program has been reached. * * @return true if the Reader has reached the end of the input (program). */ public boolean hasMoreTokens() { return st.hasMoreTokens(); } /** * Reads and returns the next token. * * @return The next Token from the input. */ public Token nextToken() { String t = st.nextToken(); try { return new Token( Integer.parseInt( t ) ); } catch ( NumberFormatException e ) { return new Token( t ); } } }