Implement branching

This commit is contained in:
Hazem Krimi
2024-05-02 21:26:14 +01:00
parent 8262f49d85
commit 2040a363e3
5 changed files with 97 additions and 14 deletions
+14 -5
View File
@@ -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();
}
};