Skip to content
Snippets Groups Projects
Commit 720af47b authored by Jan Trávníček's avatar Jan Trávníček
Browse files

method to set initial set of symbols at once

parent 1cfff42f
No related branches found
No related tags found
No related merge requests found
......@@ -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 {
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment