void State::build_word(bool allowed, string* word, size_t len) { if (len == 0) { return; } if (this->error_state) { if (allowed) { return; } } if (this->get_end_state() && allowed) { cout << "Accepting word: " << *word << endl; } else if (!this->get_end_state() && !allowed) { cout << "Rejecting word: " << *word << endl; } Alphabet* alpha = Alphabet::get_alphabet(); std::string* alpha_str = alpha->get_string(); for (size_t i = 0; i < alpha->get_size(); i++) { string tmp_string = *word; char c = (*alpha_str)[i]; tmp_string.push_back(c); this->map_transitions[c]->build_word(allowed, &tmp_string, len - 1); } }
void State::get_dot_graph(std::string* str, std::string* end_claim) { if (this->graphed) { return; } graphed = true; Alphabet* alpha = Alphabet::get_alphabet(); if (this->error_state) { str->append(this->name); str->append(" -> "); str->append(this->name); str->append(" [ label = \""); str->append(*alpha->get_string()); str->append("\" ];"); return; } for (size_t idx = 0; idx < alpha->get_size(); idx++) { char c = (*alpha->get_string())[idx]; State* s = this->map_transitions[c]; if (s == NULL) { cerr << "Ayeeee!!!!!" << endl; exit(-9005); } if (this->get_end_state()) { end_claim->append(this->name); end_claim->append("[shape = doublecircle ];\n"); } str->append(this->name); str->append(" -> "); str->append(*s->get_name()); str->append(" [label=\""); str->push_back(c); str->append("\"];\n"); s->get_dot_graph(str, end_claim); } }