From 33c2394142b0ed4f33d15ced576703dd3e10bbf6 Mon Sep 17 00:00:00 2001 From: Hazem Krimi Date: Thu, 26 Mar 2026 13:16:41 +0100 Subject: [PATCH] chore: entrypoint initial scaffolding --- main.cpp | 3 --- src/main.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) delete mode 100644 main.cpp create mode 100644 src/main.cpp diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 11b7fad..0000000 --- a/main.cpp +++ /dev/null @@ -1,3 +0,0 @@ -int main(int argc, char **argv) { - return 0; -} diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..ced9133 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +#include + +#include "parser.hpp" +#include "utils.hpp" + +int process(std::string source) { + std::ifstream ifs(source); + std::string line; + + LinkedList *commands = nullptr; + + while (getline(ifs, line)) { + if (isComment(line) || isEmptyLine(line)) + continue; + + int parseResult; + + if ((parseResult = parseCommand(commands, line)) != 0) + return parseResult; + } + + return 0; +} + +int main(int argc, char **argv) { + if (argc != 2) { + std::cerr << "You must specify an argument for the vm file to translate!" + << std::endl; + exit(1); + } + + std::string source = argv[1]; + + if (!regex_match(source, std::regex("^.+\\.vm"))) { + std::cerr << "Source file is not a vm file!" << std::endl; + exit(1); + } + + return process(source); +}