Create Parser.cpp
as of now, this parser can take a string and break it into tokens
This commit is contained in:
parent
9f5d3e5346
commit
7e221bf13e
1 changed files with 44 additions and 0 deletions
44
Parser.cpp
Normal file
44
Parser.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
|
||||
#include <string> // std::string
|
||||
#include <iostream> // std::cout
|
||||
#include <sstream> // std::stringstream
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/*
|
||||
as of now, this parser can take a string and break it into tokens
|
||||
*/
|
||||
|
||||
|
||||
vector<string> tokenize(string ss)
|
||||
{
|
||||
string tempString;
|
||||
stringstream lineStream(ss);
|
||||
vector<string> output;
|
||||
|
||||
while (lineStream >> tempString)
|
||||
{
|
||||
output.push_back(tempString);
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
int main () {
|
||||
|
||||
|
||||
string ss = "INSERT INTO animals VALUES FROM ( Joe , cat , 4 ) ;";
|
||||
|
||||
|
||||
vector<string> listOfTokens = tokenize(ss);
|
||||
|
||||
|
||||
for (int i = 0; i < listOfTokens.size(); ++i)
|
||||
{
|
||||
cout<<" slot "<<i<<" : ";
|
||||
cout<<listOfTokens[i]<<endl;
|
||||
}
|
||||
}
|
Reference in a new issue