NFA(子集算法,DFA最小化)代码实现

#include 
#include 
#include 
#include 
using namespace std;
const int maxn=1001;

/*
NFA五元组
M={K,A,f,S,Z};
K::状态集合
A::字母表
F::转换函数
S::开始状态
Z::结束状态
*/

/*状态集合K中的结点*/
string node;

/*字母表A中的符号*/
string cas;

//NFA边数
int N;

/*转换函数f*/
struct f
{
    string u,w,v;
    //起点,条件,终点
};

struct change
{
    string ta;
    string arr[maxn];
};

void none(int a)
{
    int i;
    for(i=0; inode.find(a[i+1]))
            {
                b=a[i];
                a[i]=a[i+1];
                a[i+1]=b;
            }
}

void eclouse(char c,string &he,f b[])
{
    int k;
    for(k=0; khe.length())
                    he+=b[k].v;
                eclouse(b[k].v[0],he,b);
            }
    }
}

void movex(change &he,int m,f b[])
{
    int i,j,k,l;

    k=he.ta.length();
    l=he.arr[m].length();

    for(i=0; ihe.arr[m].length())
                    he.arr[m]+=b[j].v[0];

    for(i=0; ihe.arr[m].length())
                    he.arr[m]+=b[j].v[0];
}

void output(int len,int h,change *t)
{
    int i,j,m;
    cout<<"  I   ";
    for(i=0; i>N;

    /*转换函数*/
    cout<<"input the "<>b[i].u;
        cin>>b[i].w>>b[i].v;
    }

    /*统计字母表A的大小*/
    for(i=0; inode.length())
            node+=b[i].u;
        if(node.find(b[i].v)>node.length())
            node+=b[i].v;
        if((cas.find(b[i].w)>cas.length())&&(b[i].w!="*"))
            cas+=b[i].w;
    }
    len=cas.length();

    /*输入结束状态Z*/
    cout<<"input the end state of the NFA:\n";
    bool fl=true;
    while(fl)
    {
        cin>>z;
        fl=false;
        for(i=0; inode.length())
            {
                cout<<"Sorry!!the Z state not in the K states\n";
                fl=true;
                break;
            }
        }
    }


//子集算法
    change *t=new change[maxn];
    t[0].ta=b[0].u;
    h=1;
    eclouse(b[0].u[0],t[0].ta,b);
    for(i=0; i

你可能感兴趣的:(编译原理)