Update Parserv2
This commit is contained in:
parent
ac43cf74b9
commit
459a8a5db6
1 changed files with 71 additions and 14 deletions
85
Parserv2
85
Parserv2
|
@ -37,21 +37,21 @@ vector<string> tokenize(string ss)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void par_select(vector<string> input)
|
// void par_select(vector<string> input)
|
||||||
{
|
// {
|
||||||
// if (input[0] != "(")
|
// // if (input[0] != "(")
|
||||||
// {
|
// // {
|
||||||
// cout<<"ERROR! missing parenthesis"<<endl;
|
// // cout<<"ERROR! missing parenthesis"<<endl;
|
||||||
// }
|
// // }
|
||||||
|
|
||||||
// else
|
// // else
|
||||||
// {
|
// // {
|
||||||
// input.erase(input.begin());
|
// // input.erase(input.begin());
|
||||||
|
|
||||||
// }
|
// // }
|
||||||
|
|
||||||
cout<<"par_select function was called!"<<endl;
|
// cout<<"par_select function was called!"<<endl;
|
||||||
}
|
// }
|
||||||
|
|
||||||
void displayTokenList(vector<string> input)
|
void displayTokenList(vector<string> input)
|
||||||
{
|
{
|
||||||
|
@ -112,6 +112,49 @@ vector<string> insertCMD(vector<string> input)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
vector<string> createCMD(vector<string> input)
|
||||||
|
{
|
||||||
|
//relation name will be the first element of the vector of data returned by this function
|
||||||
|
// vector<string> output;
|
||||||
|
|
||||||
|
// output.push_back(input[0]) //pushing relation name
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// if (input[0] == "VALUES" && input[1] == "FROM")
|
||||||
|
// {
|
||||||
|
// input.erase(input.begin());
|
||||||
|
// input.erase(input.begin());
|
||||||
|
|
||||||
|
|
||||||
|
// if(input[0] == "(")
|
||||||
|
// {
|
||||||
|
// input.erase(input.begin());
|
||||||
|
|
||||||
|
// while(input[0] != ")") //inserting all values to relation
|
||||||
|
// //for (int i = 0; i < 2; ++i)
|
||||||
|
// {
|
||||||
|
// if (input[0] == ",") input.erase(input.begin());
|
||||||
|
|
||||||
|
// output.push_back(input[0]);
|
||||||
|
|
||||||
|
// input.erase(input.begin());
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return output;
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
// else cout<<"Syntax error!"<<endl;
|
||||||
|
// }
|
||||||
|
// else cout<<"Syntax error!"<<endl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void par_line(vector<string> input) //calls par_command() or par_query() depending on first item from token list
|
void par_line(vector<string> input) //calls par_command() or par_query() depending on first item from token list
|
||||||
{
|
{
|
||||||
|
@ -150,13 +193,27 @@ void par_line(vector<string> input) //calls par_command() or par_query() dependi
|
||||||
|
|
||||||
if ( input[0] == "INSERT")
|
if ( input[0] == "INSERT")
|
||||||
{
|
{
|
||||||
cout<<"\nPassing the following arguments to dbEngine: \nCommand type: "<<input[0]<<endl;
|
cout<<"\nPassing the following arguments to dbEngine: \nCommand: "<<input[0]<<endl;
|
||||||
input.erase(input.begin());
|
input.erase(input.begin());
|
||||||
vector<string> insertInput = insertCMD(input);
|
vector<string> insertInput = insertCMD(input);
|
||||||
cout<<"arguments: "<<endl;
|
cout<<"arguments: "<<endl;
|
||||||
displayTokenList(insertInput);
|
displayTokenList(insertInput);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( input[0] == "CREATE")
|
||||||
|
{
|
||||||
|
cout<<"\nPassing the following arguments to dbEngine: \nCommand: "<<input[0]<<endl;
|
||||||
|
input.erase(input.begin());
|
||||||
|
input.erase(input.begin());
|
||||||
|
|
||||||
|
vector<string> insertInput = insertCMD(input);
|
||||||
|
cout<<"arguments: "<<endl;
|
||||||
|
displayTokenList(insertInput);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -199,7 +256,7 @@ int main () {
|
||||||
|
|
||||||
|
|
||||||
string ss = "INSERT INTO animals VALUES FROM ( Joe , cat , 4 ) ;";
|
string ss = "INSERT INTO animals VALUES FROM ( Joe , cat , 4 ) ;";
|
||||||
|
string ss2 = "CREATE TABLE animals ( name VARCHAR(20) , kind VARCHAR(8) , years INTEGER ) PRIMARY KEY (name, kind);";
|
||||||
|
|
||||||
vector<string> listOfTokens = tokenize(ss);
|
vector<string> listOfTokens = tokenize(ss);
|
||||||
par_line(listOfTokens);
|
par_line(listOfTokens);
|
||||||
|
|
Reference in a new issue