Update Parserv2.cpp
This commit is contained in:
parent
db10f42803
commit
11299fd6c5
1 changed files with 46 additions and 53 deletions
99
Parserv2.cpp
99
Parserv2.cpp
|
@ -1,17 +1,4 @@
|
||||||
|
tring;
|
||||||
#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);
|
stringstream lineStream(ss);
|
||||||
vector<string> output;
|
vector<string> output;
|
||||||
|
|
||||||
|
@ -107,11 +94,37 @@ vector<string> insertCMD(vector<string> input)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vector<string> showCMD(vector<string> input)
|
||||||
|
{
|
||||||
|
if (input.size() > 3)
|
||||||
|
{
|
||||||
|
cout<<"Syntax error!"<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout<<"\nPassing the following arguments to dbEngine: "<<endl;
|
||||||
|
cout<<"command :"<<input[0]<<endl;
|
||||||
|
cout<<"argument: "<<input[1]<<endl;
|
||||||
|
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<string> exitCMD(vector<string> input)
|
||||||
|
{
|
||||||
|
if (input[1] != ";")
|
||||||
|
{
|
||||||
|
cout<<"ERROR: missing semicolon!"<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input[0] != "EXIT") { cout<<"Wrong function/syntax error!"<<endl;}
|
||||||
|
cout<<"Passing command: "<<input[0]<<endl;
|
||||||
|
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
vector<string> createCMD(vector<string> input)
|
vector<string> createCMD(vector<string> input)
|
||||||
{
|
{
|
||||||
//relation name will be the first element of the vector of data returned by this function
|
// //relation name will be the first element of the vector of data returned by this function
|
||||||
// vector<string> output;
|
// vector<string> output;
|
||||||
|
|
||||||
// output.push_back(input[0]) //pushing relation name
|
// output.push_back(input[0]) //pushing relation name
|
||||||
|
@ -211,52 +224,32 @@ void par_line(vector<string> input) //calls par_command() or par_query() dependi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ( input[0] == "SHOW")
|
||||||
|
{
|
||||||
|
showCMD(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( input[0] == "EXIT")
|
||||||
|
{
|
||||||
|
exitCMD(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 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 () {
|
int main () {
|
||||||
|
|
||||||
|
|
||||||
string ss = "INSERT INTO animals VALUES FROM ( Joe , cat , 4 ) ;";
|
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);";
|
string ss2 = "SHOW Dogs ;";
|
||||||
|
string ss3 = "EXIT ; ";
|
||||||
|
|
||||||
vector<string> listOfTokens = tokenize(ss);
|
vector<string> listOfTokens = tokenize(ss);
|
||||||
|
vector<string> listOfTokens2 = tokenize(ss2);
|
||||||
|
vector<string> listOfTokens3 = tokenize(ss3);
|
||||||
|
|
||||||
par_line(listOfTokens);
|
par_line(listOfTokens);
|
||||||
|
par_line(listOfTokens2);
|
||||||
|
par_line(listOfTokens3);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue