-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
41 lines (36 loc) · 1.11 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "Lex/Lexer.hpp"
#include "Parse/Parser.hpp"
#include "AST/Dumper.hpp"
#include "boost/program_options.hpp"
#include <iostream>
using namespace tinyc;
namespace bpo = boost::program_options;
void parseCommandLineOption(const bpo::variables_map &vm, const bpo::options_description &description) {
std::string filename;
if(vm.count("help")) {
std::cout << description << std::endl;
return;
}
if(vm.count("file")) {
filename = vm["file"].as<std::string>();
tinyc::Parser parser(filename);
auto ast = parser.parse();
if(vm.count("ast-dump")) {
Dumper dumper(ast);
dumper.dump();
}
} else {
std::cerr << "Expected filename. Usage: --file <filename>" << std::endl;
return;
}
}
int main(int argc, const char* argv[]){
bpo::options_description description("");
bpo::variables_map vm;
description.add_options()
("help, h", "Help Screen")
("file, f", bpo::value<std::string>(), "filename")
("ast-dump", "Print nested AST");
bpo::store(bpo::parse_command_line(argc, argv, description), vm);
parseCommandLineOption(vm, description);
}