📄 xiatui.h
字号:
#include<iostream.h>
#include<string.h>
#include"Complexion.h"
class Xiatui{
private:
int numOfState;
char *state;
char *stateTable;
char *storChar;
Function **fun;
int numOfFun;
char startState;
char *endState;
public:
Xiatui(int n,char *s,char *sTable,char *sc,int &fN,char &sS,char *eS)
{
numOfState=n;
state=new char[n];
strcpy(state,s);
stateTable=new char[(int)strlen(sTable)];
strcpy(stateTable,sTable);
storChar=new char[(int)strlen(sc)];
strcpy(storChar,sc);
numOfFun=fN;
fun=(Function **)new Function*[numOfFun];
for(int i=0;i<numOfFun;i++)
{
fun[i]=new Function();
char *input=new char[50];
int rest;
cout<<"请输入第"<<i+1<<"个转移关系:\n";
cin>>input;
fun[i]->state=input[2];
fun[i]->charOfInput=input[4];
fun[i]->topOfStack=input[6];
fun[i]->newState=input[10];
rest=strlen(input)-14;
fun[i]->newTop=new char[rest];
for(int j=0;j<rest;j++)
fun[i]->newTop[j]=input[12+j];
fun[i]->newTop[j]='\0';
}
startState=sS;
endState=new char[(int)strlen(eS)];
strcpy(endState,eS);
}
bool judge(Complexion com)
{
if(com.isEnd())
return true;
if(com.isOver())
return false;
for(int i=0;i<numOfFun;i++)
{
if(move(fun[i],com))
{
if(judge(com))
return true;
}
}
return false;
}
bool move(Function *fun,Complexion &com)
{
if(fun->state!=com.state)
return false;
if(fun->topOfStack=='e')
{
if(fun->charOfInput=='e')
{
if(strcmp(fun->newTop,"e")==0)
{
com.state=fun->newState;
return true;
}
else
{
com.push(fun->newTop);
com.state=fun->newState;
return true;
}
}
else
{
if(fun->charOfInput==com.currChar())
{
if(strcmp(fun->newTop,"e")==0)
{
com.state=fun->newState;
com.curr++;
return true;
}
else
{
com.push(fun->newTop);
com.curr++;
com.state=fun->newState;
return true;
}
}
else
return false;
}
}
else
{
if(com.topCharOfStack()!=fun->topOfStack)
return false;
else
{
if(fun->charOfInput=='e')
{
if(strcmp(fun->newTop,"e")==0)
{
(com.storeStack)->pop();
com.state=fun->newState;
return true;
}
else
{
(com.storeStack)->pop();
com.push(fun->newTop);
com.state=fun->newState;
return true;
}
}
else
{
if(fun->charOfInput==com.currChar())
{
if(strcmp(fun->newTop,"e")==0)
{
com.state=fun->newState;
com.curr++;
(com.storeStack)->pop();
return true;
}
else
{
(com.storeStack)->pop();
com.push(fun->newTop);
com.curr++;
com.state=fun->newState;
return true;
}
}
else
return false;
}
}
}
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -