/*
* 归约函数, 从操作数栈和操作符栈各弹出一个元素,
* 与操作数栈顶的元素(并未弹出)运算后, 结果存在操作栈顶的元素中.
*/
void calculate(ArrayStack &operandStack, ArrayStack &operatorStack){
if(operandStack.getSize() < 2){
return;
}
Token *t1 = operandStack.pop();
Token *t2 = operandStack.peek();
Token *op = operatorStack.pop();
switch(op->type){
case ''*'':
t2->value *= t1->value;
break;
case ''/'':
t2->value /= t1->value;
break;
case ''+'':
t2->value += t1->value;
break;
case ''-'':
t2->value -= t1->value;
break;
default:
printf("*********Syntax Error!*********\n");
exit(1);
break;
}
}
int main(int argc, char *argv){
char buffer[256];
if(argc > 1){
strcpy(buffer, argv);
}else{
printf("Input the statement(1-256 characters):\n");
scanf("%s", buffer);
}
ArrayStack operan