Added stoi() using in Parser, added compile message to README

This commit is contained in:
Alexander Huddleston 2015-09-24 19:39:07 -05:00
parent 6ef11188ea
commit 456a0a8e3d
3 changed files with 43 additions and 78 deletions

View file

@ -36,32 +36,28 @@ class PAttribute
{
string name;
string type;
string size;
bool key;
int size;
public:
PAttribute()
{
name = "~";
type = "~";
size = "~";
key = false;
size = 0;
}
PAttribute(string str, string t)
{
name = str;
type = t;
size = "~";
key = false;
size = 0;
}
PAttribute(string str, string t, string s)
PAttribute(string str, string t, int s)
{
name = str;
type = t;
size = s;
key = false;
}
void setPAttributeName(string str)
@ -74,16 +70,11 @@ class PAttribute
type = t;
}
void setPAttributeSize(string s)
void setPAttributeSize(int s)
{
size = s;
}
void setPAttributeKey()
{
key = true;
}
string getPAttribute()
{
return name;
@ -188,35 +179,25 @@ class PRenaming
class PProjection
{
string AName;
string RName;
string newName;
string oldName;
public:
PProjection()
{
AName = "~";
RName = "~";
newName = "~";
oldName = "~";
}
PProjection(string s1, string s2)
{
AName = s1;
RName = s2;
}
void setAName(string s)
{
AName = s;
}
void setRName(string s)
{
RName = s;
newName = s1;
oldName = s2;
}
string doPProjection()
{
return "Projecting " + AName + " onto " + RName;
return "Projecting " + oldName + " onto " + newName;
}
};
@ -398,22 +379,11 @@ class PExpression
PExpression(string str)
{
temp = str;
/*
if(str == "project")
{
proj.setAName("");
proj.setRName("");
}*/
}
void setPExpression(string str)
{
temp = str;
/*
if(proj.getAName() != "~" && proj.getRName() != "~")
{
proj.setAName()
}*/
}
string getPExpression()

View file

@ -127,6 +127,8 @@ vector<string> createCMD(vector<string> input)
{
input.erase(input.begin());
//vector <PExpression> e1;
vector <PAttribute> a;
while(input[0] != ")") //inserting all values to relation
@ -150,13 +152,15 @@ vector<string> createCMD(vector<string> input)
else
{
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());
}
a.push_back(temp);
}
vector <PAttribute> apk; //save primary keys temp storage
if(input[0] == "PRIMARY" && input[1] == "KEY")
{
input.erase(input.begin());
@ -167,25 +171,21 @@ vector<string> createCMD(vector<string> input)
while(input[0] != ")") //inserting all values to relation
{
PAttribute temp;
if (input[0] == ",")
{
input.erase(input.begin());
}
for(int i = 0; i < a.size(); ++i)
{
if(input[0] == a[i].getPAttribute())
{
a[i].setPAttributeKey();
break;
}
}
temp.setPAttributeName(input[0]);
apk.push_back(temp);
input.erase(input.begin());
}
// send create commands to DBEngine
return input;
}
@ -253,29 +253,14 @@ vector<string> insertCMD(vector<string> input)
{
input.erase(input.begin());
//PExpression e(input[0]);
PExpression e;
//input.erase(input.begin());
if(input[0] == "project")
while(input[0] != ";")
{
PProjection p;
input.erase(input.begin());
if(intput[0].at(0) == "(")
{
p.setAName(input[0].substr(1, input[0].find(")")));
e.setPExpression(e.getPExpression() + input[0]);
}
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;
}
@ -293,22 +278,23 @@ vector<string> insertCMD(vector<string> input)
vector<string> updateCMD(vector<string> input)
{
//parse Relation r
//parse out SET
if(input[0] == "SET")
{
input.erase(input.begin());
PRelation r(input[0]);
input.erase(input.begin());
if(input[0] == "SET")
{
input.erase(input.begin());
//parse out ( and send everything until ) into an Expression vector
if(input[0] == "(")
{
vector <PAttribute> a;
vector <string> s;
vector <PExpression> e;
input.erase(input.begin());
while(input[0] != ")")

View file

@ -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:
git remote set-url origin https://github.tamu.edu/USERNAME/DMS.git