SyntaxParser/Compiler.cpp

91 lines
2.0 KiB
C++
Raw Normal View History

2021-04-30 12:55:56 +00:00
#include <iostream>
#include <ctime>
#include <Automata.h>
2021-04-30 12:55:56 +00:00
#include <SymbolTable.h>
#include <GrammarResourcePool.h>
#include <AnalyseTableGenerator.h>
#include <LR1Generator.h>
#include <SyntaxParser.h>
2021-04-30 12:55:56 +00:00
using std::vector;
using std::wstring;
using std::wcout;
using std::endl;
int main(int argc, const char* argv[]) {
2021-04-30 12:55:56 +00:00
2021-04-30 16:05:03 +00:00
try {
2021-05-12 16:27:10 +00:00
wcout << "Compile Program Based on LR(1) Written By Saturneric(<28><><EFBFBD><EFBFBD> 2018303206)" << endl;
wcout << "<EFBFBD><EFBFBD>ʦע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹؼ<EFBFBD><EFBFBD>ֵĴ<EFBFBD>Сд<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" << endl
<< "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><EFBFBD><EFBFBD>DZ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><EFBFBD><EFBFBD>ϻ<EFBFBD>û<EFBFBD>м<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֹؼ<EFBFBD><EFBFBD>ִ<EFBFBD>Сд<EFBFBD><EFBFBD>" << endl;
if (argc < 2) {
printf("Usage: <Input Path>\n");
return -1;
}
clock_t start, end;
start = clock();
Automata atm(argv[1]);
atm.parse();
atm.output();
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
end = clock();
double times = double(end - start) / CLOCKS_PER_SEC;
wcout << "Token Automata Run time = " << times << "s MicroSeconds" << " = " << times * 1000 << "ms" << endl;
// LR1<52><31><EFBFBD><EFBFBD>
start = clock();
2021-04-30 12:55:56 +00:00
2021-04-30 16:05:03 +00:00
const GrammarResourcePool *pool;
2021-04-30 12:55:56 +00:00
2021-04-30 16:05:03 +00:00
const AnalyseTableGenerator *atg;
2021-04-30 12:55:56 +00:00
2021-04-30 16:05:03 +00:00
LR1Generator generator;
2021-04-30 12:55:56 +00:00
2021-04-30 16:05:03 +00:00
generator.getProductions();
2021-04-30 12:55:56 +00:00
2021-04-30 16:05:03 +00:00
generator.run();
2021-04-30 12:55:56 +00:00
2021-04-30 16:05:03 +00:00
generator.output(pool, atg);
2021-04-30 12:55:56 +00:00
2021-04-30 16:05:03 +00:00
//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
end = clock(); //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
times = double(end - start) / CLOCKS_PER_SEC;
wcout << "LR(1) Generator Run time = " << times << "s MicroSeconds" << " = " << times * 1000 << "ms" << endl;
2021-04-30 12:55:56 +00:00
// <20><EFBFBD><EFB7A8><EFBFBD><EFBFBD>
2021-04-30 16:05:03 +00:00
start = clock(); //<2F><>ʼʱ<CABC><CAB1>
2021-04-30 12:55:56 +00:00
2021-04-30 16:05:03 +00:00
SyntaxParser syntaxParser(pool, atg);
2021-04-30 12:55:56 +00:00
2021-04-30 16:05:03 +00:00
syntaxParser.getToken();
2021-04-30 12:55:56 +00:00
2021-04-30 16:05:03 +00:00
syntaxParser.parse();
2021-04-30 12:55:56 +00:00
2021-04-30 16:05:03 +00:00
//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
end = clock(); //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
times = double(end - start) / CLOCKS_PER_SEC;
wcout << "Syntax Parser Run time = " << times << "s MicroSeconds " << " = " << times * 1000 << "ms" << endl;
2021-04-30 16:05:03 +00:00
} catch(std::runtime_error &e) {
std::wcout << "Runtime Error: " << e.what() << endl;
}
2021-04-30 12:55:56 +00:00
return 0;
}