The CS211In class is something called a tokenizer. CS211In can take a file or command line input and can deconstruct the file or input into strings and characters. This process is called PARSING. The actual string or character that CS211In returns to you is called a TOKEN. A token is EATEN if the class moves to the next token. See the example on the bottom of this document. OK, so you now have the basic vocabulary of tokenizers, here are all the methods in the CS211In class... ---------------------- Constructors ---------------------- public CS211In (String FileName) - This constructor takes in a file name as input and will parse the file. If the file is not found, the class will print out an error message. public CS211In (Reader r) - Opens the reader for input. You can look at all the Reader classes in the API. public CS211In() - Opens System.in for input. Again, look at the API if you don't know what it is. ---------------------- Methods ---------------------- public int getInt() - If the next token is an int, it returns the int token. If it's not an int, it throws an exception. This will eat the token. public String getWord() - Same as getInt() except returns a String. public char getOp() - Same as getInt() except it returns a char that represents an operator +,-,#,*,(,). public int peekAtKind() - Returns the type of the next token. There are 4 types of tokens: INTEGER, WORD, OPERATOR, EOF. These types are defined as integer constants in CS211InInterface.java. So if the next token is '6', then it will return -1 which is the same as CS211In.INTEGER. The token read is not eaten. public void match() - Either takes in a char or String as input. If the next token matches the char or String passed in, then nothing happens. Otherwise an error message is printed out. Whether the token matches or not, the token is eaten. public boolean check() - Either takes in a char or String as input. If the next token matches the char or String passed in, then the token is eaten and the method returns true. If it doesn't match, the method returns false, but the token is not eaten. public void pushBack() - Pushes the current token back one token. public int lineNo() - Returns the line number at which the current token is. public void close() - Closes the reader passed in. Make sure you always do this when you are done parsing. --------------------------- Example --------------------------- Let's say I have a file called "testInput.txt" that has the following text: (6+4)-2 ^ The ^ means that the above character will be the next character that will be eaten. So let's write some code... CS211In tokenizer = new CS211In("testInput.txt"); char a = tokenizer.getOp(); So now a will have the value '(' and the state of our tokenizer is now... (6+4)-2 ^ tokenizer.match('1'); tokenizer.match('+'); Since match() eats the token no matter what, the '1' is found but the '+' is not found. The state of the tokenizer would now be... (6+4)-2 ^ boolean b = tokenizer.check('2'); boolean c = tokenizer.check('4'); Since check eats the token only when the input matches the token, b gets the value false, but the token '4' is not eaten. c then gets the value true, and the token '4' is eaten. The state is now... (6+4)-2 ^ -------------------------------------------------------------------------------------------- Any questions? Confused? E-mail me if you do... rgl8@cornell.edu