📄 slrdfa.h
字号:
#include "DATA.h"
void SLRDFA()
{
int top_state(0),top_sign(0),i=0;
memset(State_S,0,sizeof(State_S));
memset(Sign_S,0,sizeof(Sign_S));
cout<<endl<<endl<<"请输入符号串:"<<endl;
while(cin>>a){
top_state=0;
top_sign=0;
i=0;
a[strlen(a)]='#';
State_S[top_state++]=0;
Sign_S[top_sign++]='#';
cout<<endl<<"SLR分析器工作过程如下:"<<endl;
cout<<"State Sign A"<<endl;
while(1)
{
if(ACTION[State_S[top_state-1]][a[i]]>0 && ACTION[State_S[top_state-1]][a[i]]!=ERROR)
{
State_S[top_state]=ACTION[State_S[top_state-1]][a[i]];
top_state++;
Sign_S[top_sign++]=a[i];
i++;
}
else if(ACTION[State_S[top_state-1]][a[i]]<0)
{
int t=-ACTION[State_S[top_state-1]][a[i]];
t--;
top_state-=g[t].l;
top_sign-=g[t].l;
State_S[top_state]=GOTO[State_S[top_state-1]][g[t].left];
top_state++;
Sign_S[top_sign]=g[t].left;
top_sign++;
}
else if(ACTION[State_S[top_state-1]][a[i]]==0)
{
cout<<"ACCEPTED"<<endl;
break;
}
else {cout<<"ERROR!"<<endl;break;}
for(int j=0;j<top_state;j++) cout<<State_S[j];
for(int j=0;j<15-top_state;j++) cout<<' ';
for(int j=0;j<top_sign;j++) cout<<Sign_S[j];
for(int j=0;j<14-top_sign;j++) cout<<' ';
for(int j=i;j<strlen(a);j++) cout<<a[j];
cout<<endl;
}
cout<<endl<<endl<<"请输入符号串:"<<endl;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -