<commit_before>#include "Command.h"
#include "execute.h"
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <boost/foreach.hpp>
#include <boost/tokenizer.hpp>
using namespace std;
using namespace boost;

void parse(string text,vector<Command*>& tokens)
{
    
    char_separator<char> sep("|;&#");             
    tokenizer< char_separator<char> > tok(text, sep);
      
     BOOST_FOREACH (const string& t, tok) {
        Command* a = new Command();
        a->addtoken(t);
        tokens.push_back(a);
        
             
     }
        
         tokens.at(0)->addsign(1);          //because the first token has no sign
         int numb = 1;                      //keep track of vector
         
    for(unsigned i = 0; i< text.size()-1; i++) //this function will determine the sign(|| $$ && #) 
    {
        if(text.substr(i,2) == "||")        //int vector where 0 = #
        {                                   // 1 = ;
            tokens[numb]->addsign(2);       // 2 = ||
            numb ++;
        }                                   // 3 = &&
        if(text.at(i) == ';')              
        {
            tokens[numb]->addsign(1);        
            numb ++;
        }
        if(text.substr(i,2) == "&&")        // second parameter of substr() is length of substring
        {
            tokens[numb]->addsign(3);        
            numb ++;
        }
        if(text.at(i) == '#')
        {
            tokens[numb]->addsign(0);       
            numb ++;
        }
       
    bool prec = false;
    int in;
    int sie = 1;
    for(unsigned i = 0; i<tokens.size(); i++)           //（echo a && echo b || echo c)
    {        
        if(tokens[i]->tokenCheck().at(0) == ' ')
        { 
            string temp = tokens[i]->tokenCheck();
            temp.erase(temp.begin(), temp.begin()+1);
            tokens[i]->addtoken(temp);
        }
        if(tokens[i]->tokenCheck().at(tokens[i]->tokenCheck().size()-1) == ' ')
        { 
            string temp = tokens[i]->tokenCheck();
            temp.erase(temp.end()-1, temp.end());
            tokens[i]->addtoken(temp);
        }
        if(prec == true)
        {
            sie++;
        }
        if(tokens[i]->tokenCheck().at(0) == '(')
        {
            string temp = tokens[i]->tokenCheck();
            temp.erase(temp.begin(), temp.begin()+1);
            tokens[i]->addtoken(temp);
            prec = true;
            in = i;
        }
        if(tokens[i]->tokenCheck().at(tokens[i]->tokenCheck().size()-1) == ')')
        {
            tokens[in]->addprec(sie);
            //tokens[i]->addsign();
            sie = 1;
            //in = 0;
            prec = false;
            string temp = tokens[i]->tokenCheck();
            temp.erase(temp.end()-1, temp.end());
            tokens[i]->addtoken(temp);
        }
    }  
    }
    for(unsigned i = 0; i<tokens.size(); i++)  //we remove any whitespace in the token and will determine whether it is a test or not
    {
        if(tokens[i]->tokenCheck().at(0) == ' ')
        { 
            string temp = tokens[i]->tokenCheck();
            temp.erase(temp.begin(), temp.begin()+1);
            tokens[i]->addtoken(temp);
        }
        if(tokens[i]->tokenCheck().at(tokens[i]->tokenCheck().size()-1) == ' ')
        { 
            string temp = tokens[i]->tokenCheck();
            temp.erase(temp.end()-1, temp.end());
            tokens[i]->addtoken(temp);
        }
        if((tokens[i]->tokenCheck().at(0) == '[' && tokens[i]->tokenCheck().at(tokens[i]->tokenCheck().size()-1) == ']') || tokens[i]->tokenCheck().substr(0,4) == "test") //this looks for test commands and will add the sign 4 
        {
            tokens[i]->addsign(4);                                                                   
            tokens[i]->addtest(true);
        }

    }
    // bool prec = false;
    // int in;
    // int sie = 1;
    // for(unsigned i = 0; i<tokens.size(); i++)           //（echo a && echo b || echo c)
    // {        
    //     if(tokens[i]->tokenCheck().at(0) == ' ')
    //     { 
    //         string temp = tokens[i]->tokenCheck();
    //         temp.erase(temp.begin(), temp.begin()+1);
    //         tokens[i]->addtoken(temp);
    //     }
    //     if(tokens[i]->tokenCheck().at(tokens[i]->tokenCheck().size()-1) == ' ')
    //     { 
    //         string temp = tokens[i]->tokenCheck();
    //         temp.erase(temp.end()-1, temp.end());
    //         tokens[i]->addtoken(temp);
    //     }
    //     if(prec == true)
    //     {
    //         sie++;
    //     }
    //     if(tokens[i]->tokenCheck().at(0) == '(')
    //     {
    //         string temp = tokens[i]->tokenCheck();
    //         temp.erase(temp.begin(), temp.begin()+1);
    //         tokens[i]->addtoken(temp);
    //         prec = true;
    //         in = i;
    //     }
    //     if(tokens[i]->tokenCheck().at(tokens[i]->tokenCheck().size()-1) == ')')
    //     {
    //         tokens[in]->addprec(sie);
    //         //tokens[i]->addsign();
    //         sie = 1;
    //         //in = 0;
    //         prec = false;
    //         string temp = tokens[i]->tokenCheck();
    //         temp.erase(temp.end()-1, temp.end());
    //         tokens[i]->addtoken(temp);
    //     }
    // }
           
}


int main() {
    
    //command prompt
    //user enters commands-cin
    //q-quit command prompt
    
    //tokenizer class to break up the getline
    // use execvp, ... to run the commands fork waitpid
    //vector <string> tokens;<commit_msg>Update main.cpp<commit_after>#include "Command.h"
#include "execute.h"
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <boost/foreach.hpp>
#include <boost/tokenizer.hpp>
using namespace std;
using namespace boost;

void parse(string text,vector<Command*>& tokens)
{
    
    char_separator<char> sep("|;&#");             
    tokenizer< char_separator<char> > tok(text, sep);
      
     BOOST_FOREACH (const string& t, tok) {
        Command* a = new Command();
        a->addtoken(t);
        tokens.push_back(a);
        
             
     }
        
         tokens.at(0)->addsign(1);          //because the first token has no sign
         int numb = 1;                      //keep track of vector
         
    for(unsigned i = 0; i< text.size()-1; i++) //this function will determine the sign(|| $$ && #) 
    {
        if(text.substr(i,2) == "||")        //int vector where 0 = #
        {                                   // 1 = ;
            tokens[numb]->addsign(2);       // 2 = ||
            numb ++;
        }                                   // 3 = &&
        if(text.at(i) == ';')              
        {
            tokens[numb]->addsign(1);        
            numb ++;
        }
        if(text.substr(i,2) == "&&")        // second parameter of substr() is length of substring
        {
            tokens[numb]->addsign(3);        
            numb ++;
        }
        if(text.at(i) == '#')
        {
            tokens[numb]->addsign(0);       
            numb ++;
        }
     
    //check for the parenthesis and removes the parenthesis and any extra spaces then updates the token    
        
    bool prec = false;
    int in;
    int sie = 1;
    for(unsigned i = 0; i<tokens.size(); i++)           
    {        
        if(tokens[i]->tokenCheck().at(0) == ' ')
        { 
            string temp = tokens[i]->tokenCheck();
            temp.erase(temp.begin(), temp.begin()+1);
            tokens[i]->addtoken(temp);
        }
        if(tokens[i]->tokenCheck().at(tokens[i]->tokenCheck().size()-1) == ' ')
        { 
            string temp = tokens[i]->tokenCheck();
            temp.erase(temp.end()-1, temp.end());
            tokens[i]->addtoken(temp);
        }
        if(prec == true)
        {
            sie++;
        }
        if(tokens[i]->tokenCheck().at(0) == '(')
        {
            string temp = tokens[i]->tokenCheck();
            temp.erase(temp.begin(), temp.begin()+1);
            tokens[i]->addtoken(temp);
            prec = true;
            in = i;
        }
        if(tokens[i]->tokenCheck().at(tokens[i]->tokenCheck().size()-1) == ')')
        {
            tokens[in]->addprec(sie);
            //tokens[i]->addsign();
            sie = 1;
            //in = 0;
            prec = false;
            string temp = tokens[i]->tokenCheck();
            temp.erase(temp.end()-1, temp.end());
            tokens[i]->addtoken(temp);
        }
    }  
    }
    for(unsigned i = 0; i<tokens.size(); i++)  //we remove any whitespace in the token and will determine whether it is a test or not
    {
        if(tokens[i]->tokenCheck().at(0) == ' ')
        { 
            string temp = tokens[i]->tokenCheck();
            temp.erase(temp.begin(), temp.begin()+1);
            tokens[i]->addtoken(temp);
        }
        if(tokens[i]->tokenCheck().at(tokens[i]->tokenCheck().size()-1) == ' ')
        { 
            string temp = tokens[i]->tokenCheck();
            temp.erase(temp.end()-1, temp.end());
            tokens[i]->addtoken(temp);
        }
        if((tokens[i]->tokenCheck().at(0) == '[' && tokens[i]->tokenCheck().at(tokens[i]->tokenCheck().size()-1) == ']') || tokens[i]->tokenCheck().substr(0,4) == "test") //this looks for test commands and will add the sign 4 
        {
            tokens[i]->addsign(4);                                                                   
            tokens[i]->addtest(true);
        }

    }
           
}


int main() {
    
    //command prompt
    //user enters commands-cin
    //q-quit command prompt
    
    //tokenizer class to break up the getline
    // use execvp, ... to run the commands fork waitpid
    //vector <string> tokens;
{'fraction_non_alphanumeric': 0.18066236029939506, 'fraction_numerical': 0.00902286475956116, 'mean_word_length': 1.4012801575578533, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 111, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3042687', 'n_tokens_mistral': 2997, 'n_tokens_neox': 2956, 'n_words': 552}