blog-static/code/compiler/13/main.cpp

28 lines
773 B
C++
Raw Permalink Normal View History

2020-09-08 18:38:05 -07:00
#include "ast.hpp"
#include <iostream>
#include "parser.hpp"
#include "compiler.hpp"
2020-09-08 18:38:05 -07:00
#include "error.hpp"
2020-09-09 12:21:50 -07:00
void yy::parser::error(const yy::location& loc, const std::string& msg) {
2020-09-11 21:29:49 -07:00
std::cerr << "An error occured: " << msg << std::endl;
2020-09-08 18:38:05 -07:00
}
int main(int argc, char** argv) {
if(argc != 2) {
std::cerr << "please enter a file to compile." << std::endl;
2020-09-11 21:29:49 -07:00
exit(1);
}
compiler cmp(argv[1]);
2020-09-08 18:38:05 -07:00
try {
cmp("program.o");
2020-09-08 18:38:05 -07:00
} catch(unification_error& err) {
err.pretty_print(std::cerr, cmp.get_file_manager(), cmp.get_type_manager());
2020-09-08 18:38:05 -07:00
} catch(type_error& err) {
err.pretty_print(std::cerr, cmp.get_file_manager());
2020-09-11 21:29:49 -07:00
} catch (compiler_error& err) {
err.pretty_print(std::cerr, cmp.get_file_manager());
2020-09-08 18:38:05 -07:00
}
}