From 2b849607dc3c77a24bb756f044eef927c534d499 Mon Sep 17 00:00:00 2001 From: dak151449 Date: Fri, 26 Jan 2024 21:05:38 +0300 Subject: [PATCH] =?UTF-8?q?(#301)=20=D0=98=D0=B7=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D1=81=D1=8F=20=D0=BE=D1=82=20=D0=BC=D1=83=D1=81=D0=BE?= =?UTF-8?q?=D1=80=D0=B0/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/Objects/include/Objects/AlgExpression.h | 3 --- libs/Objects/src/AlgExpression.cpp | 11 ++-------- libs/Objects/src/Regex.cpp | 22 ++++++++++---------- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/libs/Objects/include/Objects/AlgExpression.h b/libs/Objects/include/Objects/AlgExpression.h index 8c2785c4..82205330 100644 --- a/libs/Objects/include/Objects/AlgExpression.h +++ b/libs/Objects/include/Objects/AlgExpression.h @@ -72,9 +72,6 @@ class AlgExpression : public BaseObject { void generate_alphabet(); // Генерация алфавита и создание нового языка void make_language(); - - std::string _to_txt(bool eps_is_empty) const; - // для print_tree void print_subtree(AlgExpression* expr, int level) const; // для print_dot diff --git a/libs/Objects/src/AlgExpression.cpp b/libs/Objects/src/AlgExpression.cpp index 2aa45325..0953c288 100644 --- a/libs/Objects/src/AlgExpression.cpp +++ b/libs/Objects/src/AlgExpression.cpp @@ -114,16 +114,12 @@ bool AlgExpression::is_terminal_type(Type t) { } string AlgExpression::to_txt() const { - return _to_txt(true); -} - -string AlgExpression::_to_txt(bool eps_is_empty) const { string str1, str2; if (term_l) { - str1 = term_l->_to_txt(eps_is_empty); + str1 = term_l->to_txt(); } if (term_r) { - str2 = term_r->_to_txt(eps_is_empty); + str2 = term_r->to_txt(); } string symb; switch (type) { @@ -139,9 +135,6 @@ string AlgExpression::_to_txt(bool eps_is_empty) const { symb = symbol; break; case Type::eps: - if (!eps_is_empty) { - symb = Symbol::Epsilon; - } break; case Type::alt: symb = '|'; diff --git a/libs/Objects/src/Regex.cpp b/libs/Objects/src/Regex.cpp index fe8abc35..428f21e5 100644 --- a/libs/Objects/src/Regex.cpp +++ b/libs/Objects/src/Regex.cpp @@ -753,7 +753,7 @@ Regex* Regex::add_alt(std::vector res, Regex* root) { Regex* Regex::to_aci(std::vector& res) { // отсортировали вектор регулярок std::sort(res.begin(), res.end(), [](const Regex& i, const Regex& j) { - return i._to_txt(false) < j._to_txt(false); + return i.to_txt() < j.to_txt(); }); // rule w | w = w @@ -762,7 +762,7 @@ Regex* Regex::to_aci(std::vector& res) { if (i == j) continue; - if (res[i]._to_txt(false) == res[j]._to_txt(false)) { + if (res[i].to_txt() == res[j].to_txt()) { res.erase(res.begin() + j); } } @@ -1050,7 +1050,7 @@ FiniteAutomaton Regex::to_antimirov(iLogTemplate* log) const { } fa_states.push_back(*this); - check.insert(_to_txt(true)); + check.insert(to_txt()); for (size_t i = 0; i < fa_states.size(); i++) { Regex regex_state = fa_states[i]; for (const auto& s : symbols) { @@ -1060,7 +1060,7 @@ FiniteAutomaton Regex::to_antimirov(iLogTemplate* log) const { for (const auto& reg_der : regs_der) { partial_derivatives_by_regex.push_back({regex_state, reg_der, s}); size_t old_checks = check.size(); - check.insert(reg_der._to_txt(true)); + check.insert(reg_der.to_txt()); if (old_checks != check.size()) { fa_states.push_back(reg_der); } @@ -1071,7 +1071,7 @@ FiniteAutomaton Regex::to_antimirov(iLogTemplate* log) const { vector name_states; for (auto& state : fa_states) { - name_states.push_back(state._to_txt(true)); + name_states.push_back(state.to_txt()); } vector automat_state; @@ -1085,20 +1085,20 @@ FiniteAutomaton Regex::to_antimirov(iLogTemplate* log) const { // cout << partial_derivativ[0].to_txt() << " "; // cout << partial_derivativ[1].to_txt() << " "; // cout << partial_derivativ[2].to_txt() << endl; - deriv_log += partial_derivativ[2]._to_txt(true) + "(" + - partial_derivativ[0]._to_txt(true) + ")" + "\\ =\\ "; + deriv_log += partial_derivativ[2].to_txt() + "(" + + partial_derivativ[0].to_txt() + ")" + "\\ =\\ "; if (partial_derivativ[1].to_txt() == "") { deriv_log += "eps\\\\"; } else { - deriv_log += partial_derivativ[1]._to_txt(true) + "\\\\"; + deriv_log += partial_derivativ[1].to_txt() + "\\\\"; } - if (partial_derivativ[0]._to_txt(true) == state) { + if (partial_derivativ[0].to_txt() == state) { // поиск индекс состояния в которое переходим по символу из state auto elem_iter = find( - name_states.begin(), name_states.end(), partial_derivativ[1]._to_txt(true)); + name_states.begin(), name_states.end(), partial_derivativ[1].to_txt()); // записываем расстояние между begin и итератором, который указывает на состояние - transit[partial_derivativ[2]._to_txt(true)].insert( + transit[partial_derivativ[2].to_txt()].insert( std::distance(name_states.begin(), elem_iter)); } }