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
William Bracho Blok 4afb431044 Create Parserv2
2015-09-22 16:18:52 -05:00

175 lines
3.5 KiB
Text

#include <string> // std::string
#include <iostream> // std::cout
#include <sstream> // std::stringstream
#include <vector>
#include <string>
using namespace std;
/*
as of now, this parser can take a string and break it into tokens
*/
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;
}
}
void insertCMD(vector<string> input)
{
string relationName;
cout<<"insert-cmd function was called"<<endl;
if (input[0] == "INTO")
{
input.erase(input.begin());
relationName = input[0];
}
else
{
cout<<"Syntax error!"<<endl;
}
//displayTokenList(input);
}
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")
{
input.erase(input.begin());
insertCMD(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 () {
string ss = "INSERT INTO animals VALUES FROM ( Joe , cat , 4 ) ;";
vector<string> listOfTokens = tokenize(ss);
par_line(listOfTokens);
}