import java.io.Reader; import java.io.IOException; import java.io.StreamTokenizer; public class CompactTokenizer { private StreamTokenizer st; CompactTokenizer(Reader r){ st = new StreamTokenizer(r); st.resetSyntax(); // remove parsing of numbers... st.wordChars('\u0000','\u00FF'); // everything is part of a word // except the following... st.ordinaryChar('\n'); st.ordinaryChar('['); st.ordinaryChar(']'); st.ordinaryChar('@'); } public String nextToken() throws IOException{ st.nextToken(); while(st.ttype=='\n'|| (st.ttype==StreamTokenizer.TT_WORD && st.sval.trim().length()==0)) st.nextToken(); return getToken(); } public String getToken(){ return (st.ttype == StreamTokenizer.TT_WORD) ? st.sval : (""+(char)st.ttype); } public String skip(String sym) throws IOException { if(getToken().equals(sym)) return nextToken(); else throw new IllegalArgumentException("skip: "+sym+" expected but"+ sym +" found "); } }