From 156903415c46c296d3a57cadb1a075e1e5724a5c Mon Sep 17 00:00:00 2001 From: Rebecca Schofield Date: Tue, 22 Sep 2015 18:54:21 -0500 Subject: [PATCH] fixed file extension --- Parserv2.cpp | 262 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 262 insertions(+) create mode 100755 Parserv2.cpp diff --git a/Parserv2.cpp b/Parserv2.cpp new file mode 100755 index 0000000..17394b4 --- /dev/null +++ b/Parserv2.cpp @@ -0,0 +1,262 @@ + +#include // std::string +#include // std::cout +#include // std::stringstream +#include +#include + +using namespace std; + + + +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: "< insertCMD(vector input) +{ + //relation name will be the first element of the vector of data returned by this function + vector output; + + if (input[0] == "INTO") + { + input.erase(input.begin()); + + 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!"< 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 +{ +/* +• 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: "< listOfTokens = tokenize(ss); + par_line(listOfTokens); + + +}