package simpledb.cs422; import java.io.IOException; import java.io.StreamTokenizer; import java.io.StringReader; public class StreamTokenizerTest { public static void main( String args[] ) throws IOException { String s = "SELECT * from t1, t2 where t1.a = t2.b and c >= 10 or d < 'hello'"; StreamTokenizer tokenizer = new StreamTokenizer( new StringReader( s ) ); tokenizer.lowerCaseMode( true ); do { tokenizer.nextToken(); switch( tokenizer.ttype ) { case StreamTokenizer.TT_NUMBER: System.out.println( "Number:\t\t\t" + tokenizer.nval ); break; case StreamTokenizer.TT_WORD: System.out.println( "Word:\t\t\t" + tokenizer.sval ); break; case StreamTokenizer.TT_EOL: System.out.println( "Eod of Line" ); break; case StreamTokenizer.TT_EOF: System.out.println( "End of Stream" ); break; /* single quote string */ case '\'': System.out.println( "Single-quote String:\t" + tokenizer.sval ); break; /* double quote string */ case '\"': System.out.println( "Double-quote String:\t" + tokenizer.sval ); break; /* single-character token */ default: System.out.println( "Single-character token:\t" + (char) tokenizer.ttype ); } } while( tokenizer.ttype != StreamTokenizer.TT_EOF ); } }