Skip to content

Commit

Permalink
(#301) Избавился от мусора/
Browse files Browse the repository at this point in the history
  • Loading branch information
dak151449 committed Jan 26, 2024
1 parent a09a66f commit 2b84960
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
3 changes: 0 additions & 3 deletions libs/Objects/include/Objects/AlgExpression.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 2 additions & 9 deletions libs/Objects/src/AlgExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 = '|';
Expand Down
22 changes: 11 additions & 11 deletions libs/Objects/src/Regex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ Regex* Regex::add_alt(std::vector<Regex> res, Regex* root) {
Regex* Regex::to_aci(std::vector<Regex>& 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
Expand All @@ -762,7 +762,7 @@ Regex* Regex::to_aci(std::vector<Regex>& 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);
}
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand All @@ -1071,7 +1071,7 @@ FiniteAutomaton Regex::to_antimirov(iLogTemplate* log) const {
vector<string> name_states;

for (auto& state : fa_states) {
name_states.push_back(state._to_txt(true));
name_states.push_back(state.to_txt());
}

vector<FAState> automat_state;
Expand All @@ -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));
}
}
Expand Down

0 comments on commit 2b84960

Please sign in to comment.