import java.io.IOException;
import java.io.StreamTokenizer;
/*
 * ParseTools - this class contains a number of useful
 *              methods for parsing.
 * Eric McCreath - 2006
 */
public class ParseTools {
	static Boolean isWord(StreamTokenizer stream, String word) {
		return stream.ttype == StreamTokenizer.TT_WORD && stream.sval.equals(word);	
	}
	
	static void parseWord(StreamTokenizer stream, String word) throws IOException {
		if (!(stream.ttype == StreamTokenizer.TT_WORD && stream.sval.equals(word))) {
			System.out.println("Problem parsing, exepect : " + word + " line : " + stream.lineno());
			System.exit(1);
		}
		stream.nextToken();
	}
	
	static String parseQuote(StreamTokenizer stream) throws IOException {
		if (!(stream.ttype == '"')) {
			System.out.println("Problem parsing, quote exepect line : " + stream.lineno());
			System.exit(1);
		}
		String res = stream.sval;
		stream.nextToken();
		return res;
	}
	
	static Integer parseInteger(StreamTokenizer stream) throws IOException {
		if (!(stream.ttype == StreamTokenizer.TT_NUMBER)) {
			System.out.println("Problem parsing integer  line : " + stream.lineno());
			System.exit(1);
		}
		Integer res = (int) Math.round(stream.nval);
		stream.nextToken();
		return res;
	}
	
}

