This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
dmspine64backup/Parserv2.cpp

193 lines
4.1 KiB
C++
Raw Normal View History

2015-09-22 21:30:28 -05:00
tring;
2015-09-22 18:54:21 -05:00
stringstream lineStream(ss);
vector<string> output;
while (lineStream >> tempString)
{
output.push_back(tempString);
}
//testing---------------
cout<<"TokenList: ";
for (int i = 0; i <output.size(); ++i)
{
cout<<output[i]<<" ";
}
//----------------------
return output;
}
void displayTokenList(vector<string> input)
{
cout<<"TokenList: "<<endl;
for (int i = 0; i < input.size(); ++i)
{
cout<<input[i]<<endl;
}
}
vector<string> insertCMD(vector<string> input)
{
//relation name will be the first element of the vector of data returned by this function
vector<string> output;
if (input[0] == "INTO")
{
input.erase(input.begin());
output.push_back(input[0]); //pushing relation name
input.erase(input.begin());
if (input[0] == "VALUES" && input[1] == "FROM")
{
input.erase(input.begin());
input.erase(input.begin());
if(input[0] == "(")
{
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());
output.push_back(input[0]);
input.erase(input.begin());
}
return output;
}
else cout<<"Syntax error!"<<endl;
}
else cout<<"Syntax error!"<<endl;
}
else cout<<"Syntax error!"<<endl;
}
2015-09-22 21:30:28 -05:00
vector<string> showCMD(vector<string> input)
{
if (input.size() > 3)
{
cout<<"Syntax error!"<<endl;
}
cout<<"\nPassing the following arguments to dbEngine: "<<endl;
2015-09-22 21:49:37 -05:00
cout << "command :" << input[0] << endl;
cout << "relation name / expression: "<< input[1] << endl;
2015-09-22 21:30:28 -05:00
return input;
}
vector<string> exitCMD(vector<string> input)
{
if (input[1] != ";")
{
cout<<"ERROR: missing semicolon!"<<endl;
2015-09-22 21:49:37 -05:00
return input;
2015-09-22 21:30:28 -05:00
}
2015-09-22 21:49:37 -05:00
if (input[0] != "EXIT") {
cout<<"Wrong function/syntax error!"<<endl;
return input;
}
2015-09-22 21:30:28 -05:00
2015-09-22 21:49:37 -05:00
cout<<"Passing command: "<< input[0] <<endl;
2015-09-22 21:30:28 -05:00
return input;
}
2015-09-22 18:54:21 -05:00
vector<string> createCMD(vector<string> input)
{
2015-09-22 21:49:37 -05:00
if (input[0] != "CREATE") {
2015-09-22 21:51:39 -05:00
cout << "Error: create keyword is missing." <<endl;
2015-09-22 21:49:37 -05:00
return input;
}
2015-09-22 18:54:21 -05:00
2015-09-22 21:49:37 -05:00
cout << "\nPassing the following arguments to dbEngine: " << endl;
2015-09-22 21:51:39 -05:00
// CREATE TABLE relation-name ( typed-attribute-list ) PRIMARY KEY ( attribute-list )
2015-09-22 21:49:37 -05:00
cout << "command :" << input[0] << endl;
2015-09-22 21:51:39 -05:00
cout << "argument: " << input[1] << endl;
return input;
2015-09-22 18:54:21 -05:00
}
2015-09-22 21:49:37 -05:00
vector<string> openCMD(vector<string> input){
2015-09-22 21:51:39 -05:00
if (input[0] != "OPEN") {
cout << "Error: open keyword is missing." <<endl;
return input;
}
cout << "\nPassing the following arguments to dbEngine: " << endl;
cout << "command :" << input[0] << endl;
cout << "relation: " << input[1] << endl;
2015-09-22 21:49:37 -05:00
}
2015-09-22 18:54:21 -05:00
2015-09-22 21:49:37 -05:00
vector<string> closeCMD(vector<string> input){
2015-09-22 21:51:39 -05:00
if (input[0] != "CLOSE") {
cout << "Error: close keyword is missing." <<endl;
return input;
}
cout << "\nPassing the following arguments to dbEngine: " << endl;
cout << "command :" << input[0] << endl;
cout << "relation: " << input[1] << endl;
2015-09-22 21:53:35 -05:00
return input;
2015-09-22 21:49:37 -05:00
}
2015-09-22 18:54:21 -05:00
2015-09-22 21:49:37 -05:00
vector<string> saveCMD(vector<string> input){
2015-09-22 21:51:39 -05:00
if (input[0] != "SAVE") {
cout << "Error: save keyword is missing." <<endl;
return input;
}
cout << "\nPassing the following arguments to dbEngine: " << endl;
cout << "command :" << input[0] << endl;
cout << "relation: " << input[1] << endl;
2015-09-22 21:53:35 -05:00
return input;
2015-09-22 21:49:37 -05:00
}
2015-09-22 18:54:21 -05:00
2015-09-22 21:49:37 -05:00
vector<string> updateCMD(vector<string> input){
2015-09-22 21:53:35 -05:00
//UPDATE relation-name SET attribute-name = literal { , attribute-name = literal } WHERE condition
2015-09-22 21:49:37 -05:00
}
2015-09-22 18:54:21 -05:00
2015-09-22 21:49:37 -05:00
vector<string> deleteCMD(vector<string> input){
2015-09-22 21:53:35 -05:00
//DELETE FROM relation-name WHERE condition
if (input[0] != "DELETE") {
cout << "Error: save keyword is missing." <<endl;
return input;
}
cout << "\nPassing the following arguments to dbEngine: " << endl;
cout << "command :" << input[0] << endl;
cout << "relation: " << input[1] << endl;
for (int i = 0; i < input.size(); ++i) {
cout << input[i] << "\n";
}
2015-09-22 18:54:21 -05:00
}
int main () {
string ss = "INSERT INTO animals VALUES FROM ( Joe , cat , 4 ) ;";
2015-09-22 21:30:28 -05:00
string ss2 = "SHOW Dogs ;";
string ss3 = "EXIT ; ";
2015-09-22 18:54:21 -05:00
vector<string> listOfTokens = tokenize(ss);
2015-09-22 21:30:28 -05:00
vector<string> listOfTokens2 = tokenize(ss2);
vector<string> listOfTokens3 = tokenize(ss3);
2015-09-22 18:54:21 -05:00
2015-09-22 21:30:28 -05:00
par_line(listOfTokens);
par_line(listOfTokens2);
par_line(listOfTokens3);
2015-09-22 18:54:21 -05:00
}