za.cpp
来自「编译原理课程实验要求做的语法分析」· C++ 代码 · 共 83 行
CPP
83 行
#include"bianyi.h"
void InitStack(SqStack &Sqstack)
{
Sqstack.base=(SElemType *)malloc(100*sizeof(SElemType));
if(!Sqstack.base)
{
cout<<"error";
exit(1);
}
Sqstack.top=Sqstack.base;
Sqstack.stacksize=100;
}
int Rpop(int &Ltrace,int &Lptr,SqStack &Sqstack)
{
SElemType e;
if(Sqstack.top==Sqstack.base)
return 0;
else
{
e=*--Sqstack.top;
Lptr=e.Lptr;
Ltrace=e.Ltrace;
return 1;
}
}
void Rpush(int Ltrace,int Lptr,SqStack &Sqstack)
{
SElemType e;
if(Sqstack.top - Sqstack.base>=Sqstack.stacksize)
{
Sqstack.base=(SElemType *)realloc(Sqstack.base,(Sqstack.stacksize+=10)*sizeof(SElemType));
if(!Sqstack.base)
{
cout<<"error";
exit(1);
}
Sqstack.top=Sqstack.base+Sqstack.stacksize;
Sqstack.stacksize+=10;
}
e.Lptr=Lptr;
e.Ltrace=Ltrace;
*Sqstack.top++=e;
}
int Rempty(SqStack Sqstack)
{
if(Sqstack.top==Sqstack.base)
return 1;
return 0;
}
void Destroystack(SqStack &Sqstack)
{
while(Sqstack.base)
{
Sqstack.top=Sqstack.base+Sqstack.stacksize-1;
free(Sqstack.top);
Sqstack.stacksize--;
}
}
void Rtrail(SqStack &Sqstack,int Fiptr,bool Follow[][36])
{
SElemType *Mid;
Mid=(Sqstack.base);
while(Mid!=Sqstack.top)
{
Follow[Mid->Ltrace-128][Fiptr]=1;
Mid++;
}
}
void Epop(SqStack &Sqstack)
{
Sqstack.top=Sqstack.base;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?