lang_2023/src/main.cpp

46 lines
1.2 KiB
C++
Raw Normal View History

2023-03-31 12:10:12 +03:00
#include <fstream>
#include <iostream>
#include <sstream>
// for clangd
#include "../include/parse_tree.hpp"
#include "../include/interpreter_tree.hpp"
#include "../include/build_visitor.hpp"
#include "../include/print_visitor.hpp"
2023-05-05 11:59:02 +03:00
#include "../include/error_handling.hpp"
2023-03-31 12:10:12 +03:00
int main(int argc, char** argv) { // TODO, only test version
if (argc < 2 || argc > 2) {
std::cout << "Wrong argument count (provide one argument - source file)\n";
return 0;
}
std::string filename = argv[1];
std::ifstream in;
in.open(filename); // TODO handle errors
std::stringstream source_stream;
source_stream << in.rdbuf();
in.close();
std::string source = source_stream.str();
parser::ParseTree parse_tree(source);
2023-05-05 11:59:02 +03:00
if (!parse_tree.IsProperlyParsed()) {
error_handling::HandleParsingError("There are some parsing errors in file.", {0, 0});
}
2023-03-31 12:10:12 +03:00
std::unique_ptr<interpreter::tokens::SourceFile> source_file =
std::make_unique<interpreter::tokens::SourceFile>();
interpreter::BuildVisitor build_visitor(parse_tree);
2023-04-26 01:02:53 +03:00
interpreter::PrintVisitor print_visitor(std::cout);
2023-03-31 12:10:12 +03:00
build_visitor.VisitSourceFile(source_file.get());
2023-04-26 01:02:53 +03:00
print_visitor.VisitSourceFile(source_file.get());
2023-03-31 12:10:12 +03:00
}