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

Unknown automaton as a holder for any automaton

parent 720af47b
No related branches found
No related tags found
No related merge requests found
...@@ -28,7 +28,7 @@ protected: ...@@ -28,7 +28,7 @@ protected:
std::set<State> initialStates; std::set<State> initialStates;
std::set<State> finalStates; std::set<State> finalStates;
public: public:
virtual ~Automaton(); virtual ~Automaton() noexcept;
   
/** /**
* Adds new state to the automaton. * Adds new state to the automaton.
...@@ -50,6 +50,7 @@ public: ...@@ -50,6 +50,7 @@ public:
*/ */
const std::set<State>& getStates() const; const std::set<State>& getStates() const;
   
/** /**
* Adds input symbol to input alphabet. * Adds input symbol to input alphabet.
* @param symbol Symbol to add * @param symbol Symbol to add
...@@ -70,6 +71,7 @@ public: ...@@ -70,6 +71,7 @@ public:
*/ */
const std::set<alphabet::Symbol>& getInputAlphabet() const; const std::set<alphabet::Symbol>& getInputAlphabet() const;
   
/** /**
* Adds the State to the initial states. * Adds the State to the initial states.
* @param state State to add * @param state State to add
......
...@@ -19,19 +19,31 @@ UnknownAutomaton::UnknownAutomaton() : ...@@ -19,19 +19,31 @@ UnknownAutomaton::UnknownAutomaton() :
UnknownAutomaton::~UnknownAutomaton() { UnknownAutomaton::~UnknownAutomaton() {
} }
   
void UnknownAutomaton::setStates(const std::set<State>& states) {
this->states = states;
}
void UnknownAutomaton::removeState(const State& state) { void UnknownAutomaton::removeState(const State& state) {
if (!states.erase(state)) if (!states.erase(state))
throw AutomatonException("State \"" + state.getName() + "\" doesn't exist."); throw AutomatonException("State \"" + state.getName() + "\" doesn't exist.");
} }
   
void UnknownAutomaton::addInputSymbol(const alphabet::Symbol& symbol) {
if (!inputAlphabet.insert(symbol).second) {
throw AutomatonException("Input symbol \"" + symbol.getSymbol() + "\" already exists.");
}
}
void UnknownAutomaton::setInputSymbols(const std::set<alphabet::Symbol>& symbols) {
this->inputAlphabet = symbols;
}
void UnknownAutomaton::removeInputSymbol(const alphabet::Symbol& symbol) { void UnknownAutomaton::removeInputSymbol(const alphabet::Symbol& symbol) {
if (!inputAlphabet.erase(symbol)) if (!inputAlphabet.erase(symbol))
throw AutomatonException("Input symbol \"" + symbol.getSymbol() + "\" doesn't exist."); throw AutomatonException("Input symbol \"" + symbol.getSymbol() + "\" doesn't exist.");
} }
   
const std::set<alphabet::Symbol>& UnknownAutomaton::getStackAlphabet() const {
return stackAlphabet;
}
   
void UnknownAutomaton::addStackSymbol(const alphabet::Symbol& symbol) { void UnknownAutomaton::addStackSymbol(const alphabet::Symbol& symbol) {
if (!stackAlphabet.insert(symbol).second) { if (!stackAlphabet.insert(symbol).second) {
...@@ -39,29 +51,50 @@ void UnknownAutomaton::addStackSymbol(const alphabet::Symbol& symbol) { ...@@ -39,29 +51,50 @@ void UnknownAutomaton::addStackSymbol(const alphabet::Symbol& symbol) {
} }
} }
   
void UnknownAutomaton::setStackSymbols(const std::set<alphabet::Symbol>& symbols) {
stackAlphabet = symbols;
}
void UnknownAutomaton::removeStackSymbol(const alphabet::Symbol& symbol) { void UnknownAutomaton::removeStackSymbol(const alphabet::Symbol& symbol) {
if (!stackAlphabet.erase(symbol)) if (!stackAlphabet.erase(symbol))
throw AutomatonException("Stack symbol \"" + symbol.getSymbol() + "\" doesn't exist."); throw AutomatonException("Stack symbol \"" + symbol.getSymbol() + "\" doesn't exist.");
} }
   
const std::set<alphabet::Symbol>& UnknownAutomaton::getInitialSymbols() const { const std::set<alphabet::Symbol>& UnknownAutomaton::getStackAlphabet() const {
return initialSymbols; return stackAlphabet;
}
void UnknownAutomaton::addInitialSymbol(const alphabet::Symbol& symbol) {
if (!stackAlphabet.insert(symbol).second) {
throw AutomatonException("Stack symbol \"" + symbol.getSymbol() + "\" already exists.");
}
} }
   
void UnknownAutomaton::setInitialSymbols(const std::set<alphabet::Symbol>& symbols) { void UnknownAutomaton::setInitialSymbols(const std::set<alphabet::Symbol>& symbols) {
this->initialSymbols = symbols; this->initialSymbols = symbols;
} }
   
const std::set<alphabet::Symbol>& UnknownAutomaton::getTapeAlphabet() const { void UnknownAutomaton::removeInitialSymbol(const alphabet::Symbol& symbol) {
return tapeAlphabet; if (!stackAlphabet.erase(symbol))
throw AutomatonException("Stack symbol \"" + symbol.getSymbol() + "\" doesn't exist.");
}
const std::set<alphabet::Symbol>& UnknownAutomaton::getInitialSymbols() const {
return initialSymbols;
} }
   
void UnknownAutomaton::addTapeSymbol(const alphabet::Symbol& symbol) { void UnknownAutomaton::addTapeSymbol(const alphabet::Symbol& symbol) {
if (!tapeAlphabet.insert(symbol).second) { if (!tapeAlphabet.insert(symbol).second) {
throw AutomatonException("Tape symbol \"" + symbol.getSymbol() + "\" already exists."); throw AutomatonException("Tape symbol \"" + symbol.getSymbol() + "\" already exists.");
} }
} }
   
void UnknownAutomaton::setTapeAlphabet(const std::set<alphabet::Symbol>& symbols) {
tapeAlphabet = symbols;
}
void UnknownAutomaton::removeTapeSymbol(const alphabet::Symbol& symbol) { void UnknownAutomaton::removeTapeSymbol(const alphabet::Symbol& symbol) {
int removed = tapeAlphabet.erase(symbol); int removed = tapeAlphabet.erase(symbol);
if (!removed) { if (!removed) {
...@@ -69,18 +102,20 @@ void UnknownAutomaton::removeTapeSymbol(const alphabet::Symbol& symbol) { ...@@ -69,18 +102,20 @@ void UnknownAutomaton::removeTapeSymbol(const alphabet::Symbol& symbol) {
} }
} }
   
const alphabet::Symbol& UnknownAutomaton::getBlankSymbol() const { const std::set<alphabet::Symbol>& UnknownAutomaton::getTapeAlphabet() const {
return blankSymbol; return tapeAlphabet;
} }
   
void UnknownAutomaton::setBlankSymbol(const alphabet::Symbol& symbol) { void UnknownAutomaton::setBlankSymbol(const alphabet::Symbol& symbol) {
blankSymbol = symbol; blankSymbol = symbol;
} }
   
const std::set<UnknownTransition>& UnknownAutomaton::getTransitions() const { const alphabet::Symbol& UnknownAutomaton::getBlankSymbol() const {
return transitions; return blankSymbol;
} }
   
void UnknownAutomaton::addTransition(const UnknownTransition& transition) { void UnknownAutomaton::addTransition(const UnknownTransition& transition) {
if (!transitions.insert(transition).second) { if (!transitions.insert(transition).second) {
throw AutomatonException("Transition already exists."); throw AutomatonException("Transition already exists.");
...@@ -93,4 +128,9 @@ void UnknownAutomaton::removeTransition(const UnknownTransition& transition) { ...@@ -93,4 +128,9 @@ void UnknownAutomaton::removeTransition(const UnknownTransition& transition) {
} }
} }
   
const std::set<UnknownTransition>& UnknownAutomaton::getTransitions() const {
return transitions;
}
} /* namespace automaton */ } /* namespace automaton */
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
* Author: Martin Zak * Author: Martin Zak
*/ */
   
