SyntaxParser/LR1Generator.cpp

62 lines
1.3 KiB
C++
Raw Normal View History

2021-04-30 12:55:56 +00:00
#include <iostream>
#include <ctime>
#include <SymbolTable.h>
#include <GrammarResourcePool.h>
#include <AnalyseTableGenerator.h>
using std::vector;
using std::wstring;
using std::wcout;
using std::endl;
#include <LR1Generator.h>
#include <SyntaxParser.h>
int main() {
2021-04-30 16:05:03 +00:00
try {
clock_t start, end;//<2F><><EFBFBD><EFBFBD>clock_t<5F><74><EFBFBD><EFBFBD>
start = clock(); //<2F><>ʼʱ<CABC><CAB1>
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>
double times = double(end - start) / CLOCKS_PER_SEC;
wcout << "LR1Generator Run time = " << times << "s MicroSeconds" << " = " << times * 1000 << "ms" << endl;
2021-04-30 12:55:56 +00:00
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 << "SyntaxParser Run time = " << times << "s MicroSeconds " << " = " << times * 1000 << "ms" << endl;
} catch(std::runtime_error &e) {
std::wcout << "Runtime Error: " << e.what() << endl;
}
2021-04-30 12:55:56 +00:00
return 0;
}