2021-04-30 12:55:56 +00:00
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <ctime>
|
|
|
|
|
|
2021-04-30 17:30:50 +00:00
|
|
|
|
#include <Automata.h>
|
|
|
|
|
|
2021-04-30 12:55:56 +00:00
|
|
|
|
#include <SymbolTable.h>
|
|
|
|
|
#include <GrammarResourcePool.h>
|
|
|
|
|
#include <AnalyseTableGenerator.h>
|
|
|
|
|
|
2021-04-30 17:30:50 +00:00
|
|
|
|
#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;
|
|
|
|
|
|
|
|
|
|
|
2021-04-30 17:30:50 +00:00
|
|
|
|
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-04-30 17:30:50 +00:00
|
|
|
|
|
|
|
|
|
printf("Compile Program Based on LR(1) Written By Saturneric\n");
|
|
|
|
|
|
|
|
|
|
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>
|
2021-04-30 17:30:50 +00:00
|
|
|
|
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
|
|
|
|
|
2021-04-30 17:30:50 +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;
|
2021-04-30 17:30:50 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|