50 lines
1.5 KiB
C++
50 lines
1.5 KiB
C++
//
|
|
// Created by black on 06.07.25.
|
|
//
|
|
|
|
#include "ProgramLoader.h"
|
|
#include <sstream>
|
|
|
|
ProgramLoader *ProgramLoader::getInstance() {
|
|
static ProgramLoader instance;
|
|
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 {
|
|
out.clear();
|
|
/// Trenne den IStringStream bei jedem Leerzeichen und füge die Befehl(e)/-sargumente dem Output hinzu
|
|
std::getline(iss, out, ' ');
|
|
if (out.empty()) break;
|
|
/// Stoppe, sobald ein Kommentar im Source Code vorkommt
|
|
if (out.at(0) != '#') {
|
|
if (out.at(out.length() - 1) == ',') {
|
|
out.erase(out.length() - 1);
|
|
}
|
|
output.push_back(out);
|
|
} else {
|
|
break;
|
|
}
|
|
} while (!out.empty());
|
|
return output;
|
|
}
|
|
|
|
void ProgramLoader::indexFile(std::ifstream &m_programFile) {
|
|
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++;
|
|
}
|
|
}
|