Update Parserv2.cpp
This commit is contained in:
parent
db10f42803
commit
f8a1923856
1 changed files with 39 additions and 2 deletions
41
Parserv2.cpp
41
Parserv2.cpp
|
@ -7,6 +7,9 @@
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
/*
|
||||||
|
as of now, this parser can take a string and break it into tokens
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
vector<string> tokenize(string ss)
|
vector<string> tokenize(string ss)
|
||||||
|
@ -107,11 +110,33 @@ vector<string> insertCMD(vector<string> input)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector<string> showCMD(vector<string> input)
|
||||||
|
{
|
||||||
|
if (input.size() > 3)
|
||||||
|
{
|
||||||
|
cout<<"Syntax error!"<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout<<"\nPassing the following arguments to dbEngine: "<<endl;
|
||||||
|
cout<<"command :"<<input[0]<<endl;
|
||||||
|
cout<<"argument: "<<input[1]<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<string> exitCMD(vector<string> input)
|
||||||
|
{
|
||||||
|
if (input[1] != ";")
|
||||||
|
{
|
||||||
|
cout<<"ERROR: missing semicolon!"<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input[0] != "EXIT") { cout<<"Wrong function/syntax error!"<<endl;}
|
||||||
|
cout<<"Passing command: "<<input[0]<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
vector<string> createCMD(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
|
// //relation name will be the first element of the vector of data returned by this function
|
||||||
// vector<string> output;
|
// vector<string> output;
|
||||||
|
|
||||||
// output.push_back(input[0]) //pushing relation name
|
// output.push_back(input[0]) //pushing relation name
|
||||||
|
@ -211,6 +236,12 @@ void par_line(vector<string> input) //calls par_command() or par_query() dependi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ( input[0] == "SHOW")
|
||||||
|
{
|
||||||
|
showCMD(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -253,10 +284,16 @@ 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);";
|
string ss2 = "SHOW Dogs ;";
|
||||||
|
string ss3 = "EXIT ; ";
|
||||||
|
|
||||||
vector<string> listOfTokens = tokenize(ss);
|
vector<string> listOfTokens = tokenize(ss);
|
||||||
|
//vector<string> listOfTokens2 = tokenize(ss2);
|
||||||
|
//vector<string> listOfTokens3 = tokenize(ss3);
|
||||||
|
|
||||||
par_line(listOfTokens);
|
par_line(listOfTokens);
|
||||||
|
//par_line(listOfTokens2);
|
||||||
|
//par_line(listOfTokens3);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue