1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
Choice* token_choice = new Choice();
Sequence* token_sequence = new Sequence();
vector<Choice*> choice_vector;
vector<Keyword*> key_word_vector;
vector<Sequence*> token_sequence_vector;
int x = 0;
while(!file2.eof()){
char buf[MAX_CHARS_PER_LINE];
file2.getline(buf, MAX_CHARS_PER_LINE);
int n = 0;
const char* token[MAX_TOKENS_PER_LINE]= {};
token[0] = strtok(buf, DELIMITER);
if(token[0]){
for(n = 1; n < MAX_TOKENS_PER_LINE; n++){
token[n] = strtok(0, DELIMITER);
if(!token[n])
break;
}
}
for(int i = 0; i < n; i++){
//cout<<"token ["<<i<<"]: " << token[i] << endl;
token_copy.push_back(token[i]);
}
// cout<< endl;
}
for(int i = 0; i < token_copy.size(); i++){
cout<<"token_copy ["<<i<<"]: " << token_copy[i] << endl;
string token_as_string;
token_as_string = token_copy[i];
size_t pos= token_as_string.find(':');
//int count = 0;
if(pos != string::npos){
string keyword_in_text = token_as_string.substr(0, pos);
stored_keywords_vector.push_back(keyword_in_text);//keywords vector
cout<<"keyword: " << keyword_in_text << endl;
//stored_lines_vector.push_back(text_file_line.substr(pos + 1));//lines vector after colon extracted
Keyword* text_keyword = new Keyword(&keyword_map, keyword_in_text);
Keyword* text_keyword2 = new Keyword(&keyword_map2, keyword_in_text);
key_word_vector.push_back(text_keyword);
token_as_string = token_as_string.substr(pos + 1);
//cout<<"token as string1: " << token_as_string << endl;
//keyword_map[keyword_in_text] = parse(&keyword_map, stored_lines_vector[loop_count]);
//if(token_as_string[i] == ':'){
// Keyword* = new Keyword(&keyword_map, token_copy.substr(0, loc));
}
pos= token_as_string.find('|');
vector<Terminal*> token_terminal_vector;
while(pos != string::npos){
//cout<<"token as string2: " << token_as_string.substr(0, pos) << endl;
//Terminal* some_choice = new Terminal(token_as_string.substr(0, pos));
//token_terminal_vector.push_back(some_choice);
token_terminal_vector.push_back(new Terminal(token_as_string.substr(0, pos)));
//token_choice->addExpression(some_choice);
token_as_string = token_as_string.substr(pos + 1);
//cout<<"token as string: " << token_as_string << endl;
pos = token_as_string.find('|');
//keyword_map[keyword_in_text] = parse(&keyword_map, stored_lines_vector[loop_count]);
// keyword_map.insert(it, std::pair<string, Exp*>(keyword_in_text, token_terminal_vector[i]));
//if(token_as_string[i] == ':'){
// Keyword* = new Keyword(&keyword_map, token_copy.substr(0, loc));
}
if(pos == string::npos){
token_as_string = token_as_string.substr(0, pos);
//Terminal* some_choice = new Terminal(token_as_string);
//token_terminal_vector.push_back(some_choice);
token_terminal_vector.push_back(new Terminal(token_as_string));
//keyword_map.insert(it, std::pair<string, Exp*>(keyword_in_text, token_terminal_vector[i]));
//cout<<"token as string 3: " << token_as_string << endl;
}
//map<string, Exp*> keyword_map;
//cout<<"token terminal size: " << token_terminal_vector.size() << endl;
choice_vector.push_back(new Choice());
for(int i = 0; i < token_terminal_vector.size(); i++){
cout<<"token: " << i << ": " << token_terminal_vector[i]->getString() << endl;
cout<< endl;
//keyword_map.insert(it, std::pair<string, Exp*>(keyword_in_text, token_terminal_vector[i]));
token_choice->addExpression(token_terminal_vector[i]);
choice_vector[x]->addExpression(token_terminal_vector[i]);
cout<<"token choice inside for: " << choice_vector[x]->getString() << endl;
keyword_map2.insert(it2, std::pair<string, Exp*>(stored_keywords_vector[x], choice_vector[x]));
if(i+1 == token_terminal_vector.size()){
//token_sequence->addExpression(token_terminal_vector[i]);
token_sequence_vector.push_back(new Sequence());
//token_sequence_vector[x]->addExpression(token_terminal_vector[i]);
//token_sequence_vector[x]->addExpression(choice_vector[x]);
}
}
cout<< endl;
cout<<"token choice outside for: " << choice_vector[x]->getString() << endl;
|