|
|
@ -57,11 +57,6 @@ public:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ptr;
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NFANode* next()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
auto itr=nextMap.begin();
|
|
|
|
|
|
|
|
return *(itr->second.begin());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
map<char,set<NFANode*>> getNextMap()
|
|
|
|
map<char,set<NFANode*>> getNextMap()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return nextMap;
|
|
|
|
return nextMap;
|
|
|
@ -107,10 +102,19 @@ public:
|
|
|
|
for(int i=0;i<regex.length();i++)
|
|
|
|
for(int i=0;i<regex.length();i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
char c=regex[i];
|
|
|
|
char c=regex[i];
|
|
|
|
if(c=='('||c=='+'||c=='|')
|
|
|
|
if(c=='(')
|
|
|
|
{
|
|
|
|
{
|
|
|
|
operatorStack.push(c);
|
|
|
|
operatorStack.push(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(c=='+'||c=='|')
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
while(!operatorStack.empty()&&operatorStack.top()=='~')
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
operatorStack.pop();
|
|
|
|
|
|
|
|
calculate('~');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
operatorStack.push(c);
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(c=='*')
|
|
|
|
else if(c=='*')
|
|
|
|
{
|
|
|
|
{
|
|
|
|
NFANode* node=nfaMapStack.top();
|
|
|
|
NFANode* node=nfaMapStack.top();
|
|
|
@ -185,7 +189,7 @@ public:
|
|
|
|
list<NFANode*> outputList;
|
|
|
|
list<NFANode*> outputList;
|
|
|
|
outputList.push_back(nfaMapStack.top());
|
|
|
|
outputList.push_back(nfaMapStack.top());
|
|
|
|
outedStateSet.insert(nfaMapStack.top()->getState());
|
|
|
|
outedStateSet.insert(nfaMapStack.top()->getState());
|
|
|
|
while(!outputList.empty())
|
|
|
|
while(!outputList.empty()&&outputList.front()!=nullptr)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
NFANode* nfaNode=outputList.front();
|
|
|
|
NFANode* nfaNode=outputList.front();
|
|
|
|
outputList.pop_front();
|
|
|
|
outputList.pop_front();
|
|
|
@ -452,13 +456,14 @@ public:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void match(const string& temp)
|
|
|
|
void match(string& temp)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int currentState=0;
|
|
|
|
int currentState=0;
|
|
|
|
for(char c:temp)
|
|
|
|
for(char & c : temp)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(c==';')
|
|
|
|
if(c==';')
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
c = '\0';
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(c==' ')
|
|
|
|
if(c==' ')
|
|
|
@ -469,11 +474,11 @@ public:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(endStates.count(currentState))
|
|
|
|
if(endStates.count(currentState))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cout<<temp<<"--yes"<<endl;
|
|
|
|
cout<<setw(15)<<temp<<"--yes"<<endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cout<<temp<<"--no"<<endl;
|
|
|
|
cout<<setw(15)<<temp<<"--no"<<endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -496,7 +501,6 @@ int main()
|
|
|
|
dfa.outputEndStates();
|
|
|
|
dfa.outputEndStates();
|
|
|
|
cout<<"supported char:"<<endl;
|
|
|
|
cout<<"supported char:"<<endl;
|
|
|
|
dfa.outputCharSet();
|
|
|
|
dfa.outputCharSet();
|
|
|
|
|
|
|
|
|
|
|
|
while(true)
|
|
|
|
while(true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cout<<"please input string to test(input 'exit' to quit):";
|
|
|
|
cout<<"please input string to test(input 'exit' to quit):";
|
|
|
|