diff --git a/alib/src/alphabet/Symbol.cpp b/alib/src/alphabet/Symbol.cpp index c81332c3e5418fcca6a1edfa57db3f2cbc05a09b..c03d42d206922bd702909563243a0d4b43f15d88 100644 --- a/alib/src/alphabet/Symbol.cpp +++ b/alib/src/alphabet/Symbol.cpp @@ -29,4 +29,10 @@ bool Symbol::operator !=(const Symbol& other) const { return symbol != other.symbol; } +std::ostream& operator<<(std::ostream& out, const Symbol& symbol) { + + out << "Symbol " << (symbol.symbol == "" ? "\\epsilon" : symbol.symbol); + return out; +} + } /* namespace language */ diff --git a/alib/src/alphabet/Symbol.h b/alib/src/alphabet/Symbol.h index 1d2f01faebcd7cd02577e9ac5d319f46d97f6548..a49c107b604ed648cd30b9a99b6a7b5cae9451a0 100644 --- a/alib/src/alphabet/Symbol.h +++ b/alib/src/alphabet/Symbol.h @@ -34,6 +34,8 @@ public: bool operator <(const Symbol& other) const; bool operator ==(const Symbol& other) const; bool operator !=(const Symbol& other) const; + + friend std::ostream& operator<<(std::ostream&, const Symbol&); }; } #endif /* SYMBOL_H_ */ diff --git a/alib/src/automaton/FSM/TransitionFSM.cpp b/alib/src/automaton/FSM/TransitionFSM.cpp index 950496a9559d74d2e36ad24ee48726e9895487dd..fff1c43a7b9908184e9ab29dfcd494d3a6a8b371 100644 --- a/alib/src/automaton/FSM/TransitionFSM.cpp +++ b/alib/src/automaton/FSM/TransitionFSM.cpp @@ -29,4 +29,12 @@ bool TransitionFSM::operator != (const TransitionFSM& other) const { return from != other.from || input != other.input || to != other.to; } +std::ostream& TransitionFSM::operator>>(std::ostream& out) const { + out << "TransitionFSM from = " << this->from + << " to = " << this->to + << " input = " << this->input; + + return out; +} + } /* namespace automaton */ diff --git a/alib/src/automaton/FSM/TransitionFSM.h b/alib/src/automaton/FSM/TransitionFSM.h index 17dc9e52d1a4e956517f494e7fb6acb3ae65efc0..2c581370acebc160aacdca6d8af13143c53be934 100644 --- a/alib/src/automaton/FSM/TransitionFSM.h +++ b/alib/src/automaton/FSM/TransitionFSM.h @@ -29,6 +29,8 @@ public: bool operator <(const TransitionFSM& other) const; bool operator ==(const TransitionFSM& other) const; bool operator !=(const TransitionFSM& other) const; + + std::ostream& operator>>(std::ostream& out) const; }; } /* namespace automaton */ diff --git a/alib/src/automaton/PDA/TransitionPDA.cpp b/alib/src/automaton/PDA/TransitionPDA.cpp index 88c067cdfdfb16ffff2e97d992d00e0c08deb17c..6f14b7d00e8c69eeb14c6f4c2ab9d2e82776277f 100644 --- a/alib/src/automaton/PDA/TransitionPDA.cpp +++ b/alib/src/automaton/PDA/TransitionPDA.cpp @@ -120,4 +120,31 @@ bool TransitionPDA::operator !=(const TransitionPDA& other) const { return !((*this) == other); } +std::ostream& TransitionPDA::operator>>(std::ostream& out) const { + bool first; + out << "TransitionPDA from = " << this->from + << " to = " << this->to + << " input = " << this->input + << " pop = ["; + + first = true; + for(list<Symbol>::const_iterator iter = this->pop.begin(); iter != this->pop.end(); iter++) { + if(!first) out << ", "; + first = false; + out << *iter; + } + + out << "] push = ["; + + first = true; + for(list<Symbol>::const_iterator iter = this->push.begin(); iter != this->push.end(); iter++) { + if(!first) out << ", "; + first = false; + out << *iter; + } + out << "]"; + + return out; +} + } /* namespace automaton */ diff --git a/alib/src/automaton/PDA/TransitionPDA.h b/alib/src/automaton/PDA/TransitionPDA.h index 8f2f0b56146f6a3749b45b130aaa4c5e907d420c..9fcc2b71a87139a087c3681bdd0ccf429bb9185a 100644 --- a/alib/src/automaton/PDA/TransitionPDA.h +++ b/alib/src/automaton/PDA/TransitionPDA.h @@ -32,6 +32,8 @@ public: bool operator <(const TransitionPDA& other) const; bool operator ==(const TransitionPDA& other) const; bool operator !=(const TransitionPDA& other) const; + + std::ostream& operator>>(std::ostream& out) const; }; } /* namespace automaton */ diff --git a/alib/src/automaton/Shift.cpp b/alib/src/automaton/Shift.cpp new file mode 100644 index 0000000000000000000000000000000000000000..03f2e55c21ad5cb07091c953f7ea6c2334bae539 --- /dev/null +++ b/alib/src/automaton/Shift.cpp @@ -0,0 +1,10 @@ +/* + * Shift.cpp + * + * Created on: Dec 8, 2013 + * Author: honza + */ + +#include "Shift.h" + +std::string SHIFT_NAMES[] = {"LEFT", "RIGHT", "NONE", "NOT_SET" }; diff --git a/alib/src/automaton/Shift.h b/alib/src/automaton/Shift.h index af9632f9e4539cf588eda97c85ce25b74b947022..721caff2ad9be5795e5612e118c8e51a85572a85 100644 --- a/alib/src/automaton/Shift.h +++ b/alib/src/automaton/Shift.h @@ -8,6 +8,8 @@ #ifndef SHIFT_H_ #define SHIFT_H_ +#include <string> + /** * Represent movement of the reading head in the Turing machine. */ @@ -15,4 +17,6 @@ enum Shift { LEFT, RIGHT, NONE, NOT_SET }; +extern std::string SHIFT_NAMES[4]; + #endif /* SHIFT_H_ */ diff --git a/alib/src/automaton/State.cpp b/alib/src/automaton/State.cpp index 4c2a3fb370c7b0fd7a2316865ccb5bb95cfc0c8d..d278b21fb39be9c9f29b76062e075b60c72982f2 100644 --- a/alib/src/automaton/State.cpp +++ b/alib/src/automaton/State.cpp @@ -28,4 +28,9 @@ bool State::operator != (const State& other) const{ return name != other.name; } +std::ostream& operator<<(std::ostream& out, const State& state) { + out << "State " << state.name; + return out; +} + } /* namespace automaton */ diff --git a/alib/src/automaton/State.h b/alib/src/automaton/State.h index 6ffad3c43fae1b02e10db098b8e58c9f1a3a96b6..1cb546d3cafaf3896ca73aaa006962f65916c64c 100644 --- a/alib/src/automaton/State.h +++ b/alib/src/automaton/State.h @@ -26,6 +26,8 @@ public: bool operator < (const State& other) const; bool operator == (const State& other) const; bool operator != (const State& other) const; + + friend std::ostream& operator<<(std::ostream&, const State&); }; } /* namespace automaton */ diff --git a/alib/src/automaton/TM/TransitionTM.cpp b/alib/src/automaton/TM/TransitionTM.cpp index 2c67ffdafadfb944d4e5bc890f1aad9e02c16af3..ac535ee8dd366362eb1b2c1edf5ec9495b9ca8e1 100644 --- a/alib/src/automaton/TM/TransitionTM.cpp +++ b/alib/src/automaton/TM/TransitionTM.cpp @@ -49,4 +49,14 @@ bool TransitionTM::operator !=(const TransitionTM& other) const { return !((*this) == other); } +std::ostream& TransitionTM::operator>>(std::ostream& out) const { + out << "TransitionTM from = " << this->from + << " to = " << this->to + << " input = " << this->input + << " output = " << this->output + << " shift = " << SHIFT_NAMES[this->shift]; + + return out; +} + } /* namespace automaton */ diff --git a/alib/src/automaton/TM/TransitionTM.h b/alib/src/automaton/TM/TransitionTM.h index 505681a531e68bada88751fc9f2d560ecb0674ed..3ce2559b199762bea700e532d7f9397f47341c78 100644 --- a/alib/src/automaton/TM/TransitionTM.h +++ b/alib/src/automaton/TM/TransitionTM.h @@ -56,6 +56,8 @@ public: bool operator <(const TransitionTM& other) const; bool operator ==(const TransitionTM& other) const; bool operator !=(const TransitionTM& other) const; + + std::ostream& operator>>(std::ostream& out) const; }; } /* namespace automaton */ diff --git a/alib/src/automaton/Transition.cpp b/alib/src/automaton/Transition.cpp index 48166b2337fcfc7d4792a26b0b043a852bfc8084..3c0aea6d294c59e38bbb0a1054fd8376e92af701 100644 --- a/alib/src/automaton/Transition.cpp +++ b/alib/src/automaton/Transition.cpp @@ -42,4 +42,14 @@ bool Transition::containsState(const State& state) const { return from == state || to == state; } +std::ostream& operator<<(std::ostream& out, const Transition& transition) { + transition >> out; + return out; +} + +std::ostream& Transition::operator>>(std::ostream& out) const { + out << "Transition from = " << this->from << " to = " << this->to << " input = " << this->input; + return out; +} + } /* namespace automaton */ diff --git a/alib/src/automaton/Transition.h b/alib/src/automaton/Transition.h index 857ee473ad9f1872dea3d3b53f318e07a0f97e48..c3fce1ef4d2f415f2d10cedd124b5a763dca806e 100644 --- a/alib/src/automaton/Transition.h +++ b/alib/src/automaton/Transition.h @@ -62,6 +62,10 @@ public: * @return true when transition contains the state, false otherwise */ bool containsState(const State& state) const; + + friend std::ostream& operator<<(std::ostream&, const Transition&); + + virtual std::ostream& operator>>(std::ostream&) const; }; } /* namespace automaton */ diff --git a/alib/src/automaton/UnknownTransition.cpp b/alib/src/automaton/UnknownTransition.cpp index a452f18d9e216b91762cd362add3976830cab28f..878aededbef8d9fd28b765b8c602797eda42e5ab 100644 --- a/alib/src/automaton/UnknownTransition.cpp +++ b/alib/src/automaton/UnknownTransition.cpp @@ -138,4 +138,32 @@ bool UnknownTransition::operator !=(const UnknownTransition& other) const { return !((*this) == other); } +std::ostream& UnknownTransition::operator>>(std::ostream& out) const { + bool first; + out << "UnknownTransition from = " << this->from + << " to = " << this->to + << " input = " << this->input + << " output = " << this->output + << " pop = ["; + + first = true; + for(list<Symbol>::const_iterator iter = this->pop.begin(); iter != this->pop.end(); iter++) { + if(!first) out << ", "; + first = false; + out << *iter; + } + + out << "] push = ["; + + first = true; + for(list<Symbol>::const_iterator iter = this->push.begin(); iter != this->push.end(); iter++) { + if(!first) out << ", "; + first = false; + out << *iter; + } + out << "] shift = " << SHIFT_NAMES[this->shift]; + + return out; +} + } /* namespace automaton */ diff --git a/alib/src/automaton/UnknownTransition.h b/alib/src/automaton/UnknownTransition.h index 19621d0d9288ab9cf794e4dfa65ba550433720ad..0dcf1ee45d9a0f9f7e62f8658c3a7a21d6a21476 100644 --- a/alib/src/automaton/UnknownTransition.h +++ b/alib/src/automaton/UnknownTransition.h @@ -81,6 +81,8 @@ public: bool operator <(const UnknownTransition& other) const; bool operator ==(const UnknownTransition& other) const; bool operator !=(const UnknownTransition& other) const; + + virtual std::ostream& operator>>(std::ostream&) const; }; } /* namespace automaton */