From 762b806fe74aa61acbd2fde1ddf41a95ddb60b86 Mon Sep 17 00:00:00 2001 From: black Date: Fri, 4 Jul 2025 21:42:56 +0200 Subject: [PATCH] initial CommandParser implementation --- emulator/CommandParser.cpp | 20 ++++++++++++++++++++ emulator/CommandParser.h | 24 +++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/emulator/CommandParser.cpp b/emulator/CommandParser.cpp index 5795436..9f1b554 100644 --- a/emulator/CommandParser.cpp +++ b/emulator/CommandParser.cpp @@ -3,3 +3,23 @@ // #include "CommandParser.h" + +CommandParser & CommandParser::getInstance() { + static CommandParser instance; + return instance; +} + +std::vector CommandParser::parseLine(const std::string &input) { + std::vector 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, ' '); + if (out.at(0) != '#') { + output.push_back(out); + } + } while (!out.empty()); + return output; +} diff --git a/emulator/CommandParser.h b/emulator/CommandParser.h index e2d2f48..2177963 100644 --- a/emulator/CommandParser.h +++ b/emulator/CommandParser.h @@ -4,11 +4,33 @@ #ifndef COMMANDPARSER_H #define COMMANDPARSER_H - +#include +#include class CommandParser { +private: + CommandParser() = default; + +public: + /// Singleton Logik + CommandParser(const CommandParser&) = delete; + CommandParser(const CommandParser&&) = delete; + CommandParser& operator=(const CommandParser&) = delete; + CommandParser& operator=(const CommandParser&&) = delete; + ~CommandParser() = default; + + static CommandParser& getInstance(); + + /** + * Parst eine Zeile des Assembly Codes und gibt diese als sortierten Vektor zurück + * + * @param input Eine Zeile aus dem Assembly Code + * @return Ein Vektor mit Befehl und dessen Argumenten + */ + static std::vector parseLine(const std::string& input); + };