#include // std::string #include // std::cout #include // std::stringstream #include #include #include "Parserv3.h" 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) { cout<<"TokenList: "< showCMD(vector input) { if (input.size() > 3) { cout<<"Syntax error!"< saveCMD(vector input) { if (input.size() > 3) { cout<<"Syntax error!"< closeCMD(vector input) { if (input.size() > 3) { cout<<"Syntax error!"< openCMD(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 if (input[0] == "CREATE" && input[1] == "TABLE") { input.erase(input.begin()); input.erase(input.begin()); PRelation r; r.setPRelation(input[0]); input.erase(input.begin()); if(input[0] == "(") { input.erase(input.begin()); //vector e1; vector a; while(input[0] != ")") //inserting all values to relation { PAttribute temp; if (input[0] == ",") { input.erase(input.begin()); } temp.setPAttributeName(input[0]); input.erase(input.begin()); if(input[0] == "INTEGER") { temp.setPAttributeType(input[0]); input.erase(input.begin()); } else { temp.setPAttributeType(input[0].substr(0,input[0].find("("))); temp.setPAttributeSize(stoi(input[0].substr(input[0].find("("), input[0].find(")")))); input.erase(input.begin()); } a.push_back(temp); } vector apk; //save primary keys temp storage if(input[0] == "PRIMARY" && input[1] == "KEY") { input.erase(input.begin()); input.erase(input.begin()); if(input[0] == "(") { while(input[0] != ")") //inserting all values to relation { PAttribute temp; if (input[0] == ",") { input.erase(input.begin()); } temp.setPAttributeName(input[0]); apk.push_back(temp); input.erase(input.begin()); } return input; } } } else cout<<"Syntax error!"< insertCMD(vector input) { //relation name will be the first element of the vector of data returned by this function if (input[0] == "INTO") { input.erase(input.begin()); PRelation r(input[0]); input.erase(input.begin()); vector s; if (input[0] == "VALUES" && input[1] == "FROM") { input.erase(input.begin()); input.erase(input.begin()); if(input[0] == "(") { if(input[0].at(0) == '\"') { s.push_back(input[0].substr(1,input[0].find_last_of("\""))); } vector e; 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()); e.push_back(input[0]); input.erase(input.begin()); } cout << "Inserting: "; while(!e.empty()) { cout << e[0].getPExpression() << " "; e.erase(e.begin()); } cout << "into " << r.getName() << ".\n"; return input; } else if (input[0] == "RELATION") { input.erase(input.begin()); PExpression e; while(input[0] != ";") { e.setPExpression(e.getPExpression() + input[0]); } cout << "Inserting: " << e.getPExpression() << " into " << r.getName() << ".\n"; return input; } else cout<<"Syntax error!"< updateCMD(vector input) { PRelation r(input[0]); input.erase(input.begin()); if(input[0] == "SET") { input.erase(input.begin()); //parse out ( and send everything until ) into an Expression vector if(input[0] == "(") { vector a; vector s; vector e; input.erase(input.begin()); while(input[0] != ")") { e.push_back(input[0]); } } if(input[0] == "WHERE") { PCondition c; while(input[0] != ";") { c.setPCondition(/*c.getCondition +*/ input[0]); } } } else cout<<"Syntax error!"< deleteCMD(vector input) { // parse out DELETE FROM if (input[0] == "DELETE" && input[1] == "FROM") { input.erase(input.begin()); input.erase(input.begin()); PRelation r(input[0]); if(input[0] == "(") { vector e; input.erase(input.begin()); while(input[0] != ")") { if (input[0] == ",") input.erase(input.begin()); e.push_back(input[0]); input.erase(input.begin()); } cout << "Deleting: "; while(!e.empty()) { cout << e[0].getPExpression() << " "; e.erase(e.begin()); } cout << "from " << r.getName() << ".\n"; return input; } 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); vector listOfTokens2 = tokenize(ss2); vector listOfTokens3 = tokenize(ss3); par_line(listOfTokens); par_line(listOfTokens2); par_line(listOfTokens3); }