mirror of
https://github.com/hazemKrimi/jack-vm-translator.git
synced 2026-05-01 18:00:27 +00:00
Implement branching
This commit is contained in:
+14
-5
@@ -4,7 +4,7 @@
|
||||
#include <regex>
|
||||
#include <fstream>
|
||||
#include <cctype>
|
||||
#include <vector>
|
||||
#include "utils.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -37,17 +37,25 @@ private:
|
||||
if (!isEmptyLine(matched[1]))
|
||||
{
|
||||
string command = matched[1];
|
||||
|
||||
trim(command);
|
||||
vmCode.append(command + '\n');
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
trim(text);
|
||||
vmCode.append(text + '\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void closeFile()
|
||||
{
|
||||
file.close();
|
||||
}
|
||||
|
||||
public:
|
||||
Parser(string path)
|
||||
{
|
||||
@@ -73,6 +81,11 @@ public:
|
||||
matchedVector.push_back(matched[2]);
|
||||
matchedVector.push_back(matched[3]);
|
||||
}
|
||||
else if (regex_search(text, matched, regex("^(.*) (.*)")))
|
||||
{
|
||||
matchedVector.push_back(matched[1]);
|
||||
matchedVector.push_back(matched[2]);
|
||||
}
|
||||
else if (regex_search(text, matched, regex("^(.*)")))
|
||||
{
|
||||
matchedVector.push_back(matched[1]);
|
||||
@@ -82,8 +95,4 @@ public:
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
void closeFile() {
|
||||
file.close();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user