CS231 lecture notes, Fall 1998 Week 8, Wednesday 1) Started with Eval 2) Found two ways to convert characters to integers: for (int i=0; i123+? Operand Operand Operand Operator Error =>1+-\*/ Operand Operator Operator Error Operator Operator 6) Wrote precedence and outranks public static int precedence (char c) { switch (c) { case '+': case '-': return 0; case '*': case '/': return 1; default: System.out.println ("Error in precedence: non-operator"); System.exit(1); } } public static boolean outranks (char c, char d) { return (precedence(c) > precedence (d)); } They compile, but I didn't bother testing them. Lazy. 7) Copy a String into a StringBuffer StringBuffer out = new StringBuffer (line.length()); for (int i=0; i1+2-3 12+3- =>1+2*3 123*+ =>1*(2+3) 123+(* Oops, that last one doesn't look so good. I think in dealWithCloser I should not be peeking at the open parenthesis; I should go ahead and pop it: public static void dealWithCloser (StringBuffer out, Stack stack) { while (!stack.empty()) { char pending = ((Character) stack.pop()).charValue(); if (pending == '(') break; out.append (pending); } } That did it! 12) Last step is to put it all together: Have to change evaluate to take a StringBuffer instead of a String. StringBuffer postfix = translate (infix); System.out.println (postfix); int res = evaluate (postfix); System.out.println (res);