Your task is to write a program that will:
static int evaluate(String inputLine)
method. Thus, the code in your Frame might simply be:while (mr.hasMoreData()) { String nextLine = mr.giveMeTheNextLine(); emit(nextLine + "=" + PostFixEvaluator.evaluate(nextLine) + "\n"); }
StringTokenizer st = new StringTokenizer(s, "+-*/ ", true);
will work
well) -- or, if you prefer, learn to use a Scanner to do it.
Test your code to be sure it is generating the correct stream of tokens.Here is the algorithm presented in class:
while (more input) { nextToken = get next token if (nextToken is an operand) push(nextToken) else { // an operator x = pop(); y = pop(); push(y nextToken x); // need to implement the operation as a method } // else } emit(pop()); // the answer will be on top of the stack
String InfixToPostFix.convert(String)
method following
the algorithm presented in
lecture,
then...