From 958868714eb0c248865eae19e642f5d95dcffc54 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Mon, 15 Apr 2024 05:56:01 +0630 Subject: main.cpp now preprocesses tokens and prints the output --- asm/main.cpp | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/asm/main.cpp b/asm/main.cpp index c2414b8..61ec667 100644 --- a/asm/main.cpp +++ b/asm/main.cpp @@ -22,6 +22,7 @@ #include "./base.hpp" #include "./lexer.hpp" +#include "./preprocesser.hpp" using std::pair, std::string, std::string_view, std::vector; @@ -48,8 +49,11 @@ int main(int argc, const char *argv[]) string source_str; string_view original; string_view src; - vector tokens; + vector tokens, preprocessed_tokens; lerr_t lerr; + pp_err_t pp_err; + + // Highest scoped variable cut off point if (file_source.has_value()) source_str = file_source.value(); @@ -86,15 +90,40 @@ int main(int argc, const char *argv[]) } else { + std::cout << "LEXER: \n" + "-------------------------------------------------------------" + "-------------------\n"; for (auto token : tokens) - { - std::cout << "\t" << token << std::endl; - } + std::cout << "\t" << *token << std::endl; + std::cout << "-------------------------------------------------------------" + "-------------------\n"; + } + + // preprocessing + std::tie(preprocessed_tokens, pp_err) = preprocesser(tokens); + if (pp_err.type != pp_err_type_t::OK) + { + std::cerr << file_name << ":" << pp_err.reference->line << ":" + << pp_err.reference->column << ":" << pp_err << std::endl; + ret = 255 - static_cast(pp_err.type); + goto end; + } + else + { + std::cout << "PREPROCESSER: \n" + "-------------------------------------------------------------" + "-------------------\n"; + for (auto token : preprocessed_tokens) + std::cout << "\t" << *token << std::endl; + std::cout << "-------------------------------------------------------------" + "-------------------\n"; } end: for (auto token : tokens) delete token; + for (auto token : preprocessed_tokens) + delete token; return ret; } -- cgit v1.2.3-13-gbd6f