void do_arith (bigint_stack& stack, const char oper) { if (stack.size() < 2) throw ydc_exn ("stack empty"); bigint right = stack.top(); stack.pop(); DEBUGF ('d', "right = " << right); bigint left = stack.top(); stack.pop(); DEBUGF ('d', "left = " << left); bigint result; switch (oper) { case '+': result = left + right; break; case '-': result = left - right; break; case '*': result = left * right; break; case '/': result = left / right; break; case '%': result = left % right; break; case '^': result = pow (left, right); break; default: throw invalid_argument ( string ("do_arith operator is ") + oper); } DEBUGF ('d', "result = " << result); stack.push (result); }
void do_print (bigint_stack& stack, const char) { cout << stack.top() << endl; }
void do_dup (bigint_stack& stack, const char) { bigint top = stack.top(); DEBUGF ('d', top); stack.push (top); }
void do_print (bigint_stack& stack, const char) { if(stack.isempty()){ throw ydc_exn("ydc: stack is empty"); }else cout << stack.top() << endl; }