查询语句QL的语义分析和实现 第9页
布尔表达式求值计算的部分程序:
typedef struct{
int *base;
int *top;
int stacksize;
}s_stack;//定义一个操作数栈
typedef struct{
char *base;
char *top;
int stacksize;
}f_stack;//定义一个运算符栈
static char youxian[6][6]=
{
{'>','>','<','<','>','>'},{'>','>','<','<','>','>'},
{'>','>','>','<','>','>'},{'<','<','<','<','=','>'},
{'>','>','>','>','>','>'},{'<','<','<','<','<','='}
};//算符间的优先关系
int in(char c)
{
switch(c)
{
case '&&': return 0;
case '||': return 1;
case '!': return 2;
case '(': return 3;
case ')': return 4;
case '#':return 5;
default:return 9;
}
}
void s_push(s_stack *s,int e)
{
if(s->top-s->base>=s->stacksize)
{ //栈满增加存储空间
s->base=(int *)realloc(s->base,(s->stacksize+stackincrement1)*sizeof(int));
if(!s->base) exit(0);//存储分配失败
s->top=s->base+s->stacksize;
s->stacksize+=stackincrement1;
}
*s->top=e; s->top++;
}
void f_push(f_stack *f,char e)
{
if(f->top-f->base>=f->stacksize)
{
f->base=(char *)realloc(f->base,(f->stacksize+stackincrement2)*sizeof(char));
if(!f->base) exit (0);
f->top=f->base+f->stacksize;
f->stacksize+=stackincrement2;
}
*f->top=e;f->top++;
}
int s_gettop(s_stack *s)
{ //取栈顶元素
s->top--;
return *s->top;
}
char f_gettop(f_stack *f)
{
f->top--;
return *f->top;
}
char pduan(f_stack *f,char c)//判断优先
{
int m,n;
char w;
m=in(c);
w=*(f->top-1);
www.751com.cnp,char* r,char q)
{
switch(r)
{
case '&&': return q&&p;
case '||': return q||p;
case '!': return !q,!p;
}
} int yunsuan(char p,char r,)
{
switch(r)
{
case '!': return !p;
}
}上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9]
查询语句QL的语义分析和实现 第9页下载如图片无法显示或论文不完整,请联系qq752018766