Update Parserv2.cpp

This commit is contained in:
scho4077 2015-09-22 21:30:28 -05:00
parent db10f42803
commit 11299fd6c5

View file

@ -1,17 +1,4 @@
#include <string> // std::string
#include <iostream> // std::cout
#include <sstream> // std::stringstream
#include <vector>
#include <string>
using namespace std;
vector<string> tokenize(string ss)
{
string tempString;
tring;
stringstream lineStream(ss);
vector<string> output;
@ -107,11 +94,37 @@ vector<string> insertCMD(vector<string> input)
}
vector<string> showCMD(vector<string> input)
{
if (input.size() > 3)
{
cout<<"Syntax error!"<<endl;
}
cout<<"\nPassing the following arguments to dbEngine: "<<endl;
cout<<"command :"<<input[0]<<endl;
cout<<"argument: "<<input[1]<<endl;
return input;
}
vector<string> exitCMD(vector<string> input)
{
if (input[1] != ";")
{
cout<<"ERROR: missing semicolon!"<<endl;
}
if (input[0] != "EXIT") { cout<<"Wrong function/syntax error!"<<endl;}
cout<<"Passing command: "<<input[0]<<endl;
return input;
}
vector<string> createCMD(vector<string> 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<string> output;
// output.push_back(input[0]) //pushing relation name
@ -211,52 +224,32 @@ void par_line(vector<string> 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<string> listOfTokens = tokenize(ss);
par_line(listOfTokens);
vector<string> listOfTokens2 = tokenize(ss2);
vector<string> listOfTokens3 = tokenize(ss3);
par_line(listOfTokens);
par_line(listOfTokens2);
par_line(listOfTokens3);
}