通过递归的方法实现简单表达式的运算,支持加减乘除以及多层括号运算。
//eval.h
//
//eval.h
#if !defined(__EVAL__H__)
#define __EVAL__H__
// evaluate the value of the str.
// It support +-*/ with non-nagetive integers only.
// @param str The string to be evaluated. This string is to be modified.
// @return the value evaluated.
int eval(char* str);
#endif
//eval.c
//
//eval.c
#include "eval.h"
#include <string.h>
#include <stdio.h>
#define CH2DEC(x) ((x) - '0')
// find the most right and lowest operator in the str
// @return -1 if no any operators in the str; or
// the index of the operator sepeicified in the str
static int findop(const char *str);
// return the rank of the operator
// @return -1 if the char ch is not an operator; or
// the rank listed as 1 for * and /, 2 for + and -
static int oprank(char ch);
// convert a string into a number.
// The string s