73 lines
1.5 KiB
C++
73 lines
1.5 KiB
C++
#include <iostream>
|
|
#include <fstream>
|
|
#include <cassert>
|
|
|
|
#include "grammar.h"
|
|
#include "LL1.h"
|
|
using namespace std;
|
|
|
|
string inputs[] = {
|
|
"tests/00.txt",
|
|
"tests/20.txt"
|
|
};
|
|
|
|
string outputs_lexical[] = {
|
|
"tests/00_my_lexical.txt",
|
|
"tests/20_my_lexical.txt"
|
|
};
|
|
|
|
string outputs_grammar[] = {
|
|
"tests/00_my_grammar.txt",
|
|
"tests/20_my_grammar.txt",
|
|
};
|
|
|
|
// 读取文件
|
|
string readfile(const string& filename)
|
|
{
|
|
ifstream file(filename);
|
|
string content((istreambuf_iterator<char>(file)),istreambuf_iterator<char>());
|
|
return content;
|
|
}
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
try{
|
|
int i=0;
|
|
for (auto input : inputs) {
|
|
LL1 ll;
|
|
//ll.print_grammar_set();
|
|
|
|
string content = readfile(input);
|
|
vector<string> token_strings = recognize(minimizedDFA, content,outputs_lexical[i]);
|
|
|
|
bool flag = ll.IsLL1();
|
|
ll.build_LL1_predict();
|
|
|
|
|
|
//ll.print_LL1_predict();
|
|
ll.get_token_strings(token_strings);
|
|
|
|
|
|
ll.print_token_strings();
|
|
ll.build_LL1_grammar();
|
|
|
|
|
|
ll.fileout_LL1_grammar_log(outputs_grammar[i]);
|
|
|
|
|
|
//ll.print_LL1_grammar_log();
|
|
cout << endl;
|
|
cout<<outputs_grammar[i]<<endl;
|
|
cout<<"end"<<endl;
|
|
i++;
|
|
}
|
|
cout<<"LL1 FINISH"<<endl;
|
|
}
|
|
catch(...){
|
|
cout<<"ERROR"<<endl;
|
|
}
|
|
|
|
cout<<"SYSTEM END"<<endl;
|
|
|
|
return 0;
|
|
} |