欢迎来到天天文库
浏览记录
ID:44138183
大小:32.00 KB
页数:9页
时间:2019-10-19
《不确定有限状态自动机的确定化(NFA TO DFA)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、不确定有限状态自动机的确定化(NFATODFA)2008-12-0522:11#include#include#defineMAXS100usingnamespacestd;stringNODE;//结点集合stringCHANGE;//终结符集合intN; //NFA边数structedge{stringfirst;stringchange;stringlast;};structchan{stringltab;stringjihe[MAXS];};voidkong(inta){inti;for(i=0;i2、}//排序voidpaixu(string&a){inti,j;charb;for(j=0;jNODE.find(a[i+1])) { b=a[i]; a[i]=a[i+1]; a[i+1]=b; }}voideclouse(charc,string&he,edgeb[]){intk;for(k=0;k3、he.find(b[k].last)>he.length()) he+=b[k].last; eclouse(b[k].last[0],he,b); }}}voidmove(chan&he,intm,edgeb[]){inti,j,k,l;k=he.ltab.length();l=he.jihe[m].length();for(i=0;i4、.last[0])>he.jihe[m].length()) he.jihe[m]+=b[j].last[0];for(i=0;ihe.jihe[m].length()) he.jihe[m]+=b[j].last[0];}//输出voidoutputfa(intlen,inth,chan*t){inti,j,m;5、cout<<"I ";for(i=0;i6、=newedge[MAXS];inti,j,k,m,n,h,x,y,len;boolflag;stringjh[MAXS],endnode,ednode,sta;cout<<"请输入NFA各边信息(起点条件[空为*]终点),以#结束:"<>b[i].first; if(b[i].first=="#")break; cin>>b[i].change>>b[i].last;}N=i;/*for(j=0;j7、for(i=0;iNODE.length()) NODE+=b[i].first; if(NODE.find(b[i].last)>NODE.length()) NODE+=b[i].last; if((CHANGE.find(b[i].change)>CHANGE.length())&&(b[i].change!="*")) CHANGE+=b[i].change;}len=CHA
2、}//排序voidpaixu(string&a){inti,j;charb;for(j=0;jNODE.find(a[i+1])) { b=a[i]; a[i]=a[i+1]; a[i+1]=b; }}voideclouse(charc,string&he,edgeb[]){intk;for(k=0;k3、he.find(b[k].last)>he.length()) he+=b[k].last; eclouse(b[k].last[0],he,b); }}}voidmove(chan&he,intm,edgeb[]){inti,j,k,l;k=he.ltab.length();l=he.jihe[m].length();for(i=0;i4、.last[0])>he.jihe[m].length()) he.jihe[m]+=b[j].last[0];for(i=0;ihe.jihe[m].length()) he.jihe[m]+=b[j].last[0];}//输出voidoutputfa(intlen,inth,chan*t){inti,j,m;5、cout<<"I ";for(i=0;i6、=newedge[MAXS];inti,j,k,m,n,h,x,y,len;boolflag;stringjh[MAXS],endnode,ednode,sta;cout<<"请输入NFA各边信息(起点条件[空为*]终点),以#结束:"<>b[i].first; if(b[i].first=="#")break; cin>>b[i].change>>b[i].last;}N=i;/*for(j=0;j7、for(i=0;iNODE.length()) NODE+=b[i].first; if(NODE.find(b[i].last)>NODE.length()) NODE+=b[i].last; if((CHANGE.find(b[i].change)>CHANGE.length())&&(b[i].change!="*")) CHANGE+=b[i].change;}len=CHA
3、he.find(b[k].last)>he.length()) he+=b[k].last; eclouse(b[k].last[0],he,b); }}}voidmove(chan&he,intm,edgeb[]){inti,j,k,l;k=he.ltab.length();l=he.jihe[m].length();for(i=0;i4、.last[0])>he.jihe[m].length()) he.jihe[m]+=b[j].last[0];for(i=0;ihe.jihe[m].length()) he.jihe[m]+=b[j].last[0];}//输出voidoutputfa(intlen,inth,chan*t){inti,j,m;5、cout<<"I ";for(i=0;i6、=newedge[MAXS];inti,j,k,m,n,h,x,y,len;boolflag;stringjh[MAXS],endnode,ednode,sta;cout<<"请输入NFA各边信息(起点条件[空为*]终点),以#结束:"<>b[i].first; if(b[i].first=="#")break; cin>>b[i].change>>b[i].last;}N=i;/*for(j=0;j7、for(i=0;iNODE.length()) NODE+=b[i].first; if(NODE.find(b[i].last)>NODE.length()) NODE+=b[i].last; if((CHANGE.find(b[i].change)>CHANGE.length())&&(b[i].change!="*")) CHANGE+=b[i].change;}len=CHA
4、.last[0])>he.jihe[m].length()) he.jihe[m]+=b[j].last[0];for(i=0;ihe.jihe[m].length()) he.jihe[m]+=b[j].last[0];}//输出voidoutputfa(intlen,inth,chan*t){inti,j,m;
5、cout<<"I ";for(i=0;i6、=newedge[MAXS];inti,j,k,m,n,h,x,y,len;boolflag;stringjh[MAXS],endnode,ednode,sta;cout<<"请输入NFA各边信息(起点条件[空为*]终点),以#结束:"<>b[i].first; if(b[i].first=="#")break; cin>>b[i].change>>b[i].last;}N=i;/*for(j=0;j7、for(i=0;iNODE.length()) NODE+=b[i].first; if(NODE.find(b[i].last)>NODE.length()) NODE+=b[i].last; if((CHANGE.find(b[i].change)>CHANGE.length())&&(b[i].change!="*")) CHANGE+=b[i].change;}len=CHA
6、=newedge[MAXS];inti,j,k,m,n,h,x,y,len;boolflag;stringjh[MAXS],endnode,ednode,sta;cout<<"请输入NFA各边信息(起点条件[空为*]终点),以#结束:"<>b[i].first; if(b[i].first=="#")break; cin>>b[i].change>>b[i].last;}N=i;/*for(j=0;j7、for(i=0;iNODE.length()) NODE+=b[i].first; if(NODE.find(b[i].last)>NODE.length()) NODE+=b[i].last; if((CHANGE.find(b[i].change)>CHANGE.length())&&(b[i].change!="*")) CHANGE+=b[i].change;}len=CHA
7、for(i=0;iNODE.length()) NODE+=b[i].first; if(NODE.find(b[i].last)>NODE.length()) NODE+=b[i].last; if((CHANGE.find(b[i].change)>CHANGE.length())&&(b[i].change!="*")) CHANGE+=b[i].change;}len=CHA
此文档下载收益归作者所有