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); }