reordering and ProgramLoader basic functionality
This commit is contained in:
56
src/ProgramLoader.cpp
Normal file
56
src/ProgramLoader.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// Created by black on 06.07.25.
|
||||
//
|
||||
|
||||
#include "ProgramLoader.h"
|
||||
#include <sstream>
|
||||
|
||||
ProgramLoader::ProgramLoader(const std::string &path){
|
||||
m_programFile.open(path);
|
||||
}
|
||||
|
||||
ProgramLoader * ProgramLoader::getInstance(const std::string &program_path) {
|
||||
static ProgramLoader instance{program_path};
|
||||
return &instance;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::vector<std::string> ProgramLoader::parseLine(const std::string &input) {
|
||||
std::vector<std::string> output{};
|
||||
/// Konvertiere den Input String in einen IStringStream, damit dieser bei Leerzeichen gesplittet werden kann
|
||||
std::istringstream iss(input);
|
||||
std::string out;
|
||||
do {
|
||||
/// Trenne den IStringStream bei jedem Leerzeichen und füge die Befehl(e)/-sargumente dem Output hinzu
|
||||
std::getline(iss, out, ' ');
|
||||
/// Stoppe, sobald ein Kommentar im Source Code vorkommt
|
||||
if (out.at(0) != '#') {
|
||||
if (out.at(out.length() -1) == ',') {
|
||||
out.erase(out.length() - 1);
|
||||
}
|
||||
if (out.at(out.length() -1) == ':') {
|
||||
break;
|
||||
}
|
||||
output.push_back(out);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while (!out.empty());
|
||||
return output;
|
||||
}
|
||||
|
||||
void ProgramLoader::indexFile() {
|
||||
if (m_programFile.is_open()) {
|
||||
std::string line;
|
||||
int lineNumber = 1;
|
||||
/// Parse Zeile für Zeile
|
||||
while (std::getline(m_programFile, line)) {
|
||||
auto lineVector = parseLine(line);
|
||||
const auto first = lineVector.begin();
|
||||
/// Sobald ein Label gefunden wurde, speichere die Zeile
|
||||
if (first->at(first->length() - 1) == ':') {
|
||||
m_labels[first->substr(0, first->length() - 1)] = lineNumber;
|
||||
}
|
||||
lineNumber++;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user