aboutsummaryrefslogtreecommitdiff
path: root/asm
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2024-04-15 05:56:01 +0630
committerAryadev Chavali <aryadev@aryadevchavali.com>2024-04-15 05:56:01 +0630
commit958868714eb0c248865eae19e642f5d95dcffc54 (patch)
tree3111697d929144cbb72151f39a9b80c1ab244218 /asm
parente22ed450ac2f86787f455f529d6ad1a2ccb33260 (diff)
downloadovm-958868714eb0c248865eae19e642f5d95dcffc54.tar.gz
ovm-958868714eb0c248865eae19e642f5d95dcffc54.tar.bz2
ovm-958868714eb0c248865eae19e642f5d95dcffc54.zip
main.cpp now preprocesses tokens and prints the output
Diffstat (limited to 'asm')
-rw-r--r--asm/main.cpp37
1 files 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<token_t *> tokens;
+ vector<token_t *> 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<int>(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;
}