main.c

来自「正则表达式转换为NFA再转换为DFA」· C语言 代码 · 共 50 行

C
50
字号
//main.c


#include "RND.h"

void main()
{
/* ________________初始化操作________________*/
    fpout=fopen(FileOutputPath,"w");
    if (!Readalphabet())
    {
        printf(" Error in opening files: alphabet.txt . Please check it. \n");
        exit(1);
    }
    if (!Readregexp())
    {
        printf(" Error in opening files: regexp.txt . Please check it.\n");
        exit(1);
    }
    if (!LexScan(Regexp))//判断正则表达式是否符合要求
    {
        printf(" The regular express is illegal, please check it! \n");
        exit(1);
    }
    else 
        printf(" Lexical scan passed, The regular express is legel.\n");
    fprintf(fpout," Lexical scan passed, The regular express is legel.\n");    
    AddConcatenation();//正则式加入连接符“+” 
    REtoPostfix();//转化为后缀表达式

/* ________________RegExp==>NFA________________*/
    /*构造NFA__采用Thompson's Algorithm*/
    Nfa=(NFA *)malloc(sizeof(NFA));
    Init_Nfa();
    ConstructNFA();//Thompson's Algorithm核心算法
    OutputNFA();//输出NFA图

/* ________________NFA==>DFA________________*/
    
    ConstructDFA();//将NFA生成对应的DFA__子集构造法
    OutputDFA();//输出DFA 



    printf(" _______________________________End_________________________________ \n ");
    fprintf(fpout," _______________________________End_________________________________\n  ");
    fclose(fpout);
    printf(" You can see all above in the Report.txt at the same path Please press Enter to exit!\n");
    getchar();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?