#ifndef UNKNOWNAUTOMATON_H_ #ifndef UNKNOWN_AUTOMATON_H_
#define UNKNOWNAUTOMATON_H_ #define UNKNOWN_AUTOMATON_H_
   
#include <set> #include <set>
#include <list> #include <list>
...@@ -33,6 +33,12 @@ public: ...@@ -33,6 +33,12 @@ public:
UnknownAutomaton(); UnknownAutomaton();
virtual ~UnknownAutomaton(); virtual ~UnknownAutomaton();
   
/**
* Set new states of the automaton.
* @param states New states of the automaton
*/
void setStates(const std::set<State>& states);
/** /**
* Removes the state from the automaton. * Removes the state from the automaton.
* @param state State to remove * @param state State to remove
...@@ -40,6 +46,20 @@ public: ...@@ -40,6 +46,20 @@ public:
*/ */
void removeState(const State& state); void removeState(const State& state);
   
/**
* Adds the input symbol to the automaton.
* @param symbol Symbol to add
* @throws AutomatonException when symbol is already present in the automaton
*/
void addInputSymbol(const alphabet::Symbol& symbol);
/**
* Sets the input symbols of the automaton.
* @param symbols Symbol to be new input symbol of the automaton
*/
void setInputSymbols(const std::set<alphabet::Symbol>& symbols);
/** /**
* Removes input symbol from the input alphabet. * Removes input symbol from the input alphabet.
* @param symbol Symbol to remove * @param symbol Symbol to remove
...@@ -47,10 +67,6 @@ public: ...@@ -47,10 +67,6 @@ public:
*/ */
void removeInputSymbol(const alphabet::Symbol& symbol); void removeInputSymbol(const alphabet::Symbol& symbol);
   
/**
* @return the stack alphabet
*/
const std::set<alphabet::Symbol>& getStackAlphabet() const;
   
/** /**
* Adds symbol to the stack alphabet. * Adds symbol to the stack alphabet.
...@@ -59,6 +75,12 @@ public: ...@@ -59,6 +75,12 @@ public:
*/ */
void addStackSymbol(const alphabet::Symbol& symbol); void addStackSymbol(const alphabet::Symbol& symbol);
   
/**
* Sets symbols of the stack alphabet.
* @param symbol Symbol to add
*/
void setStackSymbols(const std::set<alphabet::Symbol>& symbols);
/** /**
* Removes symbol from the stack alphabet. * Removes symbol from the stack alphabet.
* @param symbol Symbol to remove * @param symbol Symbol to remove
...@@ -67,9 +89,17 @@ public: ...@@ -67,9 +89,17 @@ public:
void removeStackSymbol(const alphabet::Symbol& symbol); void removeStackSymbol(const alphabet::Symbol& symbol);
   
/** /**
* @return list of initial symbols * @return the stack alphabet
*/ */
const std::set<alphabet::Symbol>& getInitialSymbols() const; const std::set<alphabet::Symbol>& getStackAlphabet() const;
/**
* Adds symbol to the set of initial stack symbols.
* @param symbol Symbol to add
* @throw AutomatonException when Symbol is already present in the set of initial symbols
*/
void addInitialSymbol(const alphabet::Symbol& symbol);
   
/** /**
* Set the initial symbol list. * Set the initial symbol list.
...@@ -78,9 +108,17 @@ public: ...@@ -78,9 +108,17 @@ public:
void setInitialSymbols(const std::set<alphabet::Symbol>& symbols); void setInitialSymbols(const std::set<alphabet::Symbol>& symbols);
   
/** /**
* @return the tape alphabet * Removes symbol from the set of initial stack symbols.
* @param symbol Symbol to remove
* @throw AutomatonException when Symbol is not present in the set of initial symbols
*/ */
const std::set<alphabet::Symbol>& getTapeAlphabet() const; void removeInitialSymbol(const alphabet::Symbol& symbol);
/**
* @return list of initial symbols
*/
const std::set<alphabet::Symbol>& getInitialSymbols() const;
   
/** /**
* Adds symbol to the tape alphabet. * Adds symbol to the tape alphabet.
...@@ -89,6 +127,12 @@ public: ...@@ -89,6 +127,12 @@ public:
*/ */
void addTapeSymbol(const alphabet::Symbol& symbol); void addTapeSymbol(const alphabet::Symbol& symbol);
   
/**
* Sets the tape alphabet.
* @param symbols Symbols to become new tape alphabet
*/
void setTapeAlphabet(const std::set<alphabet::Symbol>& symbols);
/** /**
* Removes symbol from the tape alphabet. * Removes symbol from the tape alphabet.
* @param symbol Symbol to remove * @param symbol Symbol to remove
...@@ -97,9 +141,10 @@ public: ...@@ -97,9 +141,10 @@ public:
void removeTapeSymbol(const alphabet::Symbol& symbol); void removeTapeSymbol(const alphabet::Symbol& symbol);
   
/** /**
* @return the blank symbol * @return the tape alphabet
*/ */
const alphabet::Symbol& getBlankSymbol() const; const std::set<alphabet::Symbol>& getTapeAlphabet() const;
   
/** /**
* Sets the blank symbol. * Sets the blank symbol.
...@@ -108,9 +153,10 @@ public: ...@@ -108,9 +153,10 @@ public:
void setBlankSymbol(const alphabet::Symbol& symbol); void setBlankSymbol(const alphabet::Symbol& symbol);
   
/** /**
* @return transitions of the automaton * @return the blank symbol
*/ */
const std::set<UnknownTransition>& getTransitions() const; const alphabet::Symbol& getBlankSymbol() const;
   
/** /**
* Adds new transition to the automaton. * Adds new transition to the automaton.
...@@ -126,7 +172,13 @@ public: ...@@ -126,7 +172,13 @@ public:
*/ */
void removeTransition(const UnknownTransition& transition); void removeTransition(const UnknownTransition& transition);
   
/**
* @return transitions of the automaton
*/
const std::set<UnknownTransition>& getTransitions() const;
}; };
   
} /* namespace automaton */ } /* namespace automaton */
#endif /* UNKNOWNAUTOMATON_H_ */
#endif /* UNKNOWN_AUTOMATON_H_ */
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