int iType;
double tmp;
while ((iType = tf.nextToken()) != tf.TT_EOF) {
switch(iType) {
case StreamTokenizer.TT_NUMBER: // Found a number, push value to stack
push(tf.nval);
break;
case StreamTokenizer.TT_WORD:
// Found a variable, save its name. Not used here. */
variable = tf.sval;
break;
case '+":
// Found + operator, perform it immediately.
push(pop() + pop());
break;
case '-":
// Found + operator, perform it (order matters).
tmp = pop();
push(pop() - tmp);
break;
case '*":
// Multiply works OK
push(pop() * pop());
break;
case '/":
// Handle division carefully: order matters!
tmp = pop();
push(pop() / tmp);
break;
case '=":
System.out.println(peek());
break;
default:
System.out.println("What's this? iType = " + iType);
}
}