Skip to content
Snippets Groups Projects
Commit d46cb5f0 authored by Martin Žák's avatar Martin Žák
Browse files

Adds operator << to automaton, grammar and regexp

parent 1db1a2f2
No related branches found
No related tags found
No related merge requests found
...@@ -34,21 +34,21 @@ void getAutomaton(list<Token>& tokens, bool complexTypes) { ...@@ -34,21 +34,21 @@ void getAutomaton(list<Token>& tokens, bool complexTypes) {
UnknownAutomaton automaton = AutomatonParser::parse(tokens); UnknownAutomaton automaton = AutomatonParser::parse(tokens);
   
if(complexTypes) { if(complexTypes) {
Automaton* concreateAutomaton = AutomatonFactory::buildAutomaton(automaton); Automaton* concreteAutomaton = AutomatonFactory::buildAutomaton(automaton);
concreateAutomaton->toXML(cout); cout << *concreteAutomaton;
} else { } else {
automaton.toXML(cout); cout << automaton;
} }
} }
   
void getGrammar(list<Token>& tokens) { void getGrammar(list<Token>& tokens) {
UnknownGrammar grammar = GrammarParser::parse(tokens); UnknownGrammar grammar = GrammarParser::parse(tokens);
grammar.toXML(cout); cout << grammar;
} }
   
void getRegExp(list<Token>& tokens) { void getRegExp(list<Token>& tokens) {
RegExp regexp = RegExpParser::parse(tokens); RegExp regexp = RegExpParser::parse(tokens);
regexp.toXML(cout); cout << regexp;
} }
   
int main(int argc, char** argv) { int main(int argc, char** argv) {
......
...@@ -77,4 +77,11 @@ const set<State>& Automaton::getFinalStates() const { ...@@ -77,4 +77,11 @@ const set<State>& Automaton::getFinalStates() const {
return finalStates; return finalStates;
} }
   
ostream& operator <<(ostream& out, const Automaton& automaton) {
automaton.toXML(out);
return out;
}
} /* namespace automaton */ } /* namespace automaton */
...@@ -111,10 +111,17 @@ public: ...@@ -111,10 +111,17 @@ public:
const set<State>& getFinalStates() const; const set<State>& getFinalStates() const;
   
/** /**
* Prints XML representation of the automaton. * Prints XML representation of the automaton to the ostream.
* @param out output stream to which print the automaton * @param out output stream to which print the automaton
*/ */
virtual void toXML(ostream& out) const = 0; virtual void toXML(ostream& out) const = 0;
/**
* Prints XML representation of the automaton to the ostream.
* @param out output stream to which print the automaton
* @param automaton automaton to print
*/
friend ostream& operator<<(ostream& out, const Automaton& automaton);
}; };
   
} /* namespace automaton */ } /* namespace automaton */
......
...@@ -114,4 +114,9 @@ void Grammar::toXML(ostream& out) const { ...@@ -114,4 +114,9 @@ void Grammar::toXML(ostream& out) const {
GrammarPrinter::toXML(*this, out); GrammarPrinter::toXML(*this, out);
} }
   
ostream& operator <<(ostream& out, const Grammar& grammar) {
grammar.toXML(out);
return out;
}
} /* namespace grammar */ } /* namespace grammar */
...@@ -116,6 +116,13 @@ public: ...@@ -116,6 +116,13 @@ public:
* @param out output stream to print to * @param out output stream to print to
*/ */
void toXML(ostream& out) const; void toXML(ostream& out) const;
/**
* Prints the XML representation of grammar to the output stream.
* @param out output stream to print to
* @param grammar grammar to print
*/
friend ostream& operator<<(ostream& out, const Grammar& grammar);
}; };
   
} /* namespace grammar */ } /* namespace grammar */
......
...@@ -102,7 +102,7 @@ bool Rule::operator !=(const Rule& other) const { ...@@ -102,7 +102,7 @@ bool Rule::operator !=(const Rule& other) const {
|| !equal(rightSide.begin(), rightSide.end(), other.rightSide.begin()); || !equal(rightSide.begin(), rightSide.end(), other.rightSide.begin());
} }
   
std::ostream& operator<<(std::ostream& out, const Rule& rule) { ostream& operator<<(ostream& out, const Rule& rule) {
bool first; bool first;
out << " leftSide = ["; out << " leftSide = [";
   
...@@ -113,7 +113,7 @@ std::ostream& operator<<(std::ostream& out, const Rule& rule) { ...@@ -113,7 +113,7 @@ std::ostream& operator<<(std::ostream& out, const Rule& rule) {
out << *iter; out << *iter;
} }
   
out << "] rightSize = ["; out << "] rightSide = [";
   
first = true; first = true;
for(list<Symbol>::const_iterator iter = rule.rightSide.begin(); iter != rule.rightSide.end(); iter++) { for(list<Symbol>::const_iterator iter = rule.rightSide.begin(); iter != rule.rightSide.end(); iter++) {
......
...@@ -66,7 +66,7 @@ public: ...@@ -66,7 +66,7 @@ public:
bool operator ==(const Rule& other) const; bool operator ==(const Rule& other) const;
bool operator !=(const Rule& other) const; bool operator !=(const Rule& other) const;
   
friend std::ostream& operator<<(std::ostream&, const Rule&); friend ostream& operator<<(ostream&, const Rule&);
}; };
   
} /* namespace grammar */ } /* namespace grammar */
......
...@@ -70,4 +70,9 @@ void RegExp::toXML(ostream& out) { ...@@ -70,4 +70,9 @@ void RegExp::toXML(ostream& out) {
RegExpPrinter::toXML(*this, out); RegExpPrinter::toXML(*this, out);
} }
   
ostream& operator <<(ostream& out, RegExp& regexp) {
regexp.toXML(out);
return out;
}
} /* namespace regexp */ } /* namespace regexp */
...@@ -54,6 +54,13 @@ public: ...@@ -54,6 +54,13 @@ public:
* @param out output stream to which print the RegExp * @param out output stream to which print the RegExp
*/ */
void toXML(ostream& out); void toXML(ostream& out);
/**
* Prints XML representation of the RegExp to the output stream.
* @param out output stream to which print the RegExp
* @param regexp RegExp to print
*/
friend ostream& operator<<(ostream& out, RegExp& regexp);
}; };
   
} /* namespace regexp */ } /* namespace regexp */
......
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