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); +}