mirror of
https://github.com/hazemKrimi/jack-vm-translator.git
synced 2026-05-01 18:00:27 +00:00
Code class wip
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class Code
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
ofstream file;
|
||||||
|
public:
|
||||||
|
Code(string path)
|
||||||
|
{
|
||||||
|
file = ofstream(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeToFile() {
|
||||||
|
file << "Hi!" << endl;
|
||||||
|
}
|
||||||
|
};
|
||||||
+16
-3
@@ -1,21 +1,34 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <parser.h>
|
#include <parser.h>
|
||||||
|
#include <code.h>
|
||||||
|
|
||||||
using namespace std;
|
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[])
|
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;
|
cout << "Wrong file extension!" << endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Parser parser(path);
|
Parser parser(sourcePath);
|
||||||
|
|
||||||
parser.printFile();
|
parser.printFile();
|
||||||
|
|
||||||
|
string translatedPath = constructTranslatedPath(sourcePath);
|
||||||
|
|
||||||
|
Code code(translatedPath);
|
||||||
|
|
||||||
|
code.writeToFile();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user