Update Parserv2.cpp
This commit is contained in:
parent
11299fd6c5
commit
52c801715c
1 changed files with 31 additions and 128 deletions
159
Parserv2.cpp
159
Parserv2.cpp
|
@ -20,23 +20,6 @@ tring;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// void par_select(vector<string> input)
|
|
||||||
// {
|
|
||||||
// // if (input[0] != "(")
|
|
||||||
// // {
|
|
||||||
// // cout<<"ERROR! missing parenthesis"<<endl;
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// // else
|
|
||||||
// // {
|
|
||||||
// // input.erase(input.begin());
|
|
||||||
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// cout<<"par_select function was called!"<<endl;
|
|
||||||
// }
|
|
||||||
|
|
||||||
void displayTokenList(vector<string> input)
|
void displayTokenList(vector<string> input)
|
||||||
{
|
{
|
||||||
cout<<"TokenList: "<<endl;
|
cout<<"TokenList: "<<endl;
|
||||||
|
@ -102,8 +85,8 @@ vector<string> showCMD(vector<string> input)
|
||||||
}
|
}
|
||||||
|
|
||||||
cout<<"\nPassing the following arguments to dbEngine: "<<endl;
|
cout<<"\nPassing the following arguments to dbEngine: "<<endl;
|
||||||
cout<<"command :"<<input[0]<<endl;
|
cout << "command :" << input[0] << endl;
|
||||||
cout<<"argument: "<<input[1]<<endl;
|
cout << "relation name / expression: "<< input[1] << endl;
|
||||||
|
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
@ -113,131 +96,51 @@ vector<string> exitCMD(vector<string> input)
|
||||||
if (input[1] != ";")
|
if (input[1] != ";")
|
||||||
{
|
{
|
||||||
cout<<"ERROR: missing semicolon!"<<endl;
|
cout<<"ERROR: missing semicolon!"<<endl;
|
||||||
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input[0] != "EXIT") { cout<<"Wrong function/syntax error!"<<endl;}
|
if (input[0] != "EXIT") {
|
||||||
cout<<"Passing command: "<<input[0]<<endl;
|
cout<<"Wrong function/syntax error!"<<endl;
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout<<"Passing command: "<< input[0] <<endl;
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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
|
if (input[0] != "CREATE") {
|
||||||
// vector<string> output;
|
cout << "Error, create keyword is missing." <<endl;
|
||||||
|
return input;
|
||||||
// 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;
|
|
||||||
|
|
||||||
|
cout << "\nPassing the following arguments to dbEngine: " << endl;
|
||||||
|
cout << "command :" << input[0] << endl;
|
||||||
|
cout << "argument: " << input[1] << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector<string> openCMD(vector<string> input){
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<string> closeCMD(vector<string> input){
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<string> saveCMD(vector<string> input){
|
||||||
|
//open-cmd ::== OPEN relation-name
|
||||||
|
//close-cmd ::== CLOSE relation-name
|
||||||
|
//save-cmd ::== SAVE relation-name
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<string> updateCMD(vector<string> input){
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<string> deleteCMD(vector<string> input){
|
||||||
void par_line(vector<string> input) //calls par_command() or par_query() depending on first item from token list
|
//
|
||||||
{
|
|
||||||
/*
|
|
||||||
• Match the first item in the token list and determine weather this is a command or a query.
|
|
||||||
• Call functions par_command() or par_query();
|
|
||||||
• After either par_command() or par_query() returns, make sure the line ends properly with “;” token
|
|
||||||
*/
|
|
||||||
string tempChar = input.back();
|
|
||||||
if (tempChar != ";")
|
|
||||||
{
|
|
||||||
cout<<"ERROR! missing semicolon "<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//command
|
|
||||||
// if ( input[0] == "open-cmd" || input[0] == "close-cmd" ||
|
|
||||||
// input[0] == "save-cmd" || input[0] == "exit-cmd" ||
|
|
||||||
// input[0] == "show-cmd" || input[0] == "create-cmd" ||
|
|
||||||
// input[0] == "update-cmd" || input[0] == "insert-cmd" ||
|
|
||||||
// input[0] == "delete-cmd" )
|
|
||||||
// {
|
|
||||||
// par_command(input[0]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
//query
|
|
||||||
// if ( input[0] == "select" || input[0] == "project" ||
|
|
||||||
// input[0] == "product" || input[0] == "difference" ||
|
|
||||||
// input[0] == "union" || input[0] == "renaming" ||
|
|
||||||
// input[0] == "update-cmd" || input[0] == "insert-cmd" ||
|
|
||||||
// input[0] == "delete-cmd" )
|
|
||||||
// {
|
|
||||||
// par_query(input[0]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
if ( input[0] == "INSERT")
|
|
||||||
{
|
|
||||||
cout<<"\nPassing the following arguments to dbEngine: \nCommand: "<<input[0]<<endl;
|
|
||||||
input.erase(input.begin());
|
|
||||||
vector<string> insertInput = insertCMD(input);
|
|
||||||
cout<<"arguments: "<<endl;
|
|
||||||
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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ( input[0] == "SHOW")
|
|
||||||
{
|
|
||||||
showCMD(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( input[0] == "EXIT")
|
|
||||||
{
|
|
||||||
exitCMD(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main () {
|
int main () {
|
||||||
|
|
Reference in a new issue