字符串中求算术表达式的值解决思路

字符串中求算术表达式的值
随便输入一个字符串如“3+3*5”
求这个字符串中算术表达式的值。
只要求+-*/运算
请给一个好的算法   最好能给实现了

------解决方案--------------------
以下的程序可以正确计算:14*2*2/7/2*2/2/2+1+8-9-3+4*5-6+5*5/5+4-6/3*2
=====================================
14*2*2/7/2*2/2/2+1+8-9-3+4*5-6+5*5/5+4-6/3*2 is compiled OK
result is: 18.000000
Press any key to continue
=====================================
bool compile(char* string);
double implement(double oprant1,double oprant2,char op);
double calculator(char** ptExp);
double loadOperant(char**);
double add(char**);
double sub(char**);
double divide(char**);
double multiply(char**);
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

if(argc != 2){
printf( "calculator <expression> \n ");
return -1;
}
bool a=compile(argv[1]);
if(a){
printf( "%s is compiled OK\n ",argv[1]);
printf( "result is: %f \n ",calculator(argv+1));
}
else printf( "fail to compile %s\n ",argv[1]);

return nRetCode;
}
//===================================
bool compile(char *string)
{
if(*string <0x30 || *string> 0x39) return false;
while(*string> =0x30 && *string <=0x39){
string++;
}
if(*string==0) return true;
if(*string != '+ ' && *string != '- '&& *string != '* '&& *string != '/ ') return false;

while(1){
string +=1;
if(*string <0x30 || *string> 0x39) return false;
while(*string> =0x30 && *string <=0x39){
string++;
}
if(*string==0) return true;
if(*string != '+ ' && *string != '- '&& *string != '* '&& *string != '/ ') return false;


}
}

double loadOperant(char ** ptExp)
{
char buffer[100];
int i=0;
while(**ptExp> =0x30 && **ptExp <=0x39){
buffer[i++]=**ptExp;
(*ptExp)++;
}
buffer[i]=0;
return atof(buffer);
}
double implement(double operant1,double operant2,char op)
{
switch(op){
case '+ ':return operant1+operant2;
case '- ':return operant1-operant2;
case '* ':return operant1*operant2;
case '/ ':if(fabs(operant2) <1e-7){
printf( "divided by zero!\n ");
exit(-1);
}
return operant1/operant2;
default:printf( "unknown operator\n ");
exit(-2);
}
}


//======================================
//Calculator
//======================================
double calculator(char** ptExp)
{
double operant1=loadOperant(ptExp);
double operant2;
char tmpOperator;
while(**ptExp){
tmpOperator=**ptExp;//update operator
*ptExp+=1;//jump over operator
switch(tmpOperator){
case '+ ':operant2=add(ptExp);
break;
case '- ':operant2=sub(ptExp);
break;
case '* ':
operant2=multiply(ptExp);
break;
case '/ ':
operant2=divide(ptExp);
break;
default:
printf( "not an operator! %d \n ",**ptExp);
exit(1);
}
operant1=implement(operant1,operant2,tmpOperator);
}
return operant1;
}
double add(char** ptExp)
{
double operant=loadOperant(ptExp);
char tmpOperator=**ptExp;
if(tmpOperator== '\0 ') return operant;
*ptExp +=1;