1 import java.io.IOException; 2 import java.io.StreamTokenizer; 3 import java.io.StringReader; 4 5 public class PR141 { test(String str)6 public static void test(String str) throws IOException { 7 StringReader reader = new StringReader(str); 8 StreamTokenizer st = new StreamTokenizer(reader); 9 int t = 0; 10 11 do { 12 t = st.nextToken(); 13 14 switch (t) { 15 case StreamTokenizer.TT_WORD: 16 System.out.println("[TT_WORD]: " + st.sval); 17 break; 18 case StreamTokenizer.TT_NUMBER: 19 System.out.println("[TT_NUMBER]: " + st.nval); 20 break; 21 case StreamTokenizer.TT_EOL: 22 System.out.println("[TT_EOL]"); 23 break; 24 case StreamTokenizer.TT_EOF: 25 System.out.println("[TT_EOF]"); 26 break; 27 default: 28 System.out.println((char)t); 29 break; 30 } 31 } while (t != StreamTokenizer.TT_EOF); 32 } 33 main(String[] args)34 public static void main(String[] args) { 35 try { 36 test("(a).(b)"); 37 } catch (Throwable t) { 38 t.printStackTrace(); 39 } 40 } 41 } 42