I am writing a small programming language that has only one keyword which is write
. I haven't done a parser but lexer. It works fine till it gets to "
token.
main.cpp:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <vector>
using namespace std;
int main(int argc, char* argv[2])
{
char text;
string tok = "";
string str = "";
vector <string> tokens;
fstream inFile(argv[1]);
while (inFile >> noskipws >> text)
{
tok += text;
if (tok == "write")
{
tokens.push_back(tok);
tok = "";
}
else if(tok == "\"")
{
str += text;
tokens.push_back("String:"+str);
str = "";
tok = "";
tok += text;
}
for (auto const& c : tokens)
std::cout << c << ' ';
}
return 0;
}
test.txt:
write "hello"
Output is:
write write write write write write write ...
Instead of,
String:hello
What can I do? Any ideas?