diff --git a/alib2data/src/rte/RTEFeatures.h b/alib2data/src/rte/RTEFeatures.h
index 7deb651c80cf721ff9123d4ba16a6c9e61f91171..9d58de961c7c865901edcfc770e70d43ec1f0790 100644
--- a/alib2data/src/rte/RTEFeatures.h
+++ b/alib2data/src/rte/RTEFeatures.h
@@ -18,6 +18,7 @@ class RTE;
 class RTEBase;
 
 class FormalRTE;
+class FormalRTEStructure;
 
 class FormalRTEElement;
 class FormalRTEAlternation;
diff --git a/alib2data/src/rte/common/RTEToXMLComposer.cpp b/alib2data/src/rte/common/RTEToXMLComposer.cpp
index 5cc08d09b81258ee28fe7338ae66d1639d7ef96f..dbf28bcd9d8ea077bec4ceed63c52c3f19d1a3c0 100644
--- a/alib2data/src/rte/common/RTEToXMLComposer.cpp
+++ b/alib2data/src/rte/common/RTEToXMLComposer.cpp
@@ -9,62 +9,50 @@
 
 namespace rte {
 
-void RTEToXMLComposer::Formal::Visit ( void * userData, const FormalRTEAlternation & alternation ) const {
-	std::deque < sax::Token > & out = * ( ( std::deque < sax::Token > * )userData );
-
+void RTEToXMLComposer::Formal::visit ( const FormalRTEAlternation & alternation, std::deque < sax::Token > & out ) {
 	out.emplace_back ( "alternation", sax::Token::TokenType::START_ELEMENT );
-	alternation.getLeftElement ( ).Accept ( userData, * this );
-	alternation.getRightElement ( ).Accept ( userData, * this );
+	alternation.getLeftElement ( ).accept < void, RTEToXMLComposer::Formal > ( out );
+	alternation.getRightElement ( ).accept < void, RTEToXMLComposer::Formal > ( out );
 	out.emplace_back ( "alternation", sax::Token::TokenType::END_ELEMENT );
 }
 
-void RTEToXMLComposer::Formal::Visit ( void * userData, const FormalRTESubstitution & substitution ) const {
-	std::deque < sax::Token > & out = * ( ( std::deque < sax::Token > * )userData );
-
+void RTEToXMLComposer::Formal::visit ( const FormalRTESubstitution & substitution, std::deque < sax::Token > & out ) {
 	out.emplace_back ( "substitution", sax::Token::TokenType::START_ELEMENT );
 
 	alib::xmlApi < std::ranked_symbol < > >::compose ( out, substitution.getSubstitutionSymbol ( ).getSymbol ( ) );
-	substitution.getLeftElement ( ).Accept ( userData, * this );
-	substitution.getRightElement ( ).Accept ( userData, * this );
+	substitution.getLeftElement ( ).accept < void, RTEToXMLComposer::Formal > ( out );
+	substitution.getRightElement ( ).accept < void, RTEToXMLComposer::Formal > ( out );
 
 	out.emplace_back ( "substitution", sax::Token::TokenType::END_ELEMENT );
 }
 
-void RTEToXMLComposer::Formal::Visit ( void * userData, const FormalRTEIteration & iteration ) const {
-	std::deque < sax::Token > & out = * ( ( std::deque < sax::Token > * )userData );
-
+void RTEToXMLComposer::Formal::visit ( const FormalRTEIteration & iteration, std::deque < sax::Token > & out ) {
 	out.emplace_back ( "iteration", sax::Token::TokenType::START_ELEMENT );
 
 	alib::xmlApi < std::ranked_symbol < > >::compose ( out, iteration.getSubstitutionSymbol ( ).getSymbol ( ) );
-	iteration.getElement ( ).Accept ( userData, * this );
+	iteration.getElement ( ).accept < void, RTEToXMLComposer::Formal > ( out );
 
 	out.emplace_back ( "iteration", sax::Token::TokenType::END_ELEMENT );
 }
 
-void RTEToXMLComposer::Formal::Visit ( void * userData, const FormalRTESymbolAlphabet & symbol ) const {
-	std::deque < sax::Token > & out = * ( ( std::deque < sax::Token > * )userData );
-
+void RTEToXMLComposer::Formal::visit ( const FormalRTESymbolAlphabet & symbol, std::deque < sax::Token > & out ) {
 	out.emplace_back ( sax::Token ( "symbol", sax::Token::TokenType::START_ELEMENT ) );
 	alib::xmlApi < std::ranked_symbol < > >::compose ( out, symbol.getSymbol ( ) );
 
 	for ( const std::smart_ptr < const FormalRTESymbol > & element : symbol.getElements ( ) )
-		element->Accept ( userData, * this );
+		element->accept < void, RTEToXMLComposer::Formal > ( out );
 
 	out.emplace_back ( sax::Token ( "symbol", sax::Token::TokenType::END_ELEMENT ) );
 }
 
-void RTEToXMLComposer::Formal::Visit ( void * userData, const FormalRTESymbolSubst & symbol ) const {
-	std::deque < sax::Token > & out = * ( ( std::deque < sax::Token > * )userData );
-
+void RTEToXMLComposer::Formal::visit ( const FormalRTESymbolSubst & symbol, std::deque < sax::Token > & out ) {
 	out.emplace_back ( sax::Token ( "substSymbol", sax::Token::TokenType::START_ELEMENT ) );
 	alib::xmlApi < std::ranked_symbol < > >::compose ( out, symbol.getSymbol ( ) );
 
 	out.emplace_back ( sax::Token ( "substSymbol", sax::Token::TokenType::END_ELEMENT ) );
 }
 
-void RTEToXMLComposer::Formal::Visit ( void * userData, const FormalRTEEmpty & ) const {
-	std::deque < sax::Token > & out = * ( ( std::deque < sax::Token > * )userData );
-
+void RTEToXMLComposer::Formal::visit ( const FormalRTEEmpty &, std::deque < sax::Token > & out ) {
 	out.emplace_back ( "empty", sax::Token::TokenType::START_ELEMENT );
 	out.emplace_back ( "empty", sax::Token::TokenType::END_ELEMENT );
 }
@@ -85,6 +73,4 @@ void RTEToXMLComposer::composeAlphabet ( std::deque < sax::Token > & out, const
 	out.emplace_back ( "substSymbolAlphabet", sax::Token::TokenType::END_ELEMENT );
 }
 
-const RTEToXMLComposer::Formal RTEToXMLComposer::Formal::FORMAL;
-
 } /* namespace rte */
diff --git a/alib2data/src/rte/common/RTEToXMLComposer.h b/alib2data/src/rte/common/RTEToXMLComposer.h
index 344bf553223fda35425e3947130a2db0062f0a45..8261993e10673ccf8d9d761409a408fcfd743ded 100644
--- a/alib2data/src/rte/common/RTEToXMLComposer.h
+++ b/alib2data/src/rte/common/RTEToXMLComposer.h
@@ -17,18 +17,14 @@ class RTEToXMLComposer {
 public:
 	static void composeAlphabet ( std::deque < sax::Token > & out, const std::set < std::ranked_symbol < > > & alphabetF, const std::set < std::ranked_symbol < > > & alphabetK );
 
-	class Formal : public FormalRTEElement::Visitor {
+	class Formal {
 	public:
-		Formal ( ) { }
-
-		static const Formal FORMAL;
-	private:
-		void Visit ( void *, const FormalRTEAlternation & alternation ) const;
-		void Visit ( void *, const FormalRTEIteration & iteration ) const;
-		void Visit ( void *, const FormalRTESubstitution & concatenation ) const;
-		void Visit ( void *, const FormalRTESymbolAlphabet & symbol ) const;
-		void Visit ( void *, const FormalRTESymbolSubst & symbol ) const;
-		void Visit ( void *, const FormalRTEEmpty & empty ) const;
+		static void visit ( const FormalRTEAlternation & alternation, std::deque < sax::Token > & output );
+		static void visit ( const FormalRTEIteration & iteration, std::deque < sax::Token > & output );
+		static void visit ( const FormalRTESubstitution & concatenation, std::deque < sax::Token > & output );
+		static void visit ( const FormalRTESymbolAlphabet & symbol, std::deque < sax::Token > & output );
+		static void visit ( const FormalRTESymbolSubst & symbol, std::deque < sax::Token > & output );
+		static void visit ( const FormalRTEEmpty & empty, std::deque < sax::Token > & output );
 	};
 };
 
diff --git a/alib2data/src/rte/formal/FormalRTEAlternation.h b/alib2data/src/rte/formal/FormalRTEAlternation.h
index 1dcbcdf88046a10e56274423b50f9ac74853ac5d..6b8977d0f79da28b283b292c24b7e6f092c6ebc4 100644
--- a/alib2data/src/rte/formal/FormalRTEAlternation.h
+++ b/alib2data/src/rte/formal/FormalRTEAlternation.h
@@ -11,8 +11,8 @@ namespace rte {
  */
 class FormalRTEAlternation : public FormalRTEElement, public std::BinaryNode < std::smart_ptr < FormalRTEElement >, std::smart_ptr < FormalRTEElement >, FormalRTEAlternation > {
 public:
-	void Accept ( void * userData, const FormalRTEElement::Visitor & visitor ) const {
-		visitor.Visit ( userData, * this );
+	void accept ( FormalRTEElement::Visitor & visitor ) const {
+		visitor.visit ( * this );
 	}
 
 	explicit FormalRTEAlternation ( FormalRTEElement && left, FormalRTEElement && right );
diff --git a/alib2data/src/rte/formal/FormalRTEElement.h b/alib2data/src/rte/formal/FormalRTEElement.h
index 1e46b25a5d2f870e0fed3ebce749a13396b8db9a..75c6b5ec965da920358d6e5581879692cfa7a8bc 100644
--- a/alib2data/src/rte/formal/FormalRTEElement.h
+++ b/alib2data/src/rte/formal/FormalRTEElement.h
@@ -6,32 +6,61 @@
 #include <core/xmlApi.hpp>
 #include <set>
 #include <tree>
+#include <core/visitor.hpp>
+#include "../RTEFeatures.h"
 
 namespace rte {
 
-class FormalRTEAlternation;
-class FormalRTEIteration;
-class FormalRTESubstitution;
-class FormalRTESymbol;
-class FormalRTESymbolAlphabet;
-class FormalRTESymbolSubst;
-class FormalRTEEmpty;
-
-class FormalRTEElement;
-
 class FormalRTEElement : public alib::CommonBase < FormalRTEElement >, public std::BaseNode < FormalRTEElement > {
 public:
 	class Visitor {
 	public:
-		virtual void Visit ( void *, const FormalRTEAlternation & alternation ) const = 0;
-		virtual void Visit ( void *, const FormalRTEIteration & iteration ) const = 0;
-		virtual void Visit ( void *, const FormalRTESubstitution & substitution ) const = 0;
-		virtual void Visit ( void *, const FormalRTESymbolAlphabet & symbol ) const = 0;
-		virtual void Visit ( void *, const FormalRTESymbolSubst & symbol ) const = 0;
-		virtual void Visit ( void *, const FormalRTEEmpty & empty ) const = 0;
+		virtual void visit ( const FormalRTEAlternation & alternation ) = 0;
+		virtual void visit ( const FormalRTEIteration & iteration ) = 0;
+		virtual void visit ( const FormalRTESubstitution & substitution ) = 0;
+		virtual void visit ( const FormalRTESymbolAlphabet & symbol ) = 0;
+		virtual void visit ( const FormalRTESymbolSubst & symbol ) = 0;
+		virtual void visit ( const FormalRTEEmpty & empty ) = 0;
+	};
+
+	template < class ReturnType, class Visitorr, class ... Params >
+	class VisitorContext : public std::VisitorContextAux < ReturnType, Visitorr, Params ... >, public FormalRTEElement::Visitor {
+	public:
+		using std::VisitorContextAux < ReturnType, Visitorr, Params ... >::VisitorContextAux;
+
+		void visit ( const FormalRTEAlternation & inherit ) override {
+			this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
+		}
+
+		void visit ( const FormalRTEIteration & inherit ) override {
+			this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
+		}
+
+		void visit ( const FormalRTESubstitution & inherit ) override {
+			this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
+		}
+
+		void visit ( const FormalRTESymbolAlphabet & inherit ) override {
+			this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
+		}
+
+		void visit ( const FormalRTESymbolSubst & inherit ) override {
+			this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
+		}
+
+		void visit ( const FormalRTEEmpty & inherit ) override {
+			this->call ( inherit, std::make_index_sequence < sizeof ... ( Params ) > { } );
+		}
 	};
 
-	virtual void Accept ( void * userData, const FormalRTEElement::Visitor & visitor ) const = 0;
+	template < class ReturnType, class Visitorr, class ... Params >
+	ReturnType accept ( Params && ... params ) const {
+		VisitorContext < ReturnType, Visitorr, Params ... > context ( std::forward < Params > ( params ) ... );
+		accept ( context );
+		return context.getResult ( );
+	}
+
+	virtual void accept ( FormalRTEElement::Visitor & visitor ) const = 0;
 
 	/**
 	 * Traverses the regexp tree looking if particular Symbol is used in the regexp.
diff --git a/alib2data/src/rte/formal/FormalRTEEmpty.h b/alib2data/src/rte/formal/FormalRTEEmpty.h
index 1d6135de79d81155fba2c9d3d9faceea2c43d045..d2e04ec5811049601a329ff56e0a28c5e1cb76d0 100644
--- a/alib2data/src/rte/formal/FormalRTEEmpty.h
+++ b/alib2data/src/rte/formal/FormalRTEEmpty.h
@@ -11,8 +11,8 @@ namespace rte {
  */
 class FormalRTEEmpty : public FormalRTEElement {
 public:
-	void Accept ( void * userData, const FormalRTEElement::Visitor & visitor ) const {
-		visitor.Visit ( userData, * this );
+	void accept ( FormalRTEElement::Visitor & visitor ) const {
+		visitor.visit ( * this );
 	}
 
 	explicit FormalRTEEmpty ( );
diff --git a/alib2data/src/rte/formal/FormalRTEIteration.h b/alib2data/src/rte/formal/FormalRTEIteration.h
index d0d79b54fb4fd209bfcb1f339bd52506ed8fb4ac..ee04fdb6995b5b55835cfd11f848f6bd30563e7c 100644
--- a/alib2data/src/rte/formal/FormalRTEIteration.h
+++ b/alib2data/src/rte/formal/FormalRTEIteration.h
@@ -22,8 +22,8 @@ protected:
 	std::smart_ptr < FormalRTESymbolSubst > substitutionSymbol;
 
 public:
-	void Accept ( void * userData, const FormalRTEElement::Visitor & visitor ) const {
-		visitor.Visit ( userData, * this );
+	void accept ( FormalRTEElement::Visitor & visitor ) const {
+		visitor.visit ( * this );
 	}
 
 	explicit FormalRTEIteration ( FormalRTEElement &&, FormalRTESymbolSubst );
diff --git a/alib2data/src/rte/formal/FormalRTEStructure.cpp b/alib2data/src/rte/formal/FormalRTEStructure.cpp
index 5dea6d2b6f27e9796b3a310fbefc679200630280..3fbfac40c8c9254671c25aa0a27923706687165b 100644
--- a/alib2data/src/rte/formal/FormalRTEStructure.cpp
+++ b/alib2data/src/rte/formal/FormalRTEStructure.cpp
@@ -53,7 +53,7 @@ bool xmlApi < rte::FormalRTEStructure >::first ( const std::deque < sax::Token >
 }
 
 void xmlApi < rte::FormalRTEStructure >::compose ( std::deque < sax::Token > & output, const rte::FormalRTEStructure & data ) {
-	data.getStructure ( ).Accept ( ( void * ) & output, rte::RTEToXMLComposer::Formal::FORMAL );
+	data.getStructure ( ).accept < void, rte::RTEToXMLComposer::Formal > ( output );
 }
 
 } /* namespace alib */
diff --git a/alib2data/src/rte/formal/FormalRTESubstitution.h b/alib2data/src/rte/formal/FormalRTESubstitution.h
index 3bc956dda1aa221309a85128069ba4d9503f1684..907996509a3bc28bab2d38328c852643574ab0d9 100644
--- a/alib2data/src/rte/formal/FormalRTESubstitution.h
+++ b/alib2data/src/rte/formal/FormalRTESubstitution.h
@@ -16,8 +16,8 @@ protected:
 	std::smart_ptr < FormalRTESymbolSubst > substitutionSymbol; // substite this in left by right
 
 public:
-	void Accept ( void * userData, const FormalRTEElement::Visitor & visitor ) const {
-		visitor.Visit ( userData, * this );
+	void accept ( FormalRTEElement::Visitor & visitor ) const {
+		visitor.visit ( * this );
 	}
 
 	explicit FormalRTESubstitution ( FormalRTEElement && left, FormalRTEElement && right, FormalRTESymbolSubst substitutionSymbol );
diff --git a/alib2data/src/rte/formal/FormalRTESymbolAlphabet.h b/alib2data/src/rte/formal/FormalRTESymbolAlphabet.h
index 24599ab104156b1212d99d047c366ab3ccf8020b..a79972db24b3b8ae3fd9d45f842679ec02719dba 100644
--- a/alib2data/src/rte/formal/FormalRTESymbolAlphabet.h
+++ b/alib2data/src/rte/formal/FormalRTESymbolAlphabet.h
@@ -11,8 +11,8 @@ namespace rte {
  */
 class FormalRTESymbolAlphabet : public FormalRTESymbol, public std::VararyNode < std::smart_ptr < FormalRTESymbol >, std::smart_ptr < const FormalRTESymbol >, FormalRTESymbolAlphabet > {
 public:
-	void Accept ( void * userData, const FormalRTEElement::Visitor & visitor ) const {
-		visitor.Visit ( userData, * this );
+	void accept ( FormalRTEElement::Visitor & visitor ) const {
+		visitor.visit ( * this );
 	}
 
 	explicit FormalRTESymbolAlphabet ( std::ranked_symbol < > symbol );
diff --git a/alib2data/src/rte/formal/FormalRTESymbolSubst.h b/alib2data/src/rte/formal/FormalRTESymbolSubst.h
index 4be5896ba23ec5345efc159fb94ffb2f434f245a..b1ffc4617348b3c9d5f4e6b6810847bdf14b8472 100644
--- a/alib2data/src/rte/formal/FormalRTESymbolSubst.h
+++ b/alib2data/src/rte/formal/FormalRTESymbolSubst.h
@@ -11,8 +11,8 @@ namespace rte {
  */
 class FormalRTESymbolSubst : public FormalRTESymbol, public std::NullaryNode < FormalRTESymbolSubst > {
 public:
-	void Accept ( void * userData, const FormalRTEElement::Visitor & visitor ) const {
-		visitor.Visit ( userData, * this );
+	void accept ( FormalRTEElement::Visitor & visitor ) const {
+		visitor.visit ( * this );
 	}
 
 	explicit FormalRTESymbolSubst ( std::ranked_symbol < > symbol );