Added stoi() using in Parser, added compile message to README
This commit is contained in:
parent
6ef11188ea
commit
456a0a8e3d
3 changed files with 43 additions and 78 deletions
54
Parserv3.h
54
Parserv3.h
|
@ -36,32 +36,28 @@ class PAttribute
|
||||||
{
|
{
|
||||||
string name;
|
string name;
|
||||||
string type;
|
string type;
|
||||||
string size;
|
int size;
|
||||||
bool key;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PAttribute()
|
PAttribute()
|
||||||
{
|
{
|
||||||
name = "~";
|
name = "~";
|
||||||
type = "~";
|
type = "~";
|
||||||
size = "~";
|
size = 0;
|
||||||
key = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PAttribute(string str, string t)
|
PAttribute(string str, string t)
|
||||||
{
|
{
|
||||||
name = str;
|
name = str;
|
||||||
type = t;
|
type = t;
|
||||||
size = "~";
|
size = 0;
|
||||||
key = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PAttribute(string str, string t, string s)
|
PAttribute(string str, string t, int s)
|
||||||
{
|
{
|
||||||
name = str;
|
name = str;
|
||||||
type = t;
|
type = t;
|
||||||
size = s;
|
size = s;
|
||||||
key = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPAttributeName(string str)
|
void setPAttributeName(string str)
|
||||||
|
@ -74,16 +70,11 @@ class PAttribute
|
||||||
type = t;
|
type = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPAttributeSize(string s)
|
void setPAttributeSize(int s)
|
||||||
{
|
{
|
||||||
size = s;
|
size = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPAttributeKey()
|
|
||||||
{
|
|
||||||
key = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
string getPAttribute()
|
string getPAttribute()
|
||||||
{
|
{
|
||||||
return name;
|
return name;
|
||||||
|
@ -188,35 +179,25 @@ class PRenaming
|
||||||
|
|
||||||
class PProjection
|
class PProjection
|
||||||
{
|
{
|
||||||
string AName;
|
string newName;
|
||||||
string RName;
|
string oldName;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PProjection()
|
PProjection()
|
||||||
{
|
{
|
||||||
AName = "~";
|
newName = "~";
|
||||||
RName = "~";
|
oldName = "~";
|
||||||
}
|
}
|
||||||
|
|
||||||
PProjection(string s1, string s2)
|
PProjection(string s1, string s2)
|
||||||
{
|
{
|
||||||
AName = s1;
|
newName = s1;
|
||||||
RName = s2;
|
oldName = s2;
|
||||||
}
|
|
||||||
|
|
||||||
void setAName(string s)
|
|
||||||
{
|
|
||||||
AName = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setRName(string s)
|
|
||||||
{
|
|
||||||
RName = s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string doPProjection()
|
string doPProjection()
|
||||||
{
|
{
|
||||||
return "Projecting " + AName + " onto " + RName;
|
return "Projecting " + oldName + " onto " + newName;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -398,22 +379,11 @@ class PExpression
|
||||||
PExpression(string str)
|
PExpression(string str)
|
||||||
{
|
{
|
||||||
temp = str;
|
temp = str;
|
||||||
/*
|
|
||||||
if(str == "project")
|
|
||||||
{
|
|
||||||
proj.setAName("");
|
|
||||||
proj.setRName("");
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPExpression(string str)
|
void setPExpression(string str)
|
||||||
{
|
{
|
||||||
temp = str;
|
temp = str;
|
||||||
/*
|
|
||||||
if(proj.getAName() != "~" && proj.getRName() != "~")
|
|
||||||
{
|
|
||||||
proj.setAName()
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string getPExpression()
|
string getPExpression()
|
||||||
|
|
58
Parserv4.cpp
58
Parserv4.cpp
|
@ -127,6 +127,8 @@ vector<string> createCMD(vector<string> input)
|
||||||
{
|
{
|
||||||
input.erase(input.begin());
|
input.erase(input.begin());
|
||||||
|
|
||||||
|
//vector <PExpression> e1;
|
||||||
|
|
||||||
vector <PAttribute> a;
|
vector <PAttribute> a;
|
||||||
|
|
||||||
while(input[0] != ")") //inserting all values to relation
|
while(input[0] != ")") //inserting all values to relation
|
||||||
|
@ -150,13 +152,15 @@ vector<string> createCMD(vector<string> input)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
temp.setPAttributeType(input[0].substr(0,input[0].find("(")));
|
temp.setPAttributeType(input[0].substr(0,input[0].find("(")));
|
||||||
temp.setPAttributeSize(input[0].substr(input[0].find("("), input[0].find(")")));
|
temp.setPAttributeSize(stoi(input[0].substr(input[0].find("("), input[0].find(")"))));
|
||||||
input.erase(input.begin());
|
input.erase(input.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
a.push_back(temp);
|
a.push_back(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector <PAttribute> apk; //save primary keys temp storage
|
||||||
|
|
||||||
if(input[0] == "PRIMARY" && input[1] == "KEY")
|
if(input[0] == "PRIMARY" && input[1] == "KEY")
|
||||||
{
|
{
|
||||||
input.erase(input.begin());
|
input.erase(input.begin());
|
||||||
|
@ -167,26 +171,22 @@ vector<string> createCMD(vector<string> input)
|
||||||
|
|
||||||
while(input[0] != ")") //inserting all values to relation
|
while(input[0] != ")") //inserting all values to relation
|
||||||
{
|
{
|
||||||
|
PAttribute temp;
|
||||||
|
|
||||||
if (input[0] == ",")
|
if (input[0] == ",")
|
||||||
{
|
{
|
||||||
input.erase(input.begin());
|
input.erase(input.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < a.size(); ++i)
|
temp.setPAttributeName(input[0]);
|
||||||
{
|
|
||||||
if(input[0] == a[i].getPAttribute())
|
apk.push_back(temp);
|
||||||
{
|
|
||||||
a[i].setPAttributeKey();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
input.erase(input.begin());
|
input.erase(input.begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
// send create commands to DBEngine
|
|
||||||
|
|
||||||
|
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -253,30 +253,15 @@ vector<string> insertCMD(vector<string> input)
|
||||||
{
|
{
|
||||||
input.erase(input.begin());
|
input.erase(input.begin());
|
||||||
|
|
||||||
//PExpression e(input[0]);
|
PExpression e;
|
||||||
|
|
||||||
//input.erase(input.begin());
|
while(input[0] != ";")
|
||||||
|
|
||||||
if(input[0] == "project")
|
|
||||||
{
|
{
|
||||||
PProjection p;
|
e.setPExpression(e.getPExpression() + input[0]);
|
||||||
|
|
||||||
input.erase(input.begin());
|
|
||||||
|
|
||||||
if(intput[0].at(0) == "(")
|
|
||||||
{
|
|
||||||
p.setAName(input[0].substr(1, input[0].find(")")));
|
|
||||||
}
|
|
||||||
|
|
||||||
input.erase(input.begin());
|
|
||||||
|
|
||||||
p.setRName(input[0]);
|
|
||||||
|
|
||||||
input.erase(input.begin());
|
|
||||||
|
|
||||||
// send projection command to DBengine.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cout << "Inserting: " << e.getPExpression() << " into " << r.getName() << ".\n";
|
||||||
|
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,22 +278,23 @@ vector<string> insertCMD(vector<string> input)
|
||||||
|
|
||||||
vector<string> updateCMD(vector<string> input)
|
vector<string> updateCMD(vector<string> input)
|
||||||
{
|
{
|
||||||
//parse Relation r
|
PRelation r(input[0]);
|
||||||
|
|
||||||
|
input.erase(input.begin());
|
||||||
|
|
||||||
//parse out SET
|
|
||||||
if(input[0] == "SET")
|
if(input[0] == "SET")
|
||||||
{
|
{
|
||||||
input.erase(input.begin());
|
input.erase(input.begin());
|
||||||
|
|
||||||
PRelation r(input[0]);
|
|
||||||
|
|
||||||
input.erase(input.begin());
|
|
||||||
|
|
||||||
//parse out ( and send everything until ) into an Expression vector
|
//parse out ( and send everything until ) into an Expression vector
|
||||||
if(input[0] == "(")
|
if(input[0] == "(")
|
||||||
{
|
{
|
||||||
|
|
||||||
|
vector <PAttribute> a;
|
||||||
|
vector <string> s;
|
||||||
|
|
||||||
vector <PExpression> e;
|
vector <PExpression> e;
|
||||||
|
|
||||||
input.erase(input.begin());
|
input.erase(input.begin());
|
||||||
|
|
||||||
while(input[0] != ")")
|
while(input[0] != ")")
|
||||||
|
|
|
@ -1,3 +1,12 @@
|
||||||
|
//---IMPORTANT---//
|
||||||
|
|
||||||
|
The function stoi() is used in the parser .cpp file to parse integers from the input.
|
||||||
|
When compiling things with the parser included, make sure you compile using:
|
||||||
|
|
||||||
|
g++ -std=c++11 *.cpp
|
||||||
|
|
||||||
|
//---------------//
|
||||||
|
|
||||||
I changed the name of the repo. To make everything pretty, rename your working folder, and type this line:
|
I changed the name of the repo. To make everything pretty, rename your working folder, and type this line:
|
||||||
|
|
||||||
git remote set-url origin https://github.tamu.edu/USERNAME/DMS.git
|
git remote set-url origin https://github.tamu.edu/USERNAME/DMS.git
|
||||||
|
|
Reference in a new issue