initial commit
This commit is contained in:
commit
469ad9bb65
6 changed files with 85 additions and 0 deletions
50
einlesen.cpp
Normal file
50
einlesen.cpp
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <sstream>
|
||||
|
||||
std::vector<std::pair<std::string, std::string> > readFile(const std::string &filename) {
|
||||
std::vector<std::pair<std::string, std::string> > instructions;
|
||||
std::ifstream file(filename);
|
||||
if(!file.is_open()) {
|
||||
std::cerr << "Fehler: Datei " << filename << " konnte nicht geöffnet werden.\n";
|
||||
return instructions;
|
||||
}
|
||||
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
// Entferne führende oder trailing Whitespace
|
||||
if (line.empty()) continue;
|
||||
|
||||
std::istringstream iss(line);
|
||||
std::string command;
|
||||
std::string param;
|
||||
|
||||
if (!(iss >> command)) {
|
||||
// Keine gültige Eingabe in dieser Zeile
|
||||
continue;
|
||||
}
|
||||
|
||||
// Optionalen Parameter einlesen, falls vorhanden
|
||||
if (!(iss >> param)) {
|
||||
// Kein Parameter vorhanden
|
||||
param = "";
|
||||
}
|
||||
|
||||
instructions.push_back(std::make_pair(command, param));
|
||||
}
|
||||
|
||||
return instructions;
|
||||
}
|
||||
|
||||
// Beispiel zur Nutzung
|
||||
int main() {
|
||||
auto result = readFile("init");
|
||||
for (const auto &inst : result) {
|
||||
std::cout << "Befehl: " << inst.first << " | Parameter: " << inst.second << "\n";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
8
file_a
Normal file
8
file_a
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
READ A0
|
||||
ADD 5
|
||||
SUB 3
|
||||
READ A1
|
||||
ADD 10
|
||||
SUB 2
|
||||
ADD 7
|
||||
T
|
||||
8
file_b
Normal file
8
file_b
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
READ A2
|
||||
ADD 100
|
||||
SUB 20
|
||||
EXE file_c
|
||||
ADD 30
|
||||
READ A3
|
||||
SUB 15
|
||||
T
|
||||
7
file_c
Normal file
7
file_c
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
LOAD 50
|
||||
ADD 10
|
||||
EXE file_d
|
||||
SUB 20
|
||||
ADD 5
|
||||
SUB 10
|
||||
T
|
||||
6
file_d
Normal file
6
file_d
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
READ A4
|
||||
ADD 2
|
||||
READ A5
|
||||
SUB 1
|
||||
ADD 1
|
||||
T
|
||||
6
init
Normal file
6
init
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
LOAD 5
|
||||
ADD 3
|
||||
EXE file_a
|
||||
SUB 1
|
||||
EXE file_b
|
||||
T
|
||||
Loading…
Add table
Add a link
Reference in a new issue