打???的地方看得不是很懂,求高人指点一下哈

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MAX_SIZE 256
enum BOOL{FALSE,TRUE};
typedef struct tagOPERATE{

double Operand;
char Operator;
}OPERATE,*LPOPERATE;
int IsDigit(char);
int isp(char ch); 
int icp(char ch);
int Locate(char ch);
void PostSrc(char*src,LPOPERATE lpOperator);
int getOperand(char *s,int *len,double *oprd);
double Calculate(LPOPERATE lpOperator);

static char Operator[]="#(+-*/^"; //?????
static int InPriority[]={0,1,3,3,5,5,7}; //????
static int OutPriority[]={0,10,2,2,4,4,6}; //?????

int Locate(char ch)  
{
int i=0;
for(i=0;Operator[i]!='\0';i++)
if(Operator[i]==ch)
return i;
return -1;

}

int isp(char ch)  
{
if('A'<=ch&&'Z'>=ch)
return 9;
else
return InPriority[Locate(ch)];
}

int icp(char ch)  
{
if('A'<=ch&&'Z'>=ch)
return 8;
else
return OutPriority[Locate(ch)];
}

void PostSrc(char*src,LPOPERATE lpOperator)
{
char *p=src,y;
LPOPERATE lpOptr=lpOperator;
char stack[MAX_SIZE];
int top=-1; 
double Operand;
int offset=0;
stack[++top]='#';
while('\0'!=*p)
{
if(IsDigit(*p))
{
getOperand(p,&offset,&Operand);
p+=offset;
lpOptr->Operand=Operand;
lpOptr->Operator=0;
lpOptr++;
}
else

if(')'==*p)
{
for(y=stack[top--];y!='(';y=stack[top--])
(lpOptr++)->Operator=y;
p++;
}
else
{
for(y=stack[top--];isp(y)>icp(*p);y=stack[top--]) //?????
(lpOptr++)->Operator=y;
stack[++top]=y;
stack[++top]=*p++;
}

}
while(top!=-1)
(lpOptr++)->Operator=stack[top--];  

}
int IsDigit(char ch)
{
if(('0'<=ch&&'9'>=ch)||'.'==ch)
return TRUE;
return FALSE;
}
int getOperand(char *s,int *len,double *oprd){

char *p = s,ch = *s++;
double z = 0,x = 0;
int bits = 0;
int point = FALSE;
while( IsDigit(ch) == TRUE){
if (ch == '.'){
if (point == TRUE) 
return FALSE;
point = TRUE;
}
else {
if (point == TRUE){
x *= 10;
x += ch - '0';
bits++;
}
else {
z *= 10;
z += ch - '0';
}
}
ch = *s++;
}
while(bits-- > 0) x /= 10;
z += x;
*oprd = z;
*len = s - p - 1;
return TRUE;
}

牧羊人nacy
浏览 138回答 2
2回答

摇曳的蔷薇

这个应该是头文件,但是公共函数应该加上inline优化一下。enum 枚举变量 BOOL结构,包含一个double类型和char类型int IsDigit(char); //判断是否是数字(0-9)int isp(char ch); //判断是否是字符(A-Z) 返回相应的InPriority数组中值int icp(char ch); //判断是否是字符(A-Z) 返回相应的OutPriority数组中值int Locate(char ch);//判断是否运算符(+,-,*,/,^)&nbsp;猜想一下,这个估计是用来做词法分析的,分析字符串的运算表达式。做编译器?

胡说叔叔

static char Operator[]="#(+-*/^"; //?????运算/操作符。Operator[0]="#" 是 栈操作,push,pop. Operator[1]="(" 是 括号,进入一层。Operator[2]="+",Operator[3]="-",Operator[4]="*",Operator[5]="/",是 加减乘除,Operator[6]="^" 是幂 运算.static int InPriority[]={0,1,3,3,5,5,7}; //????进入/输入时的优先级static int OutPriority[]={0,10,2,2,4,4,6}; //?????退出/输出时的优先级for(y=stack[top--];isp(y)>icp(*p);y=stack[top--]) //?????从栈顶起,往下查一个一个字符,按优先级isp(y)>icp(*p)判断循环终了。
打开App,查看更多内容
随时随地看视频慕课网APP