diff --git a/alib/makefile b/alib/makefile
new file mode 100644
index 0000000000000000000000000000000000000000..6d1a3f5044f28a72b55b7a2ed38087894214d11d
--- /dev/null
+++ b/alib/makefile
@@ -0,0 +1,13 @@
+LIBRARY=libalib.so 
+CXXFLAGS= -std=c++11 -O2 -c -Wall -fPIC -I/usr/include/libxml2/ 
+LDFLAGS= -shared -lxml2
+
+
+SOURCES = src/automaton/*.cpp src/automaton/TM/*.cpp src/automaton/FSM/*.cpp src/automaton/PDA/*cpp src/automaton/exception/*.cpp src/regexp/*.cpp src/grammar/*.cpp src/grammar/Regular/*.cpp src/grammar/Linear/*.cpp src/grammar/Unrestricted/*.cpp src/grammar/ContextSensitive/*.cpp src/grammar/ContextFree/*.cpp src/sax/*.cpp src/alphabet/*.cpp src/*.cpp
+
+all:
+	g++ $(CXXFLAGS) $(SOURCES)
+	g++ $(LDFLAGS) *.o -o $(LIBRARY)
+
+clean:
+	$(RM) *.o *.d $(LIBRARY)
diff --git a/alib/src/GrammarFactory.h b/alib/src/GrammarFactory.h
index 3eb5e1e7cbb399b443c469ecdf463f366f1a932d..d622843f5e249f29149475150ef0a14c2996a9f0 100644
--- a/alib/src/GrammarFactory.h
+++ b/alib/src/GrammarFactory.h
@@ -10,14 +10,13 @@
 
 #include "sax/Token.h"
 #include "grammar/UnknownGrammar.h"
-#include "grammar/RightRegularGrammar.h"
-#include "grammar/LeftRegularGrammar.h"
-#include "grammar/RightLinearGrammar.h"
-#include "grammar/LeftLinearGrammar.h"
-#include "grammar/ContextFreeGrammar.h"
-#include "grammar/ContextSensitiveGrammar.h"
-
-#include "grammar/UnrestrictedGrammar.h"
+#include "grammar/Regular/RightRegularGrammar.h"
+#include "grammar/Regular/LeftRegularGrammar.h"
+#include "grammar/Linear/RightLinearGrammar.h"
+#include "grammar/Linear/LeftLinearGrammar.h"
+#include "grammar/ContextFree/ContextFreeGrammar.h"
+#include "grammar/ContextSensitive/ContextSensitiveGrammar.h"
+#include "grammar/Unrestricted/UnrestrictedGrammar.h"
 
 namespace grammar {
 
diff --git a/alib/src/RegExpFactory.cpp b/alib/src/RegExpFactory.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0d5d9c514f109c4ad76ac7179fdfe8653fb3e885
--- /dev/null
+++ b/alib/src/RegExpFactory.cpp
@@ -0,0 +1,28 @@
+/*
+ * RegExpFactory.cpp
+ *
+ *  Created on: Jan 1, 2014
+ *      Author: martin
+ */
+
+#include "sax/SaxInterface.h"
+#include "RegExpFactory.h"
+#include "regexp/RegExpParser.h"
+
+namespace regexp {
+
+RegExp RegExpFactory::fromFile(const string& filename) {
+	std::list<Token> tokens;
+	SaxInterface::parseFile(filename, tokens);
+	RegExpParser parser;
+	return parser.parse(tokens);
+}
+
+RegExp RegExpFactory::fromString(const string& str) {
+	list<Token> tokens;
+	SaxInterface::parseMemory(str, tokens);
+	RegExpParser parser;
+	return parser.parse(tokens);
+}
+
+} /* namespace regexp */
diff --git a/alib/src/RegExpFactory.h b/alib/src/RegExpFactory.h
new file mode 100644
index 0000000000000000000000000000000000000000..e81874405c55f8dd02f1b5d623803ce1f967b56c
--- /dev/null
+++ b/alib/src/RegExpFactory.h
@@ -0,0 +1,38 @@
+/*
+ * RegExpFactory.h
+ *
+ *  Created on: Jan 1, 2014
+ *      Author: martin
+ */
+
+#ifndef REGEXPFACTORY_H_
+#define REGEXPFACTORY_H_
+
+#include "regexp/RegExp.h"
+
+namespace regexp {
+
+using namespace std;
+
+/**
+ * RegExp builder.
+ */
+class RegExpFactory {
+public:
+	/**
+	 * Parses the XML in file and returns the RegExp.
+	 * @param filename path to the file
+	 * @return RegExp
+	 */
+	static RegExp fromFile(const string& filename);
+
+	/**
+	 * Parses the XML and returns the RegExp.
+	 * @param str string containing the XML
+	 * @return RegExp
+	 */
+	static RegExp fromString(const string& str);
+};
+
+} /* namespace regexp */
+#endif /* REGEXPFACTORY_H_ */
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/Automaton.cpp b/alib/src/automaton/Automaton.cpp
index 519b65c7c2d4e6eff25aaf1b0da7893e736c03a5..27235c01383ca74fb5f5af4b456d062d36e3d6ee 100644
--- a/alib/src/automaton/Automaton.cpp
+++ b/alib/src/automaton/Automaton.cpp
@@ -77,4 +77,11 @@ const set<State>& Automaton::getFinalStates() const {
 	return finalStates;
 }
 
+ostream& operator <<(ostream& out, const Automaton& automaton) {
+	automaton.toXML(out);
+	return out;
+}
+
 } /* namespace automaton */
+
+
diff --git a/alib/src/automaton/Automaton.h b/alib/src/automaton/Automaton.h
index bfbfd4cfb8cd6b3d258a3491954a830892317b86..7686fe04e91df3a682c04c2e58a63d9b03373bb2 100644
--- a/alib/src/automaton/Automaton.h
+++ b/alib/src/automaton/Automaton.h
@@ -111,10 +111,17 @@ public:
 	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
 	 */
 	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 */
diff --git a/alib/src/automaton/FSM/FSM.cpp b/alib/src/automaton/FSM/FSM.cpp
index 6a90f060c6d6654ba7559976eb6b174bd2505943..5d5804ecce35d8a5c013d1d0696632862b9e7f38 100644
--- a/alib/src/automaton/FSM/FSM.cpp
+++ b/alib/src/automaton/FSM/FSM.cpp
@@ -132,4 +132,8 @@ bool FSM::isDeterministic() const {
 	return true;
 }
 
+bool FSM::isTotal() const {
+	return isDeterministic() && transitions.size() == inputAlphabet.size() * states.size();
+}
+
 } /* namespace automaton */
diff --git a/alib/src/automaton/FSM/FSM.h b/alib/src/automaton/FSM/FSM.h
index 0e43b41cde89daa1cdae3a8c17cdf2ab08b9d438..9cbafba41637ebe358be9b1d62b4966ceefea941 100644
--- a/alib/src/automaton/FSM/FSM.h
+++ b/alib/src/automaton/FSM/FSM.h
@@ -83,6 +83,8 @@ public:
 	 */
 	bool isDeterministic() const;
 
+	bool isTotal() const;
+
 	/**
 	 * @copydoc Automaton::toXML(ostream&) const
 	 */
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 */
diff --git a/alib/src/grammar/ContextFreeGrammar.cpp b/alib/src/grammar/ContextFree/ContextFreeGrammar.cpp
similarity index 100%
rename from alib/src/grammar/ContextFreeGrammar.cpp
rename to alib/src/grammar/ContextFree/ContextFreeGrammar.cpp
diff --git a/alib/src/grammar/ContextFreeGrammar.h b/alib/src/grammar/ContextFree/ContextFreeGrammar.h
similarity index 98%
rename from alib/src/grammar/ContextFreeGrammar.h
rename to alib/src/grammar/ContextFree/ContextFreeGrammar.h
index febbb040c62d641e38d2b0a9203013800700fb6e..5c481e1b055199b5c99358832cfca8cdd1c46cc9 100644
--- a/alib/src/grammar/ContextFreeGrammar.h
+++ b/alib/src/grammar/ContextFree/ContextFreeGrammar.h
@@ -8,7 +8,7 @@
 #ifndef CONTEXTFREEGRAMMAR_H_
 #define CONTEXTFREEGRAMMAR_H_
 
-#include "Grammar.h"
+#include "../Grammar.h"
 
 namespace grammar {
 
diff --git a/alib/src/grammar/ContextSensitiveGrammar.cpp b/alib/src/grammar/ContextSensitive/ContextSensitiveGrammar.cpp
similarity index 100%
rename from alib/src/grammar/ContextSensitiveGrammar.cpp
rename to alib/src/grammar/ContextSensitive/ContextSensitiveGrammar.cpp
diff --git a/alib/src/grammar/ContextSensitiveGrammar.h b/alib/src/grammar/ContextSensitive/ContextSensitiveGrammar.h
similarity index 98%
rename from alib/src/grammar/ContextSensitiveGrammar.h
rename to alib/src/grammar/ContextSensitive/ContextSensitiveGrammar.h
index d41d68f272fc84275beafb4caeea210db2805004..4b6d8d62c48707fd6fcfd38b86e429fc2ca20494 100644
--- a/alib/src/grammar/ContextSensitiveGrammar.h
+++ b/alib/src/grammar/ContextSensitive/ContextSensitiveGrammar.h
@@ -8,7 +8,7 @@
 #ifndef CONTEXTSENSITIVEGRAMMAR_H_
 #define CONTEXTSENSITIVEGRAMMAR_H_
 
-#include "Grammar.h"
+#include "../Grammar.h"
 
 namespace grammar {
 
diff --git a/alib/src/grammar/Grammar.cpp b/alib/src/grammar/Grammar.cpp
index be42c3f2d1e62b1cb1fa796ec5c5423b143bec2d..c1d28daed371558cdbe39d3b12fa5be2df3b444e 100644
--- a/alib/src/grammar/Grammar.cpp
+++ b/alib/src/grammar/Grammar.cpp
@@ -114,4 +114,9 @@ void Grammar::toXML(ostream& out) const {
 	GrammarPrinter::toXML(*this, out);
 }
 
+ostream& operator <<(ostream& out, const Grammar& grammar) {
+	grammar.toXML(out);
+	return out;
+}
+
 } /* namespace grammar */
diff --git a/alib/src/grammar/Grammar.h b/alib/src/grammar/Grammar.h
index a6833a74f7e9ecfd1e8e40ed5932edbb41bf0575..fd4c2fe856de892b5e9a1cb9f2bb765d612cb362 100644
--- a/alib/src/grammar/Grammar.h
+++ b/alib/src/grammar/Grammar.h
@@ -116,6 +116,13 @@ public:
 	 * @param out output stream to print to
 	 */
 	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 */
diff --git a/alib/src/grammar/LeftLinearGrammar.cpp b/alib/src/grammar/Linear/LeftLinearGrammar.cpp
similarity index 94%
rename from alib/src/grammar/LeftLinearGrammar.cpp
rename to alib/src/grammar/Linear/LeftLinearGrammar.cpp
index f64fd515e2f323fd6a0bf6e8817d59c9fcfed139..325b652b339bcb832871d6a8424b6b8db4a08c79 100644
--- a/alib/src/grammar/LeftLinearGrammar.cpp
+++ b/alib/src/grammar/Linear/LeftLinearGrammar.cpp
@@ -10,12 +10,12 @@
 namespace grammar {
 
 LeftLinearGrammar::LeftLinearGrammar() :
-		Grammar() {
+		LinearGrammar() {
 }
 
 LeftLinearGrammar::LeftLinearGrammar(const set<Symbol>& nonTerminalSymbols, const set<Symbol>& terminalSymbols,
 		const Symbol& startSymbol) :
-		Grammar(nonTerminalSymbols, terminalSymbols, startSymbol) {
+		LinearGrammar(nonTerminalSymbols, terminalSymbols, startSymbol) {
 }
 
 bool LeftLinearGrammar::isValidRule(const Rule& rule) const {
diff --git a/alib/src/grammar/LeftLinearGrammar.h b/alib/src/grammar/Linear/LeftLinearGrammar.h
similarity index 93%
rename from alib/src/grammar/LeftLinearGrammar.h
rename to alib/src/grammar/Linear/LeftLinearGrammar.h
index c82113d3d368414de81d62f72f4475527eac1882..c81f09d022102b2ae1d1cd9dcd78d4f44f6c4c5a 100644
--- a/alib/src/grammar/LeftLinearGrammar.h
+++ b/alib/src/grammar/Linear/LeftLinearGrammar.h
@@ -8,14 +8,14 @@
 #ifndef LEFTLINEARGRAMMAR_H_
 #define LEFTLINEARGRAMMAR_H_
 
-#include "Grammar.h"
+#include "LinearGrammar.h"
 
 namespace grammar {
 
 /**
  * Left linear grammar. Produces regular language.
  */
-class LeftLinearGrammar: public Grammar {
+class LeftLinearGrammar: public LinearGrammar {
 private:
 	/**
 	 * Checks that left side of the Rule contains one symbol which is nonterminal.
diff --git a/alib/src/grammar/Linear/LinearGrammar.cpp b/alib/src/grammar/Linear/LinearGrammar.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..21e534224ed168c1df1991cbb3615e2896bb28db
--- /dev/null
+++ b/alib/src/grammar/Linear/LinearGrammar.cpp
@@ -0,0 +1,20 @@
+/*
+ * LinearGrammar.cpp
+ *
+ *  Created on: Jan 1, 2014
+ *      Author: martin
+ */
+
+#include "LinearGrammar.h"
+
+namespace grammar {
+
+LinearGrammar::LinearGrammar() :
+		Grammar() {
+}
+
+LinearGrammar::LinearGrammar(const set<Symbol>& nonTerminalSymbols, const set<Symbol>& terminalSymbols,
+		const Symbol& startSymbol) :
+		Grammar(nonTerminalSymbols, terminalSymbols, startSymbol) {
+}
+} /* namespace grammar */
diff --git a/alib/src/grammar/Linear/LinearGrammar.h b/alib/src/grammar/Linear/LinearGrammar.h
new file mode 100644
index 0000000000000000000000000000000000000000..9c3a95f736a680a7a80ae74b666ea0791dff08e8
--- /dev/null
+++ b/alib/src/grammar/Linear/LinearGrammar.h
@@ -0,0 +1,26 @@
+/*
+ * LinearGrammar.h
+ *
+ *  Created on: Jan 1, 2014
+ *      Author: Martin Zak
+ */
+
+#ifndef LINEARGRAMMAR_H_
+#define LINEARGRAMMAR_H_
+
+#include "../Grammar.h"
+
+namespace grammar {
+
+/**
+ * Abstract class for linear grammars.
+ */
+class LinearGrammar: public Grammar {
+public:
+	LinearGrammar();
+	LinearGrammar(const set<Symbol>& nonTerminalSymbols, const set<Symbol>& terminalSymbols,
+			const Symbol& startSymbol);
+};
+
+} /* namespace grammar */
+#endif /* LINEARGRAMMAR_H_ */
diff --git a/alib/src/grammar/RightLinearGrammar.cpp b/alib/src/grammar/Linear/RightLinearGrammar.cpp
similarity index 95%
rename from alib/src/grammar/RightLinearGrammar.cpp
rename to alib/src/grammar/Linear/RightLinearGrammar.cpp
index e32612d742d28d779ca2f027a5dff2f552a84ed3..10d34e1fbf4a28d6288df618723c1d183e7f68b3 100644
--- a/alib/src/grammar/RightLinearGrammar.cpp
+++ b/alib/src/grammar/Linear/RightLinearGrammar.cpp
@@ -10,12 +10,12 @@
 namespace grammar {
 
 RightLinearGrammar::RightLinearGrammar() :
-		Grammar() {
+		LinearGrammar() {
 }
 
 RightLinearGrammar::RightLinearGrammar(const set<Symbol>& nonTerminalSymbols, const set<Symbol>& terminalSymbols,
 		const Symbol& startSymbol) :
-		Grammar(nonTerminalSymbols, terminalSymbols, startSymbol) {
+		LinearGrammar(nonTerminalSymbols, terminalSymbols, startSymbol) {
 }
 
 bool RightLinearGrammar::isValidRule(const Rule& rule) const {
diff --git a/alib/src/grammar/RightLinearGrammar.h b/alib/src/grammar/Linear/RightLinearGrammar.h
similarity index 93%
rename from alib/src/grammar/RightLinearGrammar.h
rename to alib/src/grammar/Linear/RightLinearGrammar.h
index 7f0ec1a2092ce907448434401174ebf881654594..8397ece746b750102ad70d73c1a5b7f6f75f4969 100644
--- a/alib/src/grammar/RightLinearGrammar.h
+++ b/alib/src/grammar/Linear/RightLinearGrammar.h
@@ -8,14 +8,14 @@
 #ifndef RIGHTLINEARGRAMMAR_H_
 #define RIGHTLINEARGRAMMAR_H_
 
-#include "Grammar.h"
+#include "LinearGrammar.h"
 
 namespace grammar {
 
 /**
  * Right regular grammar. Produces regular language.
  */
-class RightLinearGrammar: public Grammar {
+class RightLinearGrammar: public LinearGrammar {
 private:
 	/**
 	 * Checks that left side of the Rule contains one symbol which is nonterminal.
diff --git a/alib/src/grammar/LeftRegularGrammar.cpp b/alib/src/grammar/Regular/LeftRegularGrammar.cpp
similarity index 100%
rename from alib/src/grammar/LeftRegularGrammar.cpp
rename to alib/src/grammar/Regular/LeftRegularGrammar.cpp
diff --git a/alib/src/grammar/LeftRegularGrammar.h b/alib/src/grammar/Regular/LeftRegularGrammar.h
similarity index 100%
rename from alib/src/grammar/LeftRegularGrammar.h
rename to alib/src/grammar/Regular/LeftRegularGrammar.h
diff --git a/alib/src/grammar/RegularGrammar.cpp b/alib/src/grammar/Regular/RegularGrammar.cpp
similarity index 100%
rename from alib/src/grammar/RegularGrammar.cpp
rename to alib/src/grammar/Regular/RegularGrammar.cpp
diff --git a/alib/src/grammar/RegularGrammar.h b/alib/src/grammar/Regular/RegularGrammar.h
similarity index 94%
rename from alib/src/grammar/RegularGrammar.h
rename to alib/src/grammar/Regular/RegularGrammar.h
index daa090e269c6a1268118b70dc747f8ee3dc7947b..639326417c1a20b1070b679613ba11d8d756dd76 100644
--- a/alib/src/grammar/RegularGrammar.h
+++ b/alib/src/grammar/Regular/RegularGrammar.h
@@ -8,10 +8,13 @@
 #ifndef REGULARGRAMMAR_H_
 #define REGULARGRAMMAR_H_
 
-#include "Grammar.h"
+#include "../Grammar.h"
 
 namespace grammar {
 
+/**
+ * Abstract class for regular grammars.
+ */
 class RegularGrammar: public Grammar {
 protected:
 	/**
diff --git a/alib/src/grammar/RightRegularGrammar.cpp b/alib/src/grammar/Regular/RightRegularGrammar.cpp
similarity index 100%
rename from alib/src/grammar/RightRegularGrammar.cpp
rename to alib/src/grammar/Regular/RightRegularGrammar.cpp
diff --git a/alib/src/grammar/RightRegularGrammar.h b/alib/src/grammar/Regular/RightRegularGrammar.h
similarity index 100%
rename from alib/src/grammar/RightRegularGrammar.h
rename to alib/src/grammar/Regular/RightRegularGrammar.h
diff --git a/alib/src/grammar/Rule.cpp b/alib/src/grammar/Rule.cpp
index 8113b2ca37d6dcc924e11298ffb744870e202fe5..1abe676b2552ec48a0a4ff49c270bd68eab990e7 100644
--- a/alib/src/grammar/Rule.cpp
+++ b/alib/src/grammar/Rule.cpp
@@ -102,4 +102,28 @@ bool Rule::operator !=(const Rule& other) const {
 			|| !equal(rightSide.begin(), rightSide.end(), other.rightSide.begin());
 }
 
+ostream& operator<<(ostream& out, const Rule& rule) {
+	bool first;
+	out << " leftSide = [";
+
+	first = true;
+	for(list<Symbol>::const_iterator iter = rule.leftSide.begin(); iter != rule.leftSide.end(); iter++) {
+		if(!first) out << ", ";
+		first = false;
+		out << *iter;
+	}
+
+	out << "] rightSide = [";
+
+	first = true;
+	for(list<Symbol>::const_iterator iter = rule.rightSide.begin(); iter != rule.rightSide.end(); iter++) {
+		if(!first) out << ", ";
+		first = false;
+		out << *iter;
+	}
+	out << "]";
+
+	return out;
+}
+
 } /* namespace grammar */
diff --git a/alib/src/grammar/Rule.h b/alib/src/grammar/Rule.h
index 1395dc2fef8746b4229af7275f263b70bd7e9f50..f708aa71f5ee53a4bea1765754947858431dd08b 100644
--- a/alib/src/grammar/Rule.h
+++ b/alib/src/grammar/Rule.h
@@ -65,6 +65,8 @@ public:
 	bool operator <(const Rule& other) const;
 	bool operator ==(const Rule& other) const;
 	bool operator !=(const Rule& other) const;
+
+	friend ostream& operator<<(ostream&, const Rule&);
 };
 
 } /* namespace grammar */
diff --git a/alib/src/grammar/UnrestrictedGrammar.cpp b/alib/src/grammar/Unrestricted/UnrestrictedGrammar.cpp
similarity index 100%
rename from alib/src/grammar/UnrestrictedGrammar.cpp
rename to alib/src/grammar/Unrestricted/UnrestrictedGrammar.cpp
diff --git a/alib/src/grammar/UnrestrictedGrammar.h b/alib/src/grammar/Unrestricted/UnrestrictedGrammar.h
similarity index 97%
rename from alib/src/grammar/UnrestrictedGrammar.h
rename to alib/src/grammar/Unrestricted/UnrestrictedGrammar.h
index 9bd424f3c306708d16c2d7fcee7ff0816afa43d4..eb9802d07bfa8b6e6aa5b649f3cabe65c8f5dcd9 100644
--- a/alib/src/grammar/UnrestrictedGrammar.h
+++ b/alib/src/grammar/Unrestricted/UnrestrictedGrammar.h
@@ -8,7 +8,7 @@
 #ifndef UNRESTRICTEDGRAMMAR_H_
 #define UNRESTRICTEDGRAMMAR_H_
 
-#include "Grammar.h"
+#include "../Grammar.h"
 
 namespace grammar {
 
diff --git a/alib/src/regexp/RegExp.cpp b/alib/src/regexp/RegExp.cpp
index 92641f64ab2cbd000b06812647a3fa039ced5953..6cec78b363919503f23e2e06415217cfd3cc9e4f 100644
--- a/alib/src/regexp/RegExp.cpp
+++ b/alib/src/regexp/RegExp.cpp
@@ -70,4 +70,9 @@ void RegExp::toXML(ostream& out) {
 	RegExpPrinter::toXML(*this, out);
 }
 
+ostream& operator <<(ostream& out, RegExp& regexp) {
+	regexp.toXML(out);
+	return out;
+}
+
 } /* namespace regexp */
diff --git a/alib/src/regexp/RegExp.h b/alib/src/regexp/RegExp.h
index f26f94fbf7ce1dfb7baee1317c9d353e4335ec34..73507c1fa4f01cf3152fcab3687eec88b8be62da 100644
--- a/alib/src/regexp/RegExp.h
+++ b/alib/src/regexp/RegExp.h
@@ -54,6 +54,13 @@ public:
 	 * @param out output stream to which print the RegExp
 	 */
 	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 */
diff --git a/alib/src/sax/SaxInterface.cpp b/alib/src/sax/SaxInterface.cpp
index b963e752bf90467da0868a597a716e25be29af3b..6370398af127c5ebb731b33412a1b32e18feede4 100644
--- a/alib/src/sax/SaxInterface.cpp
+++ b/alib/src/sax/SaxInterface.cpp
@@ -65,6 +65,8 @@ void SaxInterface::characters(void * userData, const xmlChar * ch, int len) {
 }
 
 void SaxInterface::startElement(void* userData, const xmlChar* name, const xmlChar** attrs) {
+	(void)attrs;
+
 	list<Token> &out = *((list<Token>*) userData);
 	out.push_back(Token((char*) name, Token::START_ELEMENT));
 }