Skip to content

Commit

Permalink
(#350) Исправление deannote
Browse files Browse the repository at this point in the history
Только для регулярок. Для автоматов ещё нужно пропустить символы на переходах через update_epsilons, чтобы убить линеаризованные эпсилоны.
  • Loading branch information
TonitaN committed Jun 10, 2024
1 parent bbee011 commit 4eea279
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
1 change: 1 addition & 0 deletions libs/Objects/include/Objects/Regex.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Regex : public AlgExpression {
Regex* expr(const std::vector<Lexeme>&, int, int) override;
Regex* scan_minus(const std::vector<Lexeme>&, int, int);

Regex update_epsilons() const;
bool equals(const AlgExpression* other) const override;

// Множество префиксов длины len
Expand Down
52 changes: 42 additions & 10 deletions libs/Objects/src/Regex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ Regex::Regex(const string& str) {
}

Regex::Regex(const Symbol& s) {
if (s.is_epsilon())
{type = Type::eps;
}
else
{type = Type::symb;
symbol = s;
alphabet = {s};
}
if (s.is_epsilon()) {
type = Type::eps;
}
else {
type = Type::symb;
symbol = s;
alphabet = {s};
}
}

Regex::Regex(const string& str, const std::shared_ptr<Language>& new_language) : Regex(str) {
Expand Down Expand Up @@ -1167,6 +1167,37 @@ FiniteAutomaton Regex::to_antimirov(iLogTemplate* log) const {
return fa;
}

Regex Regex::update_epsilons() const {
Regex result;
Symbol s;
switch (type) {
case Type::eps:
result.type = Type::eps;
break;
case Type::symb:
s = Symbol(symbol);
s.delinearize();
if (s.is_epsilon()) {
result.type = Type::eps;
break;
}
else {
result = Regex(symbol);
break;
}
default:
Regex r1 = *Regex::cast(term_l);
if (term_r!=nullptr) {
Regex r2 = *Regex::cast(term_r);
result = Regex(type, &r1.update_epsilons(), &r2.update_epsilons());
} else
result = Regex(type, &r1.update_epsilons(), nullptr);

}
return result;
}


Regex Regex::deannote(iLogTemplate* log) const {
Regex temp_copy(*this);
vector<Regex*> list = Regex::cast(temp_copy.preorder_traversal());
Expand All @@ -1177,11 +1208,12 @@ Regex Regex::deannote(iLogTemplate* log) const {
deannoted_alphabet.insert(i->symbol);
}
temp_copy.set_language(deannoted_alphabet);
Regex ttt = temp_copy.update_epsilons();
if (log) {
log->set_parameter("oldregex", *this);
log->set_parameter("result", temp_copy);
log->set_parameter("result", ttt);
}
return temp_copy;
return ttt;
}

bool Regex::is_one_unambiguous(iLogTemplate* log) const {
Expand Down

0 comments on commit 4eea279

Please sign in to comment.