Updated main file
This commit is contained in:
parent
32b7fae8af
commit
3a5006ae2a
59
src/main.cpp
59
src/main.cpp
|
@ -1,70 +1,53 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include "optparse.h"
|
||||
#include "Parsodus/inputparser.h"
|
||||
#include "Parsodus/backendmanager.h"
|
||||
#include "Parsodus/lrtables/generator.h"
|
||||
#include "Parsodus/lrtables/SLR1Itemset.h"
|
||||
#include "Parsodus/backends/cppLR.h"
|
||||
#include "Parsodus/util/parserType.h"
|
||||
#include "Parsodus/driver.h"
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
optparse::OptionParser parser = optparse::OptionParser().description("Parsodus").usage("Parsodus [-d <outputdir>] [-l <language>] [-n <lexername>] <inputfile.pds>");
|
||||
/* Set and parse command line arguments */
|
||||
optparse::OptionParser parser = optparse::OptionParser().description("Parsodus").usage("Parsodus [-d <outputdir>] [-l <language>] [-n <parsername>] <inputfile.pds>");
|
||||
parser.add_help_option(true);
|
||||
parser.version("%prog 1.0");
|
||||
parser.add_option("-d", "--outputdir").dest("outputdir").help("Output the generated files to this directory\n[default: .]").metavar("<directory>").set_default(".");
|
||||
parser.add_option("-l", "--lang", "--language").dest("language").help("The programming language to generate source files for\n[default: c++]").metavar("<language>").set_default("c++");
|
||||
parser.add_option("-n", "--name").dest("lexername").help("Use this name for the generated parser, the default is based on the input file name").metavar("<lexername>");
|
||||
parser.add_option("-n", "--name").dest("parsername").help("Use this name for the generated parser, the default is based on the input file name").metavar("<parsername>");
|
||||
optparse::Values options = parser.parse_args(argc, argv);
|
||||
std::vector<std::string> args = parser.args();
|
||||
|
||||
/* Check whether a parsodus config file is given */
|
||||
if (args.size() != 1) {
|
||||
parser.print_usage(std::cerr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Open parsodus config file, if possible */
|
||||
std::ifstream infile(args[0]);
|
||||
if (!infile.good()) {
|
||||
std::cerr << "Could not open file '" << args[0] << "' for reading" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string parsername = options["parsername"];
|
||||
|
||||
/* Set name of parser, if unset */
|
||||
if (parsername.empty() && args[0].size() >= 4 && args[0].substr(args[0].size() - 4,4) == ".pds")
|
||||
parsername = args[0].substr(0, args[0].length() - 4);
|
||||
|
||||
auto backendManager = std::make_unique<pds::BackendManager>(pds::BackendManager());
|
||||
/* Register languages */
|
||||
backendManager->registerLR<pds::backends::CppLRBackend>();
|
||||
pds::Driver driver(std::move(backendManager), infile, options["outputdir"], options["language"], "testParser");
|
||||
|
||||
return driver.run();
|
||||
|
||||
// Reporting what the inputparser found, to be removed...
|
||||
// std::cout << "Start: " << config.grammar.start << std::endl;
|
||||
// for(auto a: config.grammar.terminals)
|
||||
// std::cout << "Terminal: " << a << std::endl;
|
||||
// for(auto a: config.grammar.variables)
|
||||
// std::cout << "Variable: " << a << std::endl;
|
||||
// std::cout << "Rules: " << std::endl;
|
||||
// for(auto a: config.grammar.rules) {
|
||||
// std::cout << "\t" << a->head << " -> ";
|
||||
// for(auto c: a->tail) {
|
||||
// std::cout << c << " ";
|
||||
// }
|
||||
// std::cout << std::endl;
|
||||
// }
|
||||
//
|
||||
// std::vector<std::string> names = {"ERROR", "SHIFT", "REDUCE", "ACCEPT"};
|
||||
// pds::lr::Generator<pds::lr::SLR1Itemset> g(config.grammar);
|
||||
// auto tbl = g.generate();
|
||||
// for (std::size_t i = 0; i < tbl.act.size(); i++) {
|
||||
// std::cout << "State " << i << std::endl;
|
||||
// std::cout << " Action:" << std::endl;
|
||||
// for (auto& p : tbl.act[i]) {
|
||||
// std::cout << " " << p.first << ": " << names[static_cast<int>(p.second.first)] << " " << p.second.second << std::endl;
|
||||
// }
|
||||
// std::cout << " Goto:" << std::endl;
|
||||
// for (auto& p : tbl.goto_[i]) {
|
||||
// std::cout << " " << p.first << ": " << p.second << std::endl;;
|
||||
// }
|
||||
// }
|
||||
/* Create parserfile, if possible */
|
||||
try {
|
||||
pds::Driver driver(std::move(backendManager), infile, options["outputdir"], options["language"], parsername);
|
||||
return driver.run();
|
||||
} catch (std::exception &err) {
|
||||
std::cout << err.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue