From 11299fd6c5e21c187ab16002a6e832b9e3fb6d7a Mon Sep 17 00:00:00 2001 From: scho4077 Date: Tue, 22 Sep 2015 21:30:28 -0500 Subject: [PATCH 1/5] Update Parserv2.cpp --- Parserv2.cpp | 99 ++++++++++++++++++++++++---------------------------- 1 file changed, 46 insertions(+), 53 deletions(-) diff --git a/Parserv2.cpp b/Parserv2.cpp index 17394b4..6d77211 100755 --- a/Parserv2.cpp +++ b/Parserv2.cpp @@ -1,17 +1,4 @@ - -#include // std::string -#include // std::cout -#include // std::stringstream -#include -#include - -using namespace std; - - - -vector tokenize(string ss) -{ - string tempString; +tring; stringstream lineStream(ss); vector output; @@ -107,11 +94,37 @@ vector insertCMD(vector input) } +vector showCMD(vector input) +{ + if (input.size() > 3) + { + cout<<"Syntax error!"< exitCMD(vector input) +{ + if (input[1] != ";") + { + cout<<"ERROR: missing semicolon!"< createCMD(vector 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 output; // output.push_back(input[0]) //pushing relation name @@ -211,52 +224,32 @@ void par_line(vector input) //calls par_command() or par_query() dependi } + if ( input[0] == "SHOW") + { + showCMD(input); + } + + if ( input[0] == "EXIT") + { + exitCMD(input); + } + + } } - - -// void par_command(string ss) -// { - -// } -// void par_query(string ss); -// { - // if (input[0] == "select"); -// } - -// void par_insert(); -// void par_relationName(); -// void par_literals(); - - -// void par_condition(); -// void par_conjuction(); -// void par_automicexpr(): -// /* -// • try to match the current pointer in the token list with the atomic-expr grammar. -// • If an Expr is identified, call par_expr() grammar function -// */ -// void par_expr(): -// /* -// try to match the current pointer in the token list with the expr grammar. -// Check the current token and identify a proper query (e.g., if project-query is identified, call par_project() grammer function). -// */ -// void par_projection(): -// /*try to match the current pointer in the token list with the projection grammar -// ◦ Call grammar function par_attribute_list -// ◦ (later on, return a View after the evaluation) -// */ int main () { - - 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 listOfTokens = tokenize(ss); - par_line(listOfTokens); + vector listOfTokens2 = tokenize(ss2); + vector listOfTokens3 = tokenize(ss3); - + par_line(listOfTokens); + par_line(listOfTokens2); + par_line(listOfTokens3); } From 52c801715ca547acc9228ad35260c5359e59235e Mon Sep 17 00:00:00 2001 From: scho4077 Date: Tue, 22 Sep 2015 21:49:37 -0500 Subject: [PATCH 2/5] Update Parserv2.cpp --- Parserv2.cpp | 159 ++++++++++----------------------------------------- 1 file changed, 31 insertions(+), 128 deletions(-) diff --git a/Parserv2.cpp b/Parserv2.cpp index 6d77211..7e15a93 100755 --- a/Parserv2.cpp +++ b/Parserv2.cpp @@ -20,23 +20,6 @@ tring; } - -// void par_select(vector input) -// { - // // if (input[0] != "(") - // // { - // // cout<<"ERROR! missing parenthesis"< input) { cout<<"TokenList: "< showCMD(vector input) } cout<<"\nPassing the following arguments to dbEngine: "< exitCMD(vector input) if (input[1] != ";") { cout<<"ERROR: missing semicolon!"< createCMD(vector input) { - // //relation name will be the first element of the vector of data returned by this function - // vector 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!"< openCMD(vector input){ + // +} +vector closeCMD(vector input){ + // +} +vector saveCMD(vector input){ + //open-cmd ::== OPEN relation-name +//close-cmd ::== CLOSE relation-name +//save-cmd ::== SAVE relation-name +} +vector updateCMD(vector input){ + // +} - -void par_line(vector 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 "< insertInput = insertCMD(input); - cout<<"arguments: "< insertInput = insertCMD(input); - cout<<"arguments: "< deleteCMD(vector input){ + // } int main () { From 74bc10d0adc9d163bce91f024e842d588c3e538f Mon Sep 17 00:00:00 2001 From: scho4077 Date: Tue, 22 Sep 2015 21:51:39 -0500 Subject: [PATCH 3/5] Update Parserv2.cpp --- Parserv2.cpp | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/Parserv2.cpp b/Parserv2.cpp index 7e15a93..150bab1 100755 --- a/Parserv2.cpp +++ b/Parserv2.cpp @@ -112,27 +112,48 @@ vector exitCMD(vector input) vector createCMD(vector input) { if (input[0] != "CREATE") { - cout << "Error, create keyword is missing." < openCMD(vector input){ + if (input[0] != "OPEN") { + cout << "Error: open keyword is missing." < openCMD(vector input){ - // + cout << "relation: " << input[1] << endl; } vector closeCMD(vector input){ - // + if (input[0] != "CLOSE") { + cout << "Error: close keyword is missing." < saveCMD(vector input){ - //open-cmd ::== OPEN relation-name -//close-cmd ::== CLOSE relation-name -//save-cmd ::== SAVE relation-name + if (input[0] != "SAVE") { + cout << "Error: save keyword is missing." < updateCMD(vector input){ From db3469594acd349201d27ade48cdba56567408f4 Mon Sep 17 00:00:00 2001 From: scho4077 Date: Tue, 22 Sep 2015 21:53:35 -0500 Subject: [PATCH 4/5] Update Parserv2.cpp --- Parserv2.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Parserv2.cpp b/Parserv2.cpp index 150bab1..427bbdb 100755 --- a/Parserv2.cpp +++ b/Parserv2.cpp @@ -143,6 +143,7 @@ vector closeCMD(vector input){ cout << "\nPassing the following arguments to dbEngine: " << endl; cout << "command :" << input[0] << endl; cout << "relation: " << input[1] << endl; + return input; } vector saveCMD(vector input){ @@ -154,14 +155,26 @@ vector saveCMD(vector input){ cout << "\nPassing the following arguments to dbEngine: " << endl; cout << "command :" << input[0] << endl; cout << "relation: " << input[1] << endl; + return input; } vector updateCMD(vector input){ - // + //UPDATE relation-name SET attribute-name = literal { , attribute-name = literal } WHERE condition } vector deleteCMD(vector input){ - // + //DELETE FROM relation-name WHERE condition + if (input[0] != "DELETE") { + cout << "Error: save keyword is missing." < Date: Tue, 22 Sep 2015 21:57:52 -0500 Subject: [PATCH 5/5] Update Parserv2.cpp --- Parserv2.cpp | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/Parserv2.cpp b/Parserv2.cpp index 427bbdb..4d4b742 100755 --- a/Parserv2.cpp +++ b/Parserv2.cpp @@ -171,22 +171,14 @@ vector deleteCMD(vector input){ cout << "\nPassing the following arguments to dbEngine: " << endl; cout << "command :" << input[0] << endl; - cout << "relation: " << input[1] << endl; + cout << "relation: " << input[2] << endl; for (int i = 0; i < input.size(); ++i) { cout << input[i] << "\n"; } } int main () { - string ss = "INSERT INTO animals VALUES FROM ( Joe , cat , 4 ) ;"; - string ss2 = "SHOW Dogs ;"; - string ss3 = "EXIT ; "; + string ss = "DELETE FROM animals WHERE (age == 12);"; - vector listOfTokens = tokenize(ss); - vector listOfTokens2 = tokenize(ss2); - vector listOfTokens3 = tokenize(ss3); - - par_line(listOfTokens); - par_line(listOfTokens2); - par_line(listOfTokens3); + vector listOfTokens = tokenize(s); }