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 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
Exp* parse(multimap<string, Exp*>* keywords, string input){
// Fill me in! figure out what type of expr it is in parse, do recursively
string line_inside_parse = input;
string new_line_after_parse_extraction;
string expression;
Choice* parsed_choice_expressions= new Choice();
Sequence* parsed_sequence_expressions = new Sequence();
vector<string> vector_of_expressions;
//cout<<"line_inside_parse: "<< line_inside_parse << endl;
size_t pos= input.find('|');
if(pos != string::npos){
//cout<<"line inside parse: "<< line_inside_parse << endl;
expression = line_inside_parse.substr(0, pos);
Choice* ret = new Choice();
ret->addExpression(parse(keywords, expression));
//parsed_choice_expressions->addExpression(parse(keywords, expression));
//parsed_choice_expressions->addExpression(ret);
//cout<<"expression before for inside parse: " << expression << endl;
new_line_after_parse_extraction = line_inside_parse.substr(pos + 1);
// return parsed_terminal;
//cout<<"new line after parse before for inside parse: " << new_line_after_parse_extraction << endl;
//Terminal* initial_parse_to_terminal_expression = new Terminal(expression);
//parsed_choice_expressions->addExpression(initial_parse_to_terminal_expression);
//cout<<"parsed_choice expressions inside parse before for: " << parsed_choice_expressions->getString() << endl;
vector_of_expressions.push_back(expression);
//store the terminal inside the choice vector
//cout<<"new_line_after_parse_extraction outside while loop: " << new_line_after_parse_extraction << endl;
// cout<<"newline size outside while: " << new_line_after_parse_extraction.size() << endl;
//for(int i = 0; i < new_line_after_parse_extraction.size(); i++){
while(new_line_after_parse_extraction.size() != 0 && new_line_after_parse_extraction != expression){
//cout<<"\ninside while\n";
//cout<<"newline size inside while: " << new_line_after_parse_extraction.size() << endl;
pos = new_line_after_parse_extraction.find('|');
expression = new_line_after_parse_extraction.substr(0, pos);
vector_of_expressions.push_back(expression);
//cout<<"expression inside parse inside for loop: " << expression << endl;
new_line_after_parse_extraction = new_line_after_parse_extraction.substr(pos + 1);
//cout<<"newline size inside while: " << new_line_after_parse_extraction.size() << endl;
//cout<<"new_line_after_parse_extraction inside while: " << new_line_after_parse_extraction << endl;
//cout<<"size of line after extraction: " << text_file_expressions_after_extraction.length() << endl;
// Terminal* parse_to_terminal_expression = new Terminal(expression);
// parsed_choice_expressions->addExpression(parse(keywords, expression));
//parsed_choice_expressions->addExpression(parse_to_terminal_expression);
//cout<<"parsed_choice expressions inside parse inside for loop: " << parsed_choice_expressions->getString() << endl;
//cout<<"vector_of_expressions size: " << vector_of_expressions.size() << endl;
//for(int i = 0; i < vector_of_expressions.size(); i++)\\
//cout<<"\nhere " << endl;
ret->addExpression(parse(keywords, expression));
//cout<<"vector of expressions: " << i+1 << ": "<< vector_of_expressions[i] << endl;
//cout<<"ret inside while loop: " << ret->getString() << endl;
//if(new_line_after_parse_extraction == expression){
//return parse(keywords, new_line_after_parse_extraction);
//ret->addExpression(parse(keywords, expression));
//break;
//}
}
if(pos == string::npos){
//Choice* ret = new Choice();
expression = new_line_after_parse_extraction.substr(0, pos);
//cout<<"expression at npos: " << expression << endl;
ret->addExpression(parse(keywords, expression));
}
//cout<<"vector_of_expressions size: " << vector_of_expressions.size() << endl;
vector<Exp*> vector_of_terminals(vector_of_expressions.size());
for(int i = 0; i < vector_of_expressions.size(); i++){
//vector_of_terminals.push_back(new Terminal(vector_of_expressions[i]));
vector_of_terminals[i] = new Terminal(vector_of_expressions[i]);
//cout<< "vector of terminals: " << i+1 <<": " << vector_of_terminals[i]->getString() << endl;
//parsed_choice_expressions->addExpression(parse(keywords, vector_of_terminals[i]->getString()));
parsed_choice_expressions->addExpression(vector_of_terminals[i]);
//cout<<"parsed_choice_expressions: " << i << " : " << parsed_choice_expressions->getString() << endl;
}
//parsed_choice_expressions->addExpression(parsed_terminal);
//parsed_sequence_expressions->addExpression(parsed_choice_expressions);
//cout<<"parsed choice expressions inside parse: " << parsed_choice_expressions->getString() << endl;
//cout<<"expression: " << expression << endl;
//parse(keywords, line_inside_parse);
//return parse(keywords, line_inside_parse);
cout<<"ret before return: " << ret->getString() << endl;
return ret;
}
int main() {
multimap<string, Exp*> keyword_map2;
multimap<string, Exp*>::iterator it4= keyword_map2.begin();
loopcount = 0;
if(pos != string::npos){
keyword_in_text = text_file_line.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_map2, keyword_in_text);
keyword_map2[keyword_in_text] = parse(&keyword_map2, stored_lines_vector[loop_count]);
keyword_map2.insert(it4, std::make_pair<string, Exp*>(parse(keyword_in_text, stored_lines_vector[loop_count]));
//Exp* text_file_parsed_call= parse(&keyword_map2, stored_lines_vector[loop_count]);
//cout<<"text file after parse called : " << text_file_parsed_call->getString() << endl;
//keyword_map[keyword_in_text] = parse2(&keyword_map, stored_lines_vector[loop_count]);
//cout<<"k: " << keyword_map2[keyword_in_text]->getString() << endl;
}
loopcount++;
}
|