package rpn; import java.util.*; import java.io.*; //Throw a ParseException if the token is not recognized class ParseException extends IOException { ParseException(String s) { super(s); } } public class FormStream extends StreamTokenizer { // short names for StreamTokenizer codes public static int NUM = StreamTokenizer.TT_NUMBER; public static int EOF = StreamTokenizer.TT_EOF; private RPNEngine _rPNEngine; public FormStream(Reader reader, RPNEngine rPNEngine) throws IOException { super(new BufferedReader(reader)); _rPNEngine = rPNEngine; ordinaryChar((int)'/'); // make sure '/' is treated like any other char } public void parse() throws IOException { int token = nextToken(); while(token != EOF) { if (token == NUM) { // Push something...but what? // Hint: it is a field within StreamTokenizer. // Check the API or the example tokenizer from tutorial 9. } else if (token == '+') { // Do add operation } // Need more if-else statements for the other operators ... // ... else { throw new ParseException("Come again?"); } token = nextToken(); } } }