📄 main.cpp
字号:
//#pragma warning(disable:4786)
#include <iostream>
#include <fstream>
#include <windows.h>
#include<conio.h>
using namespace std;
#include "REManage.h"
void waitForInput()
{
cout<<endl;
cout<<"输入完毕后,请按任意键开始处理...";
cout<<endl<<endl;
getch();
HWND note=FindWindow("notepad",NULL);
::SendMessage(note,WM_CLOSE,0,0);//按任意键后关闭txt窗口
}
void ReadRE(string& re)
{
ifstream in("RE.txt");
in>>re;
}
void ReadTestString(vector<string>& str)
{
ifstream in("TestString.txt");
string temp;
for(;getline(in,temp),temp.size()>0;)
{
str.push_back(temp);
}
}
void ReadNFA(vector<EDGE>& edgeGather,vector<int>& start, vector<int>& end)
{
ifstream inNFA("NFA.txt");
EDGE edge;
int edgeNum,startNum,endNum,temp;
edgeGather.clear();
start.clear();
end.clear();
inNFA>>edgeNum;
for(int i=0;i<edgeNum;i++)
{
inNFA>>edge.start>>edge.input>>edge.end;
edgeGather.push_back(edge);
}
inNFA>>startNum;
for(i=0;i<startNum;i++)
{
inNFA>>temp;
start.push_back(temp);
}
inNFA>>endNum;
for(i=0;i<endNum;i++)
{
inNFA>>temp;
end.push_back(temp);
}
}
void ReadDFA(vector<EDGE>& edgeGather,int start, vector<int>& end)
{
ifstream inDFA("DFA.txt");
EDGE edge;
int edgeNum,startNum,endNum,temp;
edgeGather.clear();
end.clear();
inDFA>>edgeNum;
for(int i=0;i<edgeNum;i++)
{
inDFA>>edge.start>>edge.input>>edge.end;
edgeGather.push_back(edge);
}
inDFA>>startNum;
inDFA>>start;
inDFA>>endNum;
for(i=0;i<endNum;i++)
{
inDFA>>temp;
end.push_back(temp);
}
}
void OutTestResult(vector<string> str,vector<bool> isPass)
{
ofstream out("TestResult.txt");
for(int i=0;i<str.size();i++)
{
out<<str[i]<<" ";
if(isPass[i])
out<<"PASS"<<endl;
else
out<<"FAILE"<<endl;
}
}
void main()
{
REManage test;
/* ShellExecute(NULL,"open","USE.txt",NULL,NULL,SW_SHOWNORMAL);//打开txt文档
cout<<"说明:详见USE.txt"<<endl;
cout<<"请阅读后按任意键开始...";
getch();
HWND note=FindWindow("notepad",NULL);
::SendMessage(note,WM_CLOSE,0,0);
cout<<endl<<endl;*/
string re; //regular expression
vector<string> stringGather; //test string gather
vector<EDGE> edgeGather; //edge gather for both NFA and DFA
int startDFA=0; //start state for DFA
vector<int> startNFA; //start state gather for NFA
vector<int> end; //end state gather for both NFA and DFA
vector<bool> isPass; //vector是一个能够存放任意类型的动态数组,能够增加和压缩数据
for(;;)
{
stringGather.clear();
edgeGather.clear();
startNFA.clear();
end.clear();
isPass.clear();
int choice=0;
cout<<"选择你的输入:"<<endl;
cout<<" 1. 输入正规式"<<endl;
cout<<" 2. 输入NFA"<<endl;
cout<<" 3. 输入DFA"<<endl;
cout<<" 4. 退出"<<endl;
cout<<"输入你的选择(1~4):";
cin>>choice;
switch(choice)
{
case 1:
ShellExecute(NULL,"open","RE.txt",NULL,NULL,SW_SHOWNORMAL);
waitForInput();
ReadRE(re);
test.setRE(re);
test.Process();
break;
case 2:
ShellExecute(NULL,"open","NFA.txt",NULL,NULL,SW_SHOWNORMAL);
waitForInput();
ReadNFA(edgeGather,startNFA,end);
test.setNFA(edgeGather,startNFA,end);
test.Process();
break;
case 3:
ShellExecute(NULL,"open","DFA.txt",NULL,NULL,SW_SHOWNORMAL);
waitForInput();
ReadDFA(edgeGather,startDFA,end);
test.setDFA(edgeGather,startDFA,end);
test.Process();
break;
case 4:
exit(0);
default:
cout<<"输入错误!"<<endl;
exit(1);
}
for(;;)
{
isPass.clear();
stringGather.clear();
cout<<"结果已经生成,请选择:"<<endl;
cout<<" 1. 测试生成串"<<endl;
cout<<" 2. 完成"<<endl;
cout<<"请输入你的选择:";
cin>>choice;
if(choice==1)
{
ShellExecute(NULL,"open","TestString.txt",NULL,NULL,SW_SHOWNORMAL);
waitForInput();
ReadTestString(stringGather);
for(int i=0;i<stringGather.size();i++)
{
isPass.push_back(test.TestString(stringGather[i]));
}
OutTestResult(stringGather,isPass);
ShellExecute(NULL,"open","TestResult.txt",NULL,NULL,SW_SHOWNORMAL);
}
else
{
HWND note=FindWindow("notepad",NULL);
::SendMessage(note,WM_CLOSE,0,0);
break;
}
}
HWND note=FindWindow("notepad",NULL);
::SendMessage(note,WM_CLOSE,0,0);
cout<<endl<<endl;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -