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;
} }
@ -59,10 +59,10 @@ 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;
} }
@ -73,24 +73,24 @@ 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,26 +291,69 @@ 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;
@ -318,49 +361,43 @@ vector<string> updateCMD(vector<string> input)
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] == "(")
if(input[0] == "WHERE")
{ {
vector <PExpression> e; if(input[0] == "(")
input.erase(input.begin());
while(input[0] != ")")
{ {
if (input[0] == ",") input.erase(input.begin()); //PCondition c;
e.push_back(input[0]); PComparison c;
POperand oops1;
POperand oops2;
POp op;
input.erase(input.begin()); 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());
}
} }
cout << "Deleting: ";
while(!e.empty())
{
cout << e[0].getPExpression() << " ";
e.erase(e.begin());
}
cout << "from " << r.getName() << ".\n";
return input;
} }
else cout<<"Syntax error!"<<endl;
// send delete command to DBEngine
} }
//parser relation name into Relation r else cout<<"Syntax error!"<<endl;
//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,57 +416,73 @@ void par_line(vector<string> input) //calls par_command() or par_query() dependi
else else
{ {
//command if ( input[0] == "INSERT")
// if ( input[0] == "open-cmd" || input[0] == "close-cmd" || {
// input[0] == "save-cmd" || input[0] == "exit-cmd" || cout<<"\nPassing the following arguments to dbEngine: \nCommand: "<<input[0]<<endl;
// input[0] == "show-cmd" || input[0] == "create-cmd" || input.erase(input.begin());
// input[0] == "update-cmd" || input[0] == "insert-cmd" || vector<string> insertInput = insertCMD(input);
// input[0] == "delete-cmd" ) cout<<"arguments: "<<endl;
// { displayTokenList(insertInput);
// 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")
{
cout<<"\nPassing the following arguments to dbEngine: \nCommand: "<<input[0]<<endl;
input.erase(input.begin());
vector<string> insertInput = insertCMD(input);
cout<<"arguments: "<<endl;
displayTokenList(insertInput);
}
if ( input[0] == "CREATE") }
{
cout<<"\nPassing the following arguments to dbEngine: \nCommand: "<<input[0]<<endl; if ( input[0] == "CREATE")
input.erase(input.begin()); {
input.erase(input.begin()); cout<<"\nPassing the following arguments to dbEngine: \nCommand: "<<input[0]<<endl;
input.erase(input.begin());
vector<string> insertInput = insertCMD(input);
cout<<"arguments: "<<endl;
displayTokenList(insertInput);
}
if ( input[0] == "SHOW")
{
showCMD(input);
}
if ( input[0] == "EXIT") vector<string> insertInput = createCMD(input);
{ cout<<"arguments: "<<endl;
exitCMD(input); displayTokenList(insertInput);
}
}
if ( input[0] == "DELETE")
{
cout<<"\nPassing the following arguments to dbEngine: \nCommand: "<<input[0]<<endl;
input.erase(input.begin());
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;
displayTokenList(insertInput);
}
if ( input[0] == "SHOW")
{
showCMD(input);
}
if ( input[0] == "EXIT")
{
exitCMD(input);
}
if ( input[0] == "OPEN")
{
openCMD(input);
}
if ( input[0] == "SAVE")
{
saveCMD(input);
}
if ( input[0] == "CLOSE")
{
closeCMD(input);
}
} }
} }