From 7e221bf13e8348065cd6354da51be22f5dc46be8 Mon Sep 17 00:00:00 2001 From: William Bracho Blok Date: Tue, 22 Sep 2015 07:32:39 -0500 Subject: [PATCH 1/5] Create Parser.cpp as of now, this parser can take a string and break it into tokens --- Parser.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Parser.cpp diff --git a/Parser.cpp b/Parser.cpp new file mode 100644 index 0000000..4a9092f --- /dev/null +++ b/Parser.cpp @@ -0,0 +1,44 @@ + +#include // std::string +#include // std::cout +#include // std::stringstream +#include +#include + +using namespace std; + +/* + as of now, this parser can take a string and break it into tokens +*/ + + +vector tokenize(string ss) +{ + string tempString; + stringstream lineStream(ss); + vector output; + + while (lineStream >> tempString) + { + output.push_back(tempString); + } + + return output; + +} + +int main () { + + + string ss = "INSERT INTO animals VALUES FROM ( Joe , cat , 4 ) ;"; + + + vector listOfTokens = tokenize(ss); + + + for (int i = 0; i < listOfTokens.size(); ++i) + { + cout<<" slot "< Date: Tue, 22 Sep 2015 16:18:52 -0500 Subject: [PATCH 2/5] Create Parserv2 --- Parserv2 | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 Parserv2 diff --git a/Parserv2 b/Parserv2 new file mode 100644 index 0000000..af89934 --- /dev/null +++ b/Parserv2 @@ -0,0 +1,175 @@ + +#include // std::string +#include // std::cout +#include // std::stringstream +#include +#include + +using namespace std; + +/* + as of now, this parser can take a string and break it into tokens +*/ + + +vector tokenize(string ss) +{ + string tempString; + stringstream lineStream(ss); + vector output; + + while (lineStream >> tempString) + { + output.push_back(tempString); + } + + //testing--------------- + cout<<"TokenList: "; + + for (int i = 0; i input) +{ + // if (input[0] != "(") + // { + // cout<<"ERROR! missing parenthesis"< input) +{ + cout<<"TokenList: "< input) +{ + string relationName; + + cout<<"insert-cmd function was called"< 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 "< listOfTokens = tokenize(ss); + par_line(listOfTokens); + + +} From ac43cf74b94ab4eb4eff3e14d648c383156fed3b Mon Sep 17 00:00:00 2001 From: William Bracho Blok Date: Tue, 22 Sep 2015 17:11:51 -0500 Subject: [PATCH 3/5] Update Parserv2 --- Parserv2 | 55 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/Parserv2 b/Parserv2 index af89934..8e53d6a 100644 --- a/Parserv2 +++ b/Parserv2 @@ -63,22 +63,51 @@ void displayTokenList(vector input) } -void insertCMD(vector input) +vector insertCMD(vector input) { - string relationName; - - cout<<"insert-cmd function was called"< output; + if (input[0] == "INTO") { input.erase(input.begin()); - relationName = input[0]; + + output.push_back(input[0]); //pushing relation name + + input.erase(input.begin()); + + 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!"< input) //calls par_command() or par_query() dependi if ( input[0] == "INSERT") { + cout<<"\nPassing the following arguments to dbEngine: \nCommand type: "< insertInput = insertCMD(input); + cout<<"arguments: "< Date: Tue, 22 Sep 2015 18:38:04 -0500 Subject: [PATCH 4/5] Update Parserv2 --- Parserv2 | 85 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 71 insertions(+), 14 deletions(-) diff --git a/Parserv2 b/Parserv2 index 8e53d6a..675cbb1 100644 --- a/Parserv2 +++ b/Parserv2 @@ -37,21 +37,21 @@ vector tokenize(string ss) } -void par_select(vector input) -{ - // if (input[0] != "(") - // { - // cout<<"ERROR! missing parenthesis"< input) +// { + // // if (input[0] != "(") + // // { + // // cout<<"ERROR! missing parenthesis"< input) { @@ -112,6 +112,49 @@ vector insertCMD(vector input) +vector 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!"< input) //calls par_command() or par_query() depending on first item from token list { @@ -150,13 +193,27 @@ void par_line(vector input) //calls par_command() or par_query() dependi if ( input[0] == "INSERT") { - cout<<"\nPassing the following arguments to dbEngine: \nCommand type: "< insertInput = insertCMD(input); cout<<"arguments: "< insertInput = insertCMD(input); + cout<<"arguments: "< listOfTokens = tokenize(ss); par_line(listOfTokens); From 40848ba29cf875ae393d0f34b62c58710f381e34 Mon Sep 17 00:00:00 2001 From: William Bracho Blok Date: Tue, 22 Sep 2015 18:40:39 -0500 Subject: [PATCH 5/5] Update Parserv2 --- Parserv2 | 3 --- 1 file changed, 3 deletions(-) diff --git a/Parserv2 b/Parserv2 index 675cbb1..17394b4 100644 --- a/Parserv2 +++ b/Parserv2 @@ -7,9 +7,6 @@ using namespace std; -/* - as of now, this parser can take a string and break it into tokens -*/ vector tokenize(string ss)