From 2118ba13e4cccb251c2d557ceedb271ab1126dc3 Mon Sep 17 00:00:00 2001 From: Hazem Krimi Date: Mon, 25 Mar 2024 23:34:26 +0100 Subject: [PATCH] Code class wip --- src/code.h | 20 ++++++++++++++++++++ src/main.cpp | 19 ++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 src/code.h diff --git a/src/code.h b/src/code.h new file mode 100644 index 0000000..8a68821 --- /dev/null +++ b/src/code.h @@ -0,0 +1,20 @@ +#include +#include +#include + +using namespace std; + +class Code +{ +private: + ofstream file; +public: + Code(string path) + { + file = ofstream(path); + } + + void writeToFile() { + file << "Hi!" << endl; + } +}; diff --git a/src/main.cpp b/src/main.cpp index 3db314c..63da0c6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,21 +1,34 @@ #include #include #include +#include using namespace std; +string constructTranslatedPath(string path) { + size_t position = path.rfind(".vm"); + + return path.replace(position, 3, ".hack"); +} + int main(int argc, char* argv[]) { - string path = argv[1]; + string sourcePath = argv[1]; - if (!regex_match(path, regex("^.+\\.vm"))) { + if (!regex_match(sourcePath, regex("^.+\\.vm"))) { cout << "Wrong file extension!" << endl; return 1; } - Parser parser(path); + Parser parser(sourcePath); parser.printFile(); + string translatedPath = constructTranslatedPath(sourcePath); + + Code code(translatedPath); + + code.writeToFile(); + return 0; } \ No newline at end of file