/**
 * @author David
 * 
 * String Tokenizer, with simple handling
 *  Created on Sep 15, 2007 for CS 210
 */


import java.io.*;

public class ST {
	public static void readTokens(String file) throws IOException {
		// set up a StreamTokenizer to read from specified file
		FileReader fileIn = new FileReader(file);
		StreamTokenizer in = new StreamTokenizer(fileIn);
		// customization:  
		// - '/' alone is not an end-of-line comment
		// - recognize "//" and "/*" comments
		in.ordinaryChar('/');
		in.slashSlashComments(true);
		in.slashStarComments(true);
		// if 0-9 are "ordinary", it won't treat numbers specially
		//-// in.ordinaryChars('0','9');
		while (in.nextToken() != StreamTokenizer.TT_EOF) {
			switch (in.ttype) {
			case StreamTokenizer.TT_WORD:
				System.out.println("text: " + in.sval);
				break;
			case StreamTokenizer.TT_NUMBER:
				System.out.println(" Num: " + in.nval);
				break;
			default:
				// if not a 'word' or 'number', it must be a
				// symbol:  then ttype holds the character code.
				System.out.println("spec: " + (char)in.ttype);
			}

		}
	}

	// simple test of readTokens ..
	
	public static void main(String[] file) {
		System.out.println("Starting with file " + file[0]);
		try {
			ST.readTokens(file[0]);
		} 
		catch (Exception e) {
			System.out.println("OOPS, problem - " + e);
		}
		finally {
			System.out.println("...All done");
		}
		;
	}

}

