From 73bbf73a35829b214487786da93be4ef1216ef28 Mon Sep 17 00:00:00 2001 From: Martin Zak <zakmart1@fit.cvut.cz> Date: Tue, 5 Nov 2013 19:57:45 +0100 Subject: [PATCH] Renames 'current' state in Transitions to 'from' and 'next' to 'to' --- aconvert/src/DotConverter.cpp | 6 ++-- alib/src/AutomatonFactory.cpp | 6 ++-- alib/src/automaton/AutomatonParser.cpp | 4 +-- alib/src/automaton/FSM/FSM.cpp | 8 ++--- alib/src/automaton/FSM/TransitionFSM.cpp | 16 ++++----- alib/src/automaton/FSM/TransitionFSM.h | 2 +- alib/src/automaton/PDA/PDA.cpp | 10 +++--- alib/src/automaton/PDA/TransitionPDA.cpp | 42 ++++++++++++------------ alib/src/automaton/PDA/TransitionPDA.h | 20 +++++------ alib/src/automaton/TM/TM.cpp | 10 +++--- alib/src/automaton/TM/TransitionTM.cpp | 18 +++++----- alib/src/automaton/TM/TransitionTM.h | 6 ++-- alib/src/automaton/Transition.cpp | 20 +++++------ alib/src/automaton/Transition.h | 12 +++---- alib/src/automaton/UnknownTransition.cpp | 10 +++--- 15 files changed, 96 insertions(+), 94 deletions(-) diff --git a/aconvert/src/DotConverter.cpp b/aconvert/src/DotConverter.cpp index d30035e88a..d5bf21a5d4 100644 --- a/aconvert/src/DotConverter.cpp +++ b/aconvert/src/DotConverter.cpp @@ -92,7 +92,7 @@ void DotConverter::transitions(const automaton::FSM& fsm, const std::map<automat symbol = it->getInput().getSymbol(); } - pair<int, int> key(states.find(it->getCurrent())->second, states.find(it->getNext())->second); + pair<int, int> key(states.find(it->getFrom())->second, states.find(it->getTo())->second); map<pair<int, int>, string>::iterator mapit = transitions.find(key); if (mapit == transitions.end()) { @@ -154,7 +154,7 @@ void DotConverter::transitions(const automaton::PDA& pda, const std::map<automat } //Insert into map - pair<int, int> key(states.find(it->getCurrent())->second, states.find(it->getNext())->second); + pair<int, int> key(states.find(it->getFrom())->second, states.find(it->getTo())->second); map<pair<int, int>, string>::iterator mapit = transitions.find(key); if (mapit == transitions.end()) { @@ -193,7 +193,7 @@ void DotConverter::transitions(const automaton::TM& tm, const std::map<automaton symbol += (std::string[] ) { "←", "→", "×" } [it->getShift()]; //Insert into map - pair<int, int> key(states.find(it->getCurrent())->second, states.find(it->getNext())->second); + pair<int, int> key(states.find(it->getFrom())->second, states.find(it->getTo())->second); map<pair<int, int>, string>::iterator mapit = transitions.find(key); if (mapit == transitions.end()) { diff --git a/alib/src/AutomatonFactory.cpp b/alib/src/AutomatonFactory.cpp index d8f9ed5ace..1a444857bd 100644 --- a/alib/src/AutomatonFactory.cpp +++ b/alib/src/AutomatonFactory.cpp @@ -114,7 +114,7 @@ FSM AutomatonFactory::buildFSM(UnknownAutomaton* automaton) { const set<UnknownTransition> transitions = automaton->getTransitions(); set<UnknownTransition>::const_iterator transition = transitions.begin(); while (transition != transitions.end()) { - fsm.addTransition(transition->getCurrent(), transition->getInput(), transition->getNext()); + fsm.addTransition(transition->getFrom(), transition->getInput(), transition->getTo()); transition++; } @@ -159,7 +159,7 @@ PDA AutomatonFactory::buildPDA(UnknownAutomaton* automaton) { set<UnknownTransition>::const_iterator transition = transitions.begin(); while (transition != transitions.end()) { - TransitionPDA tr(transition->getCurrent(), transition->getInput(), transition->getNext(), transition->getPop(), + TransitionPDA tr(transition->getFrom(), transition->getInput(), transition->getTo(), transition->getPop(), transition->getPush()); pda.addTransition(tr); transition++; @@ -211,7 +211,7 @@ TM AutomatonFactory::buildTM(UnknownAutomaton* automaton) { set<UnknownTransition>::const_iterator transition = transitions.begin(); while (transition != transitions.end()) { - TransitionTM tr(transition->getCurrent(), transition->getInput(), transition->getNext(), + TransitionTM tr(transition->getFrom(), transition->getInput(), transition->getTo(), transition->getOutput(), transition->getShift()); tm.addTransition(tr); transition++; diff --git a/alib/src/automaton/AutomatonParser.cpp b/alib/src/automaton/AutomatonParser.cpp index 00ddf2398d..4760c4b7b9 100644 --- a/alib/src/automaton/AutomatonParser.cpp +++ b/alib/src/automaton/AutomatonParser.cpp @@ -207,11 +207,11 @@ UnknownTransition AutomatonParser::parseTransition(list<Token>& input) { if (isToken(input, Token::END_ELEMENT, "transition")) { break; } else if (isToken(input, Token::START_ELEMENT, "current")) { - transition.setCurrent(parseState(input, "current")); + transition.setFrom(parseState(input, "current")); } else if (isToken(input, Token::START_ELEMENT, "input")) { transition.setInput(parseSymbol(input, "input")); } else if (isToken(input, Token::START_ELEMENT, "next")) { - transition.setNext(parseState(input, "next")); + transition.setTo(parseState(input, "next")); } else if (isToken(input, Token::START_ELEMENT, "pop")) { parsePop(input, &transition); } else if (isToken(input, Token::START_ELEMENT, "push")) { diff --git a/alib/src/automaton/FSM/FSM.cpp b/alib/src/automaton/FSM/FSM.cpp index 39be0ba888..a5b55a8de0 100644 --- a/alib/src/automaton/FSM/FSM.cpp +++ b/alib/src/automaton/FSM/FSM.cpp @@ -33,7 +33,7 @@ void FSM::removeState(const State& state) { } for (set<TransitionFSM>::const_iterator t = transitions.begin(); t != transitions.end(); t++) { - if (state == t->getCurrent() || state == t->getNext()) + if (state == t->getFrom() || state == t->getTo()) throw AutomatonException("State \"" + state.getName() + "\" is used in transition."); } @@ -75,15 +75,15 @@ void FSM::addTransition(const State& current, const Symbol& input, const State& } void FSM::addTransition(const TransitionFSM& transition) { - addTransition(transition.getCurrent(), transition.getInput(), transition.getNext()); + addTransition(transition.getFrom(), transition.getInput(), transition.getTo()); } void FSM::removeTransition(const TransitionFSM& transition) { int removed = transitions.erase(transition); if (!removed) throw AutomatonException( - "Transition (\"" + transition.getCurrent().getName() + "\", \"" + transition.getInput().getSymbol() - + "\") -> \"" + transition.getNext().getName() + "\" doesn't exist."); + "Transition (\"" + transition.getFrom().getName() + "\", \"" + transition.getInput().getSymbol() + + "\") -> \"" + transition.getTo().getName() + "\" doesn't exist."); } diff --git a/alib/src/automaton/FSM/TransitionFSM.cpp b/alib/src/automaton/FSM/TransitionFSM.cpp index d56c4ce052..d34b02cd42 100644 --- a/alib/src/automaton/FSM/TransitionFSM.cpp +++ b/alib/src/automaton/FSM/TransitionFSM.cpp @@ -8,36 +8,36 @@ #include "TransitionFSM.h" namespace automaton { -TransitionFSM::TransitionFSM(const State& current,const Symbol& input,const State& next) : Transition(current, input, next) { +TransitionFSM::TransitionFSM(const State& from,const Symbol& input,const State& to) : Transition(from, input, to) { } bool TransitionFSM::operator < (const TransitionFSM& other) const { - if(current != other.current) { - return current < other.current; + if(from != other.from) { + return from < other.from; } else if(input != other.input) { return input < other.input; } else { - return next < other.next; + return to < other.to; } } bool TransitionFSM::operator == (const TransitionFSM& other) const { - return current == other.current && input == other.input && next == other.next; + return from == other.from && input == other.input && to == other.to; } bool TransitionFSM::operator != (const TransitionFSM& other) const { - return current != other.current || input != other.input || next != other.next; + return from != other.from || input != other.input || to != other.to; } void TransitionFSM::toXML(std::ostream& out, const std::string& indent) const { out << indent << "<transition>\n"; - out << indent << "\t" << "<current>" << current.getName() << "</current>\n"; + out << indent << "\t" << "<current>" << from.getName() << "</current>\n"; if(input.getSymbol() == "") { out << indent << "\t" << "<input>" << "<eps/>" << "</input>\n"; } else { out << indent << "\t" << "<input>" << input.getSymbol() << "</input>\n"; } - out << indent << "\t" << "<next>" << next.getName() << "</next>\n"; + out << indent << "\t" << "<next>" << to.getName() << "</next>\n"; out << indent << "</transition>\n"; } diff --git a/alib/src/automaton/FSM/TransitionFSM.h b/alib/src/automaton/FSM/TransitionFSM.h index f8b69d88a0..d9dd3517e1 100644 --- a/alib/src/automaton/FSM/TransitionFSM.h +++ b/alib/src/automaton/FSM/TransitionFSM.h @@ -15,7 +15,7 @@ namespace automaton { class TransitionFSM : public Transition { public: - TransitionFSM(const State& current,const Symbol& input,const State& next); + TransitionFSM(const State& from,const Symbol& input,const State& to); bool operator <(const TransitionFSM& other) const; bool operator ==(const TransitionFSM& other) const; diff --git a/alib/src/automaton/PDA/PDA.cpp b/alib/src/automaton/PDA/PDA.cpp index 30d2228b88..8227670102 100644 --- a/alib/src/automaton/PDA/PDA.cpp +++ b/alib/src/automaton/PDA/PDA.cpp @@ -32,7 +32,7 @@ void PDA::removeState(const State& state) { } for (set<TransitionPDA>::const_iterator t = transitions.begin(); t != transitions.end(); t++) { - if (state == t->getCurrent() || state == t->getNext()) + if (state == t->getFrom() || state == t->getTo()) throw AutomatonException("State \"" + state.getName() + "\" is used in transition."); } @@ -89,8 +89,8 @@ const set<Symbol>& PDA::getStackAlphabet() const { } void PDA::addTransition(const TransitionPDA& transition) { - if (states.find(transition.getCurrent()) == states.end()) { - throw AutomatonException("State \"" + transition.getCurrent().getName() + "\" doesn't exist."); + if (states.find(transition.getFrom()) == states.end()) { + throw AutomatonException("State \"" + transition.getFrom().getName() + "\" doesn't exist."); } if (transition.getInput().getSymbol().compare("") != 0) { @@ -99,8 +99,8 @@ void PDA::addTransition(const TransitionPDA& transition) { } } - if (states.find(transition.getNext()) == states.end()) { - throw AutomatonException("State \"" + transition.getCurrent().getName() + "\" doesn't exist."); + if (states.find(transition.getTo()) == states.end()) { + throw AutomatonException("State \"" + transition.getFrom().getName() + "\" doesn't exist."); } list<Symbol>::const_iterator popSymbol = transition.getPop().begin(); diff --git a/alib/src/automaton/PDA/TransitionPDA.cpp b/alib/src/automaton/PDA/TransitionPDA.cpp index 58985efa37..10779064b4 100644 --- a/alib/src/automaton/PDA/TransitionPDA.cpp +++ b/alib/src/automaton/PDA/TransitionPDA.cpp @@ -9,43 +9,43 @@ namespace automaton { -TransitionPDA::TransitionPDA(const State& current, const Symbol& input, const State& next) : Transition(current, input, next){ +TransitionPDA::TransitionPDA(const State& from, const Symbol& input, const State& to) : Transition(from, input, to){ } -TransitionPDA::TransitionPDA(const State& current, const Symbol& input, const State& next, const std::list<Symbol>& pop, - const std::list<Symbol>& push) : - Transition(current, input, next), pop(pop), push(push) { +TransitionPDA::TransitionPDA(const State& from, const Symbol& input, const State& to, const list<Symbol>& pop, + const list<Symbol>& push) : + Transition(from, input, to), pop(pop), push(push) { } -void TransitionPDA::setPop(const std::list<Symbol>& pop) { +void TransitionPDA::setPop(const list<Symbol>& pop) { this->pop = pop; } -const std::list<Symbol>& TransitionPDA::getPop() const { +const list<Symbol>& TransitionPDA::getPop() const { return pop; } -void TransitionPDA::setPush(const std::list<Symbol>& push) { +void TransitionPDA::setPush(const list<Symbol>& push) { this->push = push; } -const std::list<Symbol>& TransitionPDA::getPush() const { +const list<Symbol>& TransitionPDA::getPush() const { return push; } bool TransitionPDA::operator <(const TransitionPDA& other) const { - if (current != other.current) { - return current < other.current; + if (from != other.from) { + return from < other.from; } else if (input != other.input) { return input < other.input; - } else if (next != next) { - return next < other.next; + } else if (to != to) { + return to < other.to; } - std::list<Symbol>::const_iterator it; - std::list<Symbol>::const_iterator it2; + list<Symbol>::const_iterator it; + list<Symbol>::const_iterator it2; //compare pop size if (pop.size() != other.pop.size()) @@ -79,7 +79,7 @@ bool TransitionPDA::operator <(const TransitionPDA& other) const { } bool TransitionPDA::operator ==(const TransitionPDA& other) const { - if (current == other.current && input == other.input && next == other.next) { + if (from == other.from && input == other.input && to == other.to) { //compare pop size if (pop.size() != other.pop.size()) @@ -88,8 +88,8 @@ bool TransitionPDA::operator ==(const TransitionPDA& other) const { if (push.size() != other.push.size()) return false; - std::list<Symbol>::const_iterator it; - std::list<Symbol>::const_iterator it2; + list<Symbol>::const_iterator it; + list<Symbol>::const_iterator it2; //compare pop content it = pop.begin(); @@ -120,18 +120,18 @@ bool TransitionPDA::operator !=(const TransitionPDA& other) const { return !((*this) == other); } -void TransitionPDA::toXML(std::ostream& out, const std::string& indent) const { +void TransitionPDA::toXML(ostream& out, const string& indent) const { out << indent << "<transition>\n"; - out << indent << "\t" << "<current>" << current.getName() << "</current>\n"; + out << indent << "\t" << "<current>" << from.getName() << "</current>\n"; if (input.getSymbol() == "") { out << indent << "\t" << "<input>" << "<eps/>" << "</input>\n"; } else { out << indent << "\t" << "<input>" << input.getSymbol() << "</input>\n"; } - out << indent << "\t" << "<next>" << next.getName() << "</next>\n"; + out << indent << "\t" << "<next>" << to.getName() << "</next>\n"; out << indent << "\t" << "<pop>\n"; - std::list<Symbol>::const_iterator it = pop.begin(); + list<Symbol>::const_iterator it = pop.begin(); while (it != pop.end()) { (*it).toXML(out, indent + "\t\t"); it++; diff --git a/alib/src/automaton/PDA/TransitionPDA.h b/alib/src/automaton/PDA/TransitionPDA.h index 957a784ce1..0fba5f3401 100644 --- a/alib/src/automaton/PDA/TransitionPDA.h +++ b/alib/src/automaton/PDA/TransitionPDA.h @@ -16,24 +16,24 @@ using namespace std; class TransitionPDA: public Transition { protected: - std::list<Symbol> pop; - std::list<Symbol> push; + list<Symbol> pop; + list<Symbol> push; public: - TransitionPDA(const State& current, const Symbol& input, const State& next); - TransitionPDA(const State& current, const Symbol& input, const State& next, const std::list<Symbol>& pop, - const std::list<Symbol>& push); + TransitionPDA(const State& from, const Symbol& input, const State& to); + TransitionPDA(const State& from, const Symbol& input, const State& to, const list<Symbol>& pop, + const list<Symbol>& push); - void setPop(const std::list<Symbol>& pop); - const std::list<Symbol>& getPop() const; - void setPush(const std::list<Symbol>& push); - const std::list<Symbol>& getPush() const; + void setPop(const list<Symbol>& pop); + const list<Symbol>& getPop() const; + void setPush(const list<Symbol>& push); + const list<Symbol>& getPush() const; bool operator <(const TransitionPDA& other) const; bool operator ==(const TransitionPDA& other) const; bool operator !=(const TransitionPDA& other) const; - virtual void toXML(std::ostream& out, const std::string& indent) const; + virtual void toXML(ostream& out, const string& indent) const; }; } /* namespace automaton */ diff --git a/alib/src/automaton/TM/TM.cpp b/alib/src/automaton/TM/TM.cpp index 3a97364cae..b5855f9cb2 100644 --- a/alib/src/automaton/TM/TM.cpp +++ b/alib/src/automaton/TM/TM.cpp @@ -46,7 +46,7 @@ void TM::removeState(const State& state) { } for (set<TransitionTM>::const_iterator t = transitions.begin(); t != transitions.end(); t++) { - if (state == t->getCurrent() || state == t->getNext()) + if (state == t->getFrom() || state == t->getTo()) throw AutomatonException("State \"" + state.getName() + "\" is used."); } @@ -90,16 +90,16 @@ const std::set<Symbol>& TM::getTapeSymbols() const { } void TM::addTransition(const TransitionTM& transition) { - if (states.find(transition.getCurrent()) == states.end()) { - throw AutomatonException("State \"" + transition.getCurrent().getName() + "\" doesn't exist."); + if (states.find(transition.getFrom()) == states.end()) { + throw AutomatonException("State \"" + transition.getFrom().getName() + "\" doesn't exist."); } if (tapeAlphabet.find(transition.getInput()) == tapeAlphabet.end()) { throw AutomatonException("Tape symbol \"" + transition.getInput().getSymbol() + "\" doesn't exist."); } - if (states.find(transition.getNext()) == states.end()) { - throw AutomatonException("State \"" + transition.getNext().getName() + "\" doesn't exist."); + if (states.find(transition.getTo()) == states.end()) { + throw AutomatonException("State \"" + transition.getTo().getName() + "\" doesn't exist."); } if (tapeAlphabet.find(transition.getOutput()) == tapeAlphabet.end()) { diff --git a/alib/src/automaton/TM/TransitionTM.cpp b/alib/src/automaton/TM/TransitionTM.cpp index 489d0265df..7f17802a0b 100644 --- a/alib/src/automaton/TM/TransitionTM.cpp +++ b/alib/src/automaton/TM/TransitionTM.cpp @@ -9,9 +9,9 @@ namespace automaton { -TransitionTM::TransitionTM(const State& current, const Symbol& input, const State& next, const Symbol& output, +TransitionTM::TransitionTM(const State& from, const Symbol& input, const State& to, const Symbol& output, Shift shift) : - Transition(current, input, next), output(output), shift(shift) { + Transition(from, input, to), output(output), shift(shift) { } const Symbol& TransitionTM::getOutput() const { @@ -28,12 +28,12 @@ void TransitionTM::setShift(Shift shift) { } bool TransitionTM::operator <(const TransitionTM& other) const { - if (current != other.current) { - return current < other.current; + if (from != other.from) { + return from < other.from; } else if (input != other.input) { return input < other.input; - } else if (next != next) { - return next < other.next; + } else if (to != to) { + return to < other.to; } else if (output != output) { return output < other.output; } else { @@ -42,7 +42,7 @@ bool TransitionTM::operator <(const TransitionTM& other) const { } bool TransitionTM::operator ==(const TransitionTM& other) const { - return current == other.current && input == other.input && next == other.next && output == other.output + return from == other.from && input == other.input && to == other.to && output == other.output && shift == other.shift; } bool TransitionTM::operator !=(const TransitionTM& other) const { @@ -51,13 +51,13 @@ bool TransitionTM::operator !=(const TransitionTM& other) const { void TransitionTM::toXML(std::ostream& out, const std::string& indent) const { out << indent << "<transition>\n"; - out << indent << "\t" << "<current>" << current.getName() << "</current>\n"; + out << indent << "\t" << "<current>" << from.getName() << "</current>\n"; if (input.getSymbol() == "") { out << indent << "\t" << "<input>" << "<eps/>" << "</input>\n"; } else { out << indent << "\t" << "<input>" << input.getSymbol() << "</input>\n"; } - out << indent << "\t" << "<next>" << next.getName() << "</next>\n"; + out << indent << "\t" << "<next>" << to.getName() << "</next>\n"; out << indent << "\t" << "<output>" << output.getSymbol() << "</output>\n"; out << indent << "\t" << "<shift>" << (std::string[]){"left","right","none"}[shift] << "</shift>\n"; out << indent << "</transition>\n"; diff --git a/alib/src/automaton/TM/TransitionTM.h b/alib/src/automaton/TM/TransitionTM.h index 54bd086fd2..7291f56ed5 100644 --- a/alib/src/automaton/TM/TransitionTM.h +++ b/alib/src/automaton/TM/TransitionTM.h @@ -13,12 +13,14 @@ namespace automaton { +using namespace std; + class TransitionTM: public Transition { protected: Symbol output; Shift shift; public: - TransitionTM(const State& current, const Symbol& input, const State& next, const Symbol& output, Shift shift); + TransitionTM(const State& from, const Symbol& input, const State& to, const Symbol& output, Shift shift); const Symbol& getOutput() const; void setOutput(const Symbol& output); @@ -29,7 +31,7 @@ public: bool operator ==(const TransitionTM& other) const; bool operator !=(const TransitionTM& other) const; - virtual void toXML(std::ostream& out, const std::string& indent) const; + virtual void toXML(ostream& out, const string& indent) const; }; } /* namespace automaton */ diff --git a/alib/src/automaton/Transition.cpp b/alib/src/automaton/Transition.cpp index 63db6379c1..48166b2337 100644 --- a/alib/src/automaton/Transition.cpp +++ b/alib/src/automaton/Transition.cpp @@ -10,18 +10,18 @@ namespace automaton { Transition::Transition(const State& current, const Symbol& input, const State& next) : - current(current), input(input), next(next) { + from(current), input(input), to(next) { } Transition::~Transition() { } -void Transition::setCurrent(const State& state) { - current = state; +void Transition::setFrom(const State& state) { + from = state; } -const State& Transition::getCurrent() const { - return current; +const State& Transition::getFrom() const { + return from; } void Transition::setInput(const Symbol& symbol) { input = symbol; @@ -30,16 +30,16 @@ void Transition::setInput(const Symbol& symbol) { const Symbol& Transition::getInput() const { return input; } -void Transition::setNext(const State& state) { - next = state; +void Transition::setTo(const State& state) { + to = state; } -const State& Transition::getNext() const { - return next; +const State& Transition::getTo() const { + return to; } bool Transition::containsState(const State& state) const { - return current == state || next == state; + return from == state || to == state; } } /* namespace automaton */ diff --git a/alib/src/automaton/Transition.h b/alib/src/automaton/Transition.h index 39d52b126f..031b328b6e 100644 --- a/alib/src/automaton/Transition.h +++ b/alib/src/automaton/Transition.h @@ -17,19 +17,19 @@ using namespace alphabet; class Transition { protected: - State current; + State from; Symbol input; - State next; + State to; public: Transition(const State& current, const Symbol& input, const State& next); virtual ~Transition(); - void setCurrent(const State& state); - const State& getCurrent() const; + void setFrom(const State& state); + const State& getFrom() const; void setInput(const Symbol& symbol); const Symbol& getInput() const; - void setNext(const State& state); - const State& getNext() const; + void setTo(const State& state); + const State& getTo() const; bool containsState(const State& state) const; diff --git a/alib/src/automaton/UnknownTransition.cpp b/alib/src/automaton/UnknownTransition.cpp index db69eb4d87..ea7582b4d7 100644 --- a/alib/src/automaton/UnknownTransition.cpp +++ b/alib/src/automaton/UnknownTransition.cpp @@ -49,12 +49,12 @@ void UnknownTransition::setShift(const Shift& shift) { } bool UnknownTransition::operator <(const UnknownTransition& other) const { - if (current != other.current) { - return current < other.current; + if (from != other.from) { + return from < other.from; } else if (input != other.input) { return input < other.input; - } else if (next != next) { - return next < other.next; + } else if (to != to) { + return to < other.to; } else if (output != output) { return output < other.output; } else if (shift != other.shift) { @@ -96,7 +96,7 @@ bool UnknownTransition::operator <(const UnknownTransition& other) const { } bool UnknownTransition::operator ==(const UnknownTransition& other) const { - if (current == other.current && input == other.input && next == other.next && output == other.output + if (from == other.from && input == other.input && to == other.to && output == other.output && shift == other.shift) { //compare pop size -- GitLab