updates
This commit is contained in:
parent
db10f42803
commit
97eaea15f2
4 changed files with 2 additions and 265 deletions
|
@ -45,7 +45,6 @@ bool Attribute::isKey(){
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
//may need to change primary key implementation
|
|
||||||
int Attribute::getSize(){
|
int Attribute::getSize(){
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ Relation DBEngine::projection(vector<string> input, Relation r){
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
//TEST ERRORS MATCHING
|
//test error matching
|
||||||
void DBEngine::rename(Relation& r, vector<string> oldnames, vector<string> newnames){
|
void DBEngine::rename(Relation& r, vector<string> oldnames, vector<string> newnames){
|
||||||
if (oldnames.size() != newnames.size()) {
|
if (oldnames.size() != newnames.size()) {
|
||||||
cout << "Failure to rename: number of attributes do not match.";
|
cout << "Failure to rename: number of attributes do not match.";
|
||||||
|
|
262
Parserv2.cpp
262
Parserv2.cpp
|
@ -1,262 +0,0 @@
|
||||||
|
|
||||||
#include <string> // std::string
|
|
||||||
#include <iostream> // std::cout
|
|
||||||
#include <sstream> // std::stringstream
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
vector<string> tokenize(string ss)
|
|
||||||
{
|
|
||||||
string tempString;
|
|
||||||
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 par_select(vector<string> input)
|
|
||||||
// {
|
|
||||||
// // if (input[0] != "(")
|
|
||||||
// // {
|
|
||||||
// // cout<<"ERROR! missing parenthesis"<<endl;
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// // else
|
|
||||||
// // {
|
|
||||||
// // input.erase(input.begin());
|
|
||||||
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// cout<<"par_select function was called!"<<endl;
|
|
||||||
// }
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
vector<string> createCMD(vector<string> input)
|
|
||||||
{
|
|
||||||
//relation name will be the first element of the vector of data returned by this function
|
|
||||||
// vector<string> output;
|
|
||||||
|
|
||||||
// output.push_back(input[0]) //pushing relation name
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void par_line(vector<string> input) //calls par_command() or par_query() depending on first item from token list
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
• Match the first item in the token list and determine weather this is a command or a query.
|
|
||||||
• Call functions par_command() or par_query();
|
|
||||||
• After either par_command() or par_query() returns, make sure the line ends properly with “;” token
|
|
||||||
*/
|
|
||||||
string tempChar = input.back();
|
|
||||||
if (tempChar != ";")
|
|
||||||
{
|
|
||||||
cout<<"ERROR! missing semicolon "<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
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")
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
input.erase(input.begin());
|
|
||||||
input.erase(input.begin());
|
|
||||||
|
|
||||||
vector<string> insertInput = insertCMD(input);
|
|
||||||
cout<<"arguments: "<<endl;
|
|
||||||
displayTokenList(insertInput);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// void par_command(string ss)
|
|
||||||
// {
|
|
||||||
|
|
||||||
// }
|
|
||||||
// void par_query(string ss);
|
|
||||||
// {
|
|
||||||
// if (input[0] == "select");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// void par_insert();
|
|
||||||
// void par_relationName();
|
|
||||||
// void par_literals();
|
|
||||||
|
|
||||||
|
|
||||||
// void par_condition();
|
|
||||||
// void par_conjuction();
|
|
||||||
// void par_automicexpr():
|
|
||||||
// /*
|
|
||||||
// • try to match the current pointer in the token list with the atomic-expr grammar.
|
|
||||||
// • If an Expr is identified, call par_expr() grammar function
|
|
||||||
// */
|
|
||||||
// void par_expr():
|
|
||||||
// /*
|
|
||||||
// try to match the current pointer in the token list with the expr grammar.
|
|
||||||
// Check the current token and identify a proper query (e.g., if project-query is identified, call par_project() grammer function).
|
|
||||||
// */
|
|
||||||
// void par_projection():
|
|
||||||
// /*try to match the current pointer in the token list with the projection grammar
|
|
||||||
// ◦ Call grammar function par_attribute_list
|
|
||||||
// ◦ (later on, return a View after the evaluation)
|
|
||||||
// */
|
|
||||||
int main () {
|
|
||||||
|
|
||||||
|
|
||||||
string ss = "INSERT INTO animals VALUES FROM ( Joe , cat , 4 ) ;";
|
|
||||||
string ss2 = "CREATE TABLE animals ( name VARCHAR(20) , kind VARCHAR(8) , years INTEGER ) PRIMARY KEY (name, kind);";
|
|
||||||
|
|
||||||
vector<string> listOfTokens = tokenize(ss);
|
|
||||||
par_line(listOfTokens);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -17,7 +17,7 @@ public:
|
||||||
void renameAttribute(string oldstr, string newstr);
|
void renameAttribute(string oldstr, string newstr);
|
||||||
int getSize();
|
int getSize();
|
||||||
void display();
|
void display();
|
||||||
void insertTuple(vector<string> tuple); //we are assuming they are in order
|
void insertTuple(vector<string> tuple); //assuming they are in order
|
||||||
void insertFromRelation(Relation r);
|
void insertFromRelation(Relation r);
|
||||||
//void removeTuple();
|
//void removeTuple();
|
||||||
};
|
};
|
Reference in a new issue