diff --git a/alib2/src/automaton/PDA/PDA.cpp b/alib2/src/automaton/PDA/PDA.cpp index 87969dbb7bc8fead6dd79d1f49fd4633141235c3..80cc0edc1a26aeb42fcc1730e39e6b3e7d483aa5 100644 --- a/alib2/src/automaton/PDA/PDA.cpp +++ b/alib2/src/automaton/PDA/PDA.cpp @@ -139,7 +139,6 @@ const std::map<std::tuple<State, std::variant<string::Epsilon, alphabet::Symbol> } void PDA::addInitialSymbol(const alphabet::Symbol& start) { - if (stackAlphabet.find(start) == stackAlphabet.end()) { throw AutomatonException("Stack symbol \"" + start.getSymbol() + "\" doesn't exist."); } @@ -151,10 +150,22 @@ void PDA::addInitialSymbol(const alphabet::Symbol& start) { } void PDA::removeInitialSymbol(const alphabet::Symbol& start) { + if(this->initialSymbols.size() <= 1) + throw AutomatonException("There must be at least one initial symbol"); int removed = this->initialSymbols.erase(start); - if (!removed) { + if (!removed) throw AutomatonException("Transition doesn't exist."); - } +} + +void PDA::setInitialSymbols(const std::set<alphabet::Symbol>& symbols) { + if(symbols.size() < 1) + throw AutomatonException("There must be at least one initial symbol"); + std::set<alphabet::Symbol> tmp(symbols); + tmp.erase(this->stackAlphabet.begin(), this->stackAlphabet.end()); + if(tmp.size() != 0) + throw AutomatonException("Initial symbols not in stack alphabet"); + + this->initialSymbols = symbols; } const std::set<alphabet::Symbol>& PDA::getInitialSymbols() const { diff --git a/alib2/src/automaton/PDA/PDA.h b/alib2/src/automaton/PDA/PDA.h index 74b29987460122b8149e1aeef3b9e14d025b67ad..e767112b4c10a886350659d0de46e49f542fee9f 100644 --- a/alib2/src/automaton/PDA/PDA.h +++ b/alib2/src/automaton/PDA/PDA.h @@ -97,9 +97,17 @@ public: * Adds initial symbol. Initial symbols are symbols that are pushed * to the stack when PDA is created. * @param start new initial symbol - * @throws AutomatonException when symbol is not present in the stack alphabet or it is not present in the set + * @throws AutomatonException when symbol is not present in the set of initial symbols */ void removeInitialSymbol(const alphabet::Symbol& start); + + /** + * Sets initial symbols. Initial symbols are symbols that are pushed + * to the stack when PDA is created. + * @param symbols new initial symbols + * @throws AutomatonException when any of symbols is not present in the stack alphabet + */ + void setInitialSymbols(const std::set<alphabet::Symbol>& symbols); /** * @return list of start symbols