lang/src/main.cpp

50 lines
1.2 KiB
C++
Raw Normal View History

2023-07-23 19:40:27 +03:00
#include <fstream>
#include <iostream>
#include <sstream>
2023-07-26 14:21:33 +03:00
#include "basic_printers.hpp"
2023-07-23 19:40:27 +03:00
#include "error_handling.hpp"
#include "expression_nodes.hpp"
2023-07-28 19:42:09 +03:00
#include "name_tree.hpp"
2023-07-23 19:40:27 +03:00
#include "statement_builders.hpp"
2023-07-26 14:21:33 +03:00
#include "statement_printers.hpp"
2023-07-23 19:40:27 +03:00
#include "type_nodes.hpp"
int main(int argc, char **argv) {
if (argc < 2 || argc > 2) {
std::cout << "Wrong argument count (one argument should be provided - "
"source file)\n";
return 0;
}
std::string filename = argv[1];
std::ifstream in;
in.open(filename);
std::stringstream source_stream;
source_stream << in.rdbuf();
in.close();
std::string source = source_stream.str();
parser::ParseTree parse_tree(source);
if (!parse_tree.is_properly_parsed()) {
error_handling::handle_parsing_error(
"There are some parsing errors in file", parse_tree.get_root());
}
nodes::ExpressionStorage expression_storage;
nodes::TypeStorage type_storage;
2023-07-28 19:42:09 +03:00
names::NameTree name_tree;
2023-07-23 19:40:27 +03:00
2023-07-26 14:21:33 +03:00
auto statements = builders::build_source_file(
2023-07-28 19:42:09 +03:00
parse_tree.get_root(), expression_storage, type_storage, name_tree);
2023-07-26 14:21:33 +03:00
2023-07-29 12:19:37 +03:00
printers::Printer printer(std::cout, 2, 80, true);
2023-07-26 14:21:33 +03:00
printers::print_source_file(statements, printer);
2023-07-16 20:55:07 +03:00
}