Parser is ready to be linked with DBEngine

This commit is contained in:
Alexander Huddleston 2015-09-24 20:40:50 -05:00
parent 456a0a8e3d
commit 32015a7409

View file

@ -46,9 +46,9 @@ vector<string> showCMD(vector<string> input)
cout<<"Syntax error!"<<endl; cout<<"Syntax error!"<<endl;
} }
cout<<"\nPassing the following arguments to dbEngine: "<<endl; PRelation r(input[0]);
cout<<"command :"<<input[0]<<endl;
cout<<"argument: "<<input[1]<<endl; // send show command to DBEngine
return input; return input;
} }
@ -60,9 +60,9 @@ vector<string> saveCMD(vector<string> input)
cout<<"Syntax error!"<<endl; cout<<"Syntax error!"<<endl;
} }
cout<<"\nPassing the following arguments to dbEngine: "<<endl; PRelation r(input[0]);
cout<<"command :"<<input[0]<<endl;
cout<<"argument: "<<input[1]<<endl; // send save command to DBEngine
return input; return input;
} }
@ -74,23 +74,23 @@ vector<string> closeCMD(vector<string> input)
cout<<"Syntax error!"<<endl; cout<<"Syntax error!"<<endl;
} }
cout<<"\nPassing the following arguments to dbEngine: "<<endl; PRelation r(input[0]);
cout<<"command :"<<input[0]<<endl;
cout<<"argument: "<<input[1]<<endl; // send close command to DBEngine
return input; return input;
} }
vector<string> openCMD(vector<string> input) vector<string> openCMD(vector<string> input)
{ {
if (input.size() > 3) if (input.size() > 2)
{ {
cout<<"Syntax error!"<<endl; cout<<"Syntax error!"<<endl;
} }
cout<<"\nPassing the following arguments to dbEngine: "<<endl; PRelation r(input[0]);
cout<<"command :"<<input[0]<<endl;
cout<<"argument: "<<input[1]<<endl; // send open command to DBEngine
return input; return input;
} }
@ -291,76 +291,113 @@ vector<string> updateCMD(vector<string> input)
{ {
vector <PAttribute> a; vector <PAttribute> a;
PAttribute temp;
vector <string> s; vector <string> s;
vector <PExpression> e; //vector <PExpression> e;
input.erase(input.begin()); input.erase(input.begin());
while(input[0] != ")") while(input[0] != ")")
{ {
e.push_back(input[0]); temp.setPAttributeName(input[0]);
a.push_back(temp);
temp.setPAttributeName("~");
input.erase(input.begin());
if(input[0] == "=")
{
input.erase(input.begin());
s.push_back(input[0]);
}
else
{
cout<<"Syntax error!"<<endl;
}
if(input[0] == ",")
{
input.erase(input.begin());
}
} }
} }
if(input[0] == "WHERE") if(input[0] == "WHERE")
{ {
PCondition c; if(input[0] == "(")
while(input[0] != ";")
{ {
c.setPCondition(/*c.getCondition +*/ input[0]); //PCondition c;
PComparison c;
POperand oops1;
POperand oops2;
POp op;
while(input[0] != ")")
{
oops1.setPOperand(input[0]);
input.erase(input.begin());
oops2.setPOperand(input[0]);
input.erase(input.begin());
op.setPOp(input[0]);
input.erase(input.begin());
c.setPComparison(oops1.getPOperand(), op.getPOp(), oops2.getPOperand());
} }
} }
} }
// send update command to DBEngine
}
else cout<<"Syntax error!"<<endl; else cout<<"Syntax error!"<<endl;
} }
vector<string> deleteCMD(vector<string> input) vector<string> deleteCMD(vector<string> input)
{ {
// parse out DELETE FROM
if (input[0] == "DELETE" && input[1] == "FROM") if (input[0] == "DELETE" && input[1] == "FROM")
{ {
input.erase(input.begin()); input.erase(input.begin());
input.erase(input.begin()); input.erase(input.begin());
PRelation r(input[0]); PRelation r(input[0]);
if(input[0] == "WHERE")
{
if(input[0] == "(") if(input[0] == "(")
{ {
vector <PExpression> e; //PCondition c;
input.erase(input.begin());
PComparison c;
POperand oops1;
POperand oops2;
POp op;
while(input[0] != ")") while(input[0] != ")")
{ {
if (input[0] == ",") input.erase(input.begin()); oops1.setPOperand(input[0]);
e.push_back(input[0]);
input.erase(input.begin()); input.erase(input.begin());
oops2.setPOperand(input[0]);
input.erase(input.begin());
op.setPOp(input[0]);
input.erase(input.begin());
c.setPComparison(oops1.getPOperand(), op.getPOp(), oops2.getPOperand());
}
}
} }
cout << "Deleting: "; // send delete command to DBEngine
while(!e.empty())
{
cout << e[0].getPExpression() << " ";
e.erase(e.begin());
}
cout << "from " << r.getName() << ".\n";
return input;
} }
else cout<<"Syntax error!"<<endl; else cout<<"Syntax error!"<<endl;
}
//parser relation name into Relation r
//parse out WHERE
//parse condition into Condition c
//cout "Deleting [c] from [r]"
//return input
} }
void par_line(vector<string> input) //calls par_command() or par_query() depending on first item from token list void par_line(vector<string> input) //calls par_command() or par_query() depending on first item from token list
@ -379,26 +416,6 @@ void par_line(vector<string> input) //calls par_command() or par_query() dependi
else else
{ {
//command
// if ( input[0] == "open-cmd" || input[0] == "close-cmd" ||
// input[0] == "save-cmd" || input[0] == "exit-cmd" ||
// input[0] == "show-cmd" || input[0] == "create-cmd" ||
// input[0] == "update-cmd" || input[0] == "insert-cmd" ||
// input[0] == "delete-cmd" )
// {
// par_command(input[0]);
// }
//query
// if ( input[0] == "select" || input[0] == "project" ||
// input[0] == "product" || input[0] == "difference" ||
// input[0] == "union" || input[0] == "renaming" ||
// input[0] == "update-cmd" || input[0] == "insert-cmd" ||
// input[0] == "delete-cmd" )
// {
// par_query(input[0]);
// }
if ( input[0] == "INSERT") if ( input[0] == "INSERT")
{ {
cout<<"\nPassing the following arguments to dbEngine: \nCommand: "<<input[0]<<endl; cout<<"\nPassing the following arguments to dbEngine: \nCommand: "<<input[0]<<endl;
@ -413,9 +430,30 @@ void par_line(vector<string> input) //calls par_command() or par_query() dependi
{ {
cout<<"\nPassing the following arguments to dbEngine: \nCommand: "<<input[0]<<endl; cout<<"\nPassing the following arguments to dbEngine: \nCommand: "<<input[0]<<endl;
input.erase(input.begin()); input.erase(input.begin());
vector<string> insertInput = createCMD(input);
cout<<"arguments: "<<endl;
displayTokenList(insertInput);
}
if ( input[0] == "DELETE")
{
cout<<"\nPassing the following arguments to dbEngine: \nCommand: "<<input[0]<<endl;
input.erase(input.begin()); input.erase(input.begin());
vector<string> insertInput = insertCMD(input); vector<string> insertInput = deleteCMD(input);
cout<<"arguments: "<<endl;
displayTokenList(insertInput);
}
if ( input[0] == "UPDATE")
{
cout<<"\nPassing the following arguments to dbEngine: \nCommand: "<<input[0]<<endl;
input.erase(input.begin());
vector<string> insertInput = updateCMD(input);
cout<<"arguments: "<<endl; cout<<"arguments: "<<endl;
displayTokenList(insertInput); displayTokenList(insertInput);
@ -430,6 +468,21 @@ void par_line(vector<string> input) //calls par_command() or par_query() dependi
{ {
exitCMD(input); exitCMD(input);
} }
if ( input[0] == "OPEN")
{
openCMD(input);
}
if ( input[0] == "SAVE")
{
saveCMD(input);
}
if ( input[0] == "CLOSE")
{
closeCMD(input);
}
} }
} }