C++ NFA构建:后缀表达式转NFA代码解析

本篇文章将解析一段C++代码,该代码实现了将正则表达式的后缀表达式转换为NFA(非确定性有限自动机)。c++void nfaManager::postfix_to_nfa(string postfix){ for(unsigned int i=0; i<postfix.size(); i++) {

    if((postfix[i]>=48 && postfix[i]<=57)||(postfix[i]>=65 && postfix[i]<=90)                ||(postfix[i]>=97 && postfix[i]<=122))        {            character(postfix[i]);            NumOfChar++;            chars.push_back(postfix[i]);        }        else            switch(postfix[i])            {            case '*': kleene_star(); break;            case '.': concatenation(); break;            case '|': union_();        }    }

int w = st.top(); nfa.NodeTable[w].final=1;//标识最后一个结点

int m=st.top(); st.pop(); int n=st.top(); st.pop(); st.push(n); st.push(m); start_state = n;//记录起始结点的位置


原文地址: http://www.cveoy.top/t/topic/bnek 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录