#include <iostream>
#include <vector>
using namespace std;
void printVect(vector<string> inp,char pchar = '\0') {
for (const string& w : inp) {
if (pchar != '\0') { cout << w << pchar; }
else { cout << w; }
}
}
long int findToken(vector<string> text,long int index, string ftext) {
for (index <= text.size(); index++;) {
if (text.at(index) == ftext){
return index;
}
}
return 0; // bulunamazsa döndürcek
}
vector<string> clearCode(vector<string> code, int baslangic, int bitis) {
// Verilen konumdan bitiş konumuna kadar verilen karakteri silcek
code.erase(code.begin()+baslangic,code.begin()+bitis);
printVect(code);
return code;
}
vector<string> Parser(string code, string charset) {
vector<string> parsingCode;
string guncelCode;
for (char c : code) {
bool found = false;
for (char checkChar : charset) {
if (checkChar == c) {
parsingCode.push_back(guncelCode);
parsingCode.push_back(string(1, checkChar));
guncelCode = "";
found = true;
break;
}
}
if (!found) {
guncelCode += c;
}
}
parsingCode.push_back(guncelCode);
//printVect(parsingCode);
return parsingCode;
}
string interpreter(vector<string> code) {
long int counter = 0;
/*
counter --> parselanmış kodda gelinen yerin indexi
*/
for (counter <= code.size(); counter++;) {
if (code[counter] == "write") {
code = clearCode(code,counter,findToken(code,counter,"("));
printVect(code);
}
}
return "";
}
int main() {
string code = "write (\"na ber\");";
string charset = ")(\"; ";
vector<string> output = Parser(code, charset);
interpreter(output);
return 0;
}