i am currently making a "stack-based programming language" where in order to push a string onto the stack, you shall use " at the beggining on the string, and also on the end. So in the end an acceptable string is something like this: "some_string".
However, i need to tokenize the whole line of the file i am reading (splitting by whitespaces). This means i cant use such string: "hello are you there?" because it would get splitten up into "hello (new element) are (new element) you (new element) there?". And this is a problem because i want it to be a whole element, not four separated elements (since texts that are not beggining with a " are treated as keywords, and it would lead to a keyword not found error because i dont have the keyword yes).
This is my current code (where str should be the line i am reading from the file, and the delimiter is a simple whitespace, ' '):
std::vector<std::string> tokenize(std::string str, char delim) {
std::stringstream ss(str);
std::vector<std::string> out;
std::string s;
while (std::getline(ss, s, delim)) {
s.erase(std::remove(s.begin(), s.end(), '\t'), s.end());
out.push_back(s);
}
return out; }
What approach shall i take?