From dfd0f3b9111e84d04b9c9c5e54d5ac8b45af02df Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Thu, 7 Feb 2019 07:48:32 +0100 Subject: [PATCH] user documentation of grammar transform algos --- alib2algo/src/grammar/simplify/Rename.cpp | 13 ++- alib2algo/src/grammar/simplify/Rename.h | 13 +++ alib2algo/src/grammar/simplify/ToCNF.cpp | 62 +++++++++-- alib2algo/src/grammar/simplify/ToCNF.h | 94 ++++++++++++++++ alib2algo/src/grammar/simplify/ToGNF.cpp | 62 +++++++++-- alib2algo/src/grammar/simplify/ToGNF.h | 102 ++++++++++++++++++ alib2algo/src/grammar/simplify/Trim.cpp | 62 +++++++++-- alib2algo/src/grammar/simplify/Trim.h | 14 ++- .../simplify/UnproductiveSymbolsRemover.cpp | 62 +++++++++-- .../simplify/UnproductiveSymbolsRemover.h | 18 +++- .../simplify/UnreachableSymbolsRemover.cpp | 62 +++++++++-- .../simplify/UnreachableSymbolsRemover.h | 16 ++- 12 files changed, 526 insertions(+), 54 deletions(-) diff --git a/alib2algo/src/grammar/simplify/Rename.cpp b/alib2algo/src/grammar/simplify/Rename.cpp index 57f0cd654c..b8b8c466d1 100644 --- a/alib2algo/src/grammar/simplify/Rename.cpp +++ b/alib2algo/src/grammar/simplify/Rename.cpp @@ -12,8 +12,17 @@ namespace grammar { namespace simplify { -auto RenameRightRG = registration::AbstractRegister < Rename, grammar::RightRG < DefaultSymbolType, unsigned >, const grammar::RightRG < > & > ( Rename::rename ); -auto RenameLeftRG = registration::AbstractRegister < Rename, grammar::LeftRG < DefaultSymbolType, unsigned >, const grammar::LeftRG < > & > ( Rename::rename ); +auto RenameRightRG = registration::AbstractRegister < Rename, grammar::RightRG < DefaultSymbolType, unsigned >, const grammar::RightRG < > & > ( Rename::rename, "grammar" ).setDocumentation ( +"Renames nonterminal symbols in given grammar\n\ +\n\ +@param grammar the renamed grammar\n\ +@return grammar with nonterminal symbols renamed" ); + +auto RenameLeftRG = registration::AbstractRegister < Rename, grammar::LeftRG < DefaultSymbolType, unsigned >, const grammar::LeftRG < > & > ( Rename::rename, "grammar" ).setDocumentation ( +"Renames nonterminal symbols in given grammar\n\ +\n\ +@param grammar the renamed grammar\n\ +@return grammar with nonterminal symbols renamed" ); } /* namespace simplify */ diff --git a/alib2algo/src/grammar/simplify/Rename.h b/alib2algo/src/grammar/simplify/Rename.h index 195d73c82b..2cc1cce88c 100644 --- a/alib2algo/src/grammar/simplify/Rename.h +++ b/alib2algo/src/grammar/simplify/Rename.h @@ -21,9 +21,22 @@ namespace simplify { class Rename { public: + /** + * Renames nonterminal symbols in given grammar + * + * \tparam TerminalSymbolType the type of terminal symbol in the given grammar + * \tparam NonterminalSymbolType the type of nonterminal symbol in the given grammar + * + * \param grammar the renamed grammar + * + * \return grammar with nonterminal symbols renamed + */ template < class TerminalSymbolType, class NonterminalSymbolType > static grammar::RightRG < TerminalSymbolType, unsigned > rename ( const grammar::RightRG < TerminalSymbolType, NonterminalSymbolType > & grammar ); + /** + * \override + */ template < class TerminalSymbolType, class NonterminalSymbolType > static grammar::LeftRG < TerminalSymbolType, unsigned > rename ( const grammar::LeftRG < TerminalSymbolType, NonterminalSymbolType > & grammar ); }; diff --git a/alib2algo/src/grammar/simplify/ToCNF.cpp b/alib2algo/src/grammar/simplify/ToCNF.cpp index cc3496e996..72c048d74d 100644 --- a/alib2algo/src/grammar/simplify/ToCNF.cpp +++ b/alib2algo/src/grammar/simplify/ToCNF.cpp @@ -12,15 +12,59 @@ namespace grammar { namespace simplify { -auto ToCNFCFG = registration::AbstractRegister < ToCNF, grammar::CNF < DefaultSymbolType, ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > >, const grammar::CFG < > & > ( ToCNF::convert ); -auto ToCNFEpsilonFreeCFG = registration::AbstractRegister < ToCNF, grammar::CNF < DefaultSymbolType, ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > >, const grammar::EpsilonFreeCFG < > & > ( ToCNF::convert ); -auto ToCNFCNF = registration::AbstractRegister < ToCNF, grammar::CNF < >, const grammar::CNF < > & > ( ToCNF::convert ); -auto ToCNFGNF = registration::AbstractRegister < ToCNF, grammar::CNF < DefaultSymbolType, ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > >, const grammar::GNF < > & > ( ToCNF::convert ); -auto ToCNFLG = registration::AbstractRegister < ToCNF, grammar::CNF < DefaultSymbolType, ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > >, const grammar::LG < > & > ( ToCNF::convert ); -auto ToCNFLeftLG = registration::AbstractRegister < ToCNF, grammar::CNF < DefaultSymbolType, ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > >, const grammar::LeftLG < > & > ( ToCNF::convert ); -auto ToCNFLeftRG = registration::AbstractRegister < ToCNF, grammar::CNF < DefaultSymbolType, ext::variant < DefaultSymbolType, DefaultSymbolType > >, const grammar::LeftRG < > & > ( ToCNF::convert ); -auto ToCNFRightLG = registration::AbstractRegister < ToCNF, grammar::CNF < DefaultSymbolType, ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > >, const grammar::RightLG < > & > ( ToCNF::convert ); -auto ToCNFRightRG = registration::AbstractRegister < ToCNF, grammar::CNF < DefaultSymbolType, ext::variant < DefaultSymbolType, DefaultSymbolType > >, const grammar::RightRG < > & > ( ToCNF::convert ); +auto ToCNFCFG = registration::AbstractRegister < ToCNF, grammar::CNF < DefaultSymbolType, ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > >, const grammar::CFG < > & > ( ToCNF::convert, "grammar" ).setDocumentation ( +"Implements transformation of a grammar into chomsky's normal form.\n\ +\n\ +@param grammar the transformed grammar\n\ +@return an grammar in chomsky's normal form equivalent to the @p grammar" ); + +auto ToCNFEpsilonFreeCFG = registration::AbstractRegister < ToCNF, grammar::CNF < DefaultSymbolType, ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > >, const grammar::EpsilonFreeCFG < > & > ( ToCNF::convert, "grammar" ).setDocumentation ( +"Implements transformation of a grammar into chomsky's normal form.\n\ +\n\ +@param grammar the transformed grammar\n\ +@return an grammar in chomsky's normal form equivalent to the @p grammar" ); + +auto ToCNFCNF = registration::AbstractRegister < ToCNF, grammar::CNF < >, const grammar::CNF < > & > ( ToCNF::convert, "grammar" ).setDocumentation ( +"Implements transformation of a grammar into chomsky's normal form.\n\ +\n\ +@param grammar the transformed grammar\n\ +@return an grammar in chomsky's normal form equivalent to the @p grammar" ); + +auto ToCNFGNF = registration::AbstractRegister < ToCNF, grammar::CNF < DefaultSymbolType, ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > >, const grammar::GNF < > & > ( ToCNF::convert, "grammar" ).setDocumentation ( +"Implements transformation of a grammar into chomsky's normal form.\n\ +\n\ +@param grammar the transformed grammar\n\ +@return an grammar in chomsky's normal form equivalent to the @p grammar" ); + +auto ToCNFLG = registration::AbstractRegister < ToCNF, grammar::CNF < DefaultSymbolType, ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > >, const grammar::LG < > & > ( ToCNF::convert, "grammar" ).setDocumentation ( +"Implements transformation of a grammar into chomsky's normal form.\n\ +\n\ +@param grammar the transformed grammar\n\ +@return an grammar in chomsky's normal form equivalent to the @p grammar" ); + +auto ToCNFLeftLG = registration::AbstractRegister < ToCNF, grammar::CNF < DefaultSymbolType, ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > >, const grammar::LeftLG < > & > ( ToCNF::convert, "grammar" ).setDocumentation ( +"Implements transformation of a grammar into chomsky's normal form.\n\ +\n\ +@param grammar the transformed grammar\n\ +@return an grammar in chomsky's normal form equivalent to the @p grammar" ); + +auto ToCNFLeftRG = registration::AbstractRegister < ToCNF, grammar::CNF < DefaultSymbolType, ext::variant < DefaultSymbolType, DefaultSymbolType > >, const grammar::LeftRG < > & > ( ToCNF::convert, "grammar" ).setDocumentation ( +"Implements transformation of a grammar into chomsky's normal form.\n\ +\n\ +@param grammar the transformed grammar\n\ +@return an grammar in chomsky's normal form equivalent to the @p grammar" ); + +auto ToCNFRightLG = registration::AbstractRegister < ToCNF, grammar::CNF < DefaultSymbolType, ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > >, const grammar::RightLG < > & > ( ToCNF::convert, "grammar" ).setDocumentation ( +"Implements transformation of a grammar into chomsky's normal form.\n\ +\n\ +@param grammar the transformed grammar\n\ +@return an grammar in chomsky's normal form equivalent to the @p grammar" ); + +auto ToCNFRightRG = registration::AbstractRegister < ToCNF, grammar::CNF < DefaultSymbolType, ext::variant < DefaultSymbolType, DefaultSymbolType > >, const grammar::RightRG < > & > ( ToCNF::convert, "grammar" ).setDocumentation ( +"Implements transformation of a grammar into chomsky's normal form.\n\ +\n\ +@param grammar the transformed grammar\n\ +@return an grammar in chomsky's normal form equivalent to the @p grammar" ); } /* namespace simplify */ diff --git a/alib2algo/src/grammar/simplify/ToCNF.h b/alib2algo/src/grammar/simplify/ToCNF.h index dd7d4d2839..9035cd29ea 100644 --- a/alib2algo/src/grammar/simplify/ToCNF.h +++ b/alib2algo/src/grammar/simplify/ToCNF.h @@ -29,32 +29,126 @@ namespace grammar { namespace simplify { +/** + * Implements transformation of a grammar into chomsky's normal form. + * + */ class ToCNF { public: + /** + * Implements transformation of a grammar into chomsky's normal form. + * + * \tparam TerminalSymbolType the type of terminals in the transformed grammar + * \tparam NonterminalSymbolType the type of nonterminals in the transformed grammar + * + * \param grammar the transformed grammar + * + * \return an grammar in chomsky's normal form equivalent to the @p grammar + */ template < class TerminalSymbolType, class NonterminalSymbolType > static grammar::CNF < TerminalSymbolType, ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > > convert( const grammar::CFG < TerminalSymbolType, NonterminalSymbolType > & grammar ); + /** + * Implements transformation of a grammar into chomsky's normal form. + * + * \tparam TerminalSymbolType the type of terminals in the transformed grammar + * \tparam NonterminalSymbolType the type of nonterminals in the transformed grammar + * + * \param grammar the transformed grammar + * + * \return an grammar in chomsky's normal form equivalent to the @p grammar + */ template < class TerminalSymbolType, class NonterminalSymbolType > static grammar::CNF < TerminalSymbolType, ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > > convert( const grammar::EpsilonFreeCFG < TerminalSymbolType, NonterminalSymbolType > & grammar ); + /** + * Implements transformation of a grammar into chomsky's normal form. + * + * \tparam TerminalSymbolType the type of terminals in the transformed grammar + * \tparam NonterminalSymbolType the type of nonterminals in the transformed grammar + * + * \param grammar the transformed grammar + * + * \return an grammar in chomsky's normal form equivalent to the @p grammar + */ template < class TerminalSymbolType, class NonterminalSymbolType > static grammar::CNF < TerminalSymbolType, ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > > convert( const grammar::GNF < TerminalSymbolType, NonterminalSymbolType > & grammar ); + /** + * Implements transformation of a grammar into chomsky's normal form. + * + * \tparam TerminalSymbolType the type of terminals in the transformed grammar + * \tparam NonterminalSymbolType the type of nonterminals in the transformed grammar + * + * \param grammar the transformed grammar + * + * \return an grammar in chomsky's normal form equivalent to the @p grammar + */ template < class TerminalSymbolType, class NonterminalSymbolType > static grammar::CNF < TerminalSymbolType, NonterminalSymbolType > convert( const grammar::CNF < TerminalSymbolType, NonterminalSymbolType > & grammar ); + /** + * Implements transformation of a grammar into chomsky's normal form. + * + * \tparam TerminalSymbolType the type of terminals in the transformed grammar + * \tparam NonterminalSymbolType the type of nonterminals in the transformed grammar + * + * \param grammar the transformed grammar + * + * \return an grammar in chomsky's normal form equivalent to the @p grammar + */ template < class TerminalSymbolType, class NonterminalSymbolType > static grammar::CNF < TerminalSymbolType, ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > > convert( const grammar::LG < TerminalSymbolType, NonterminalSymbolType > & grammar ); + /** + * Implements transformation of a grammar into chomsky's normal form. + * + * \tparam TerminalSymbolType the type of terminals in the transformed grammar + * \tparam NonterminalSymbolType the type of nonterminals in the transformed grammar + * + * \param grammar the transformed grammar + * + * \return an grammar in chomsky's normal form equivalent to the @p grammar + */ template < class TerminalSymbolType, class NonterminalSymbolType > static grammar::CNF < TerminalSymbolType, ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > > convert( const grammar::LeftLG < TerminalSymbolType, NonterminalSymbolType > & grammar ); + /** + * Implements transformation of a grammar into chomsky's normal form. + * + * \tparam TerminalSymbolType the type of terminals in the transformed grammar + * \tparam NonterminalSymbolType the type of nonterminals in the transformed grammar + * + * \param grammar the transformed grammar + * + * \return an grammar in chomsky's normal form equivalent to the @p grammar + */ template < class TerminalSymbolType, class NonterminalSymbolType > static grammar::CNF < TerminalSymbolType, ext::variant < TerminalSymbolType, NonterminalSymbolType > > convert( const grammar::LeftRG < TerminalSymbolType, NonterminalSymbolType > & grammar ); + /** + * Implements transformation of a grammar into chomsky's normal form. + * + * \tparam TerminalSymbolType the type of terminals in the transformed grammar + * \tparam NonterminalSymbolType the type of nonterminals in the transformed grammar + * + * \param grammar the transformed grammar + * + * \return an grammar in chomsky's normal form equivalent to the @p grammar + */ template < class TerminalSymbolType, class NonterminalSymbolType > static grammar::CNF < TerminalSymbolType, ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > > convert( const grammar::RightLG < TerminalSymbolType, NonterminalSymbolType > & grammar ); + /** + * Implements transformation of a grammar into chomsky's normal form. + * + * \tparam TerminalSymbolType the type of terminals in the transformed grammar + * \tparam NonterminalSymbolType the type of nonterminals in the transformed grammar + * + * \param grammar the transformed grammar + * + * \return an grammar in chomsky's normal form equivalent to the @p grammar + */ template < class TerminalSymbolType, class NonterminalSymbolType > static grammar::CNF < TerminalSymbolType, ext::variant < TerminalSymbolType, NonterminalSymbolType > > convert( const grammar::RightRG < TerminalSymbolType, NonterminalSymbolType > & grammar ); }; diff --git a/alib2algo/src/grammar/simplify/ToGNF.cpp b/alib2algo/src/grammar/simplify/ToGNF.cpp index 412797732b..084c8f1113 100644 --- a/alib2algo/src/grammar/simplify/ToGNF.cpp +++ b/alib2algo/src/grammar/simplify/ToGNF.cpp @@ -12,15 +12,59 @@ namespace grammar { namespace simplify { -auto ToGNFCFG = registration::AbstractRegister < ToGNF, grammar::GNF < DefaultSymbolType, ext::variant < DefaultSymbolType, DefaultSymbolType > >, const grammar::CFG < > & > ( ToGNF::convert ); -auto ToGNFEpsilonFreeCFG = registration::AbstractRegister < ToGNF, grammar::GNF < DefaultSymbolType, ext::variant < DefaultSymbolType, DefaultSymbolType > >, const grammar::EpsilonFreeCFG < > & > ( ToGNF::convert ); -auto ToGNFCNF = registration::AbstractRegister < ToGNF, grammar::GNF < DefaultSymbolType, ext::variant < DefaultSymbolType, DefaultSymbolType > >, const grammar::CNF < > & > ( ToGNF::convert ); -auto ToGNFGNF = registration::AbstractRegister < ToGNF, grammar::GNF < >, const grammar::GNF < > & > ( ToGNF::convert ); -auto ToGNFLG = registration::AbstractRegister < ToGNF, grammar::GNF < DefaultSymbolType, ext::variant < DefaultSymbolType, DefaultSymbolType > >, const grammar::LG < > & > ( ToGNF::convert ); -auto ToGNFLeftLG = registration::AbstractRegister < ToGNF, grammar::GNF < DefaultSymbolType, ext::variant < DefaultSymbolType, DefaultSymbolType > >, const grammar::LeftLG < > & > ( ToGNF::convert ); -auto ToGNFLeftRG = registration::AbstractRegister < ToGNF, grammar::RightRG < >, const grammar::LeftRG < > & > ( ToGNF::convert ); -auto ToGNFRightLG = registration::AbstractRegister < ToGNF, grammar::GNF < DefaultSymbolType, ext::variant < DefaultSymbolType, DefaultSymbolType > >, const grammar::RightLG < > & > ( ToGNF::convert ); -auto ToGNFRightRG = registration::AbstractRegister < ToGNF, grammar::RightRG < >, const grammar::RightRG < > & > ( ToGNF::convert ); +auto ToGNFCFG = registration::AbstractRegister < ToGNF, grammar::GNF < DefaultSymbolType, ext::variant < DefaultSymbolType, DefaultSymbolType > >, const grammar::CFG < > & > ( ToGNF::convert, "grammar" ).setDocumentation ( +"Implements transformation of a grammar into greibach normal form.\n\ +\n\ +@param grammar the transformed grammar\n\ +@return an grammar in greibach normal form equivalent to the @p grammar" ); + +auto ToGNFEpsilonFreeCFG = registration::AbstractRegister < ToGNF, grammar::GNF < DefaultSymbolType, ext::variant < DefaultSymbolType, DefaultSymbolType > >, const grammar::EpsilonFreeCFG < > & > ( ToGNF::convert, "grammar" ).setDocumentation ( +"Implements transformation of a grammar into greibach normal form.\n\ +\n\ +@param grammar the transformed grammar\n\ +@return an grammar in greibach normal form equivalent to the @p grammar" ); + +auto ToGNFCNF = registration::AbstractRegister < ToGNF, grammar::GNF < DefaultSymbolType, ext::variant < DefaultSymbolType, DefaultSymbolType > >, const grammar::CNF < > & > ( ToGNF::convert, "grammar" ).setDocumentation ( +"Implements transformation of a grammar into greibach normal form.\n\ +\n\ +@param grammar the transformed grammar\n\ +@return an grammar in greibach normal form equivalent to the @p grammar" ); + +auto ToGNFGNF = registration::AbstractRegister < ToGNF, grammar::GNF < >, const grammar::GNF < > & > ( ToGNF::convert, "grammar" ).setDocumentation ( +"Implements transformation of a grammar into greibach normal form.\n\ +\n\ +@param grammar the transformed grammar\n\ +@return an grammar in greibach normal form equivalent to the @p grammar" ); + +auto ToGNFLG = registration::AbstractRegister < ToGNF, grammar::GNF < DefaultSymbolType, ext::variant < DefaultSymbolType, DefaultSymbolType > >, const grammar::LG < > & > ( ToGNF::convert, "grammar" ).setDocumentation ( +"Implements transformation of a grammar into greibach normal form.\n\ +\n\ +@param grammar the transformed grammar\n\ +@return an grammar in greibach normal form equivalent to the @p grammar" ); + +auto ToGNFLeftLG = registration::AbstractRegister < ToGNF, grammar::GNF < DefaultSymbolType, ext::variant < DefaultSymbolType, DefaultSymbolType > >, const grammar::LeftLG < > & > ( ToGNF::convert, "grammar" ).setDocumentation ( +"Implements transformation of a grammar into greibach normal form.\n\ +\n\ +@param grammar the transformed grammar\n\ +@return an grammar in greibach normal form equivalent to the @p grammar" ); + +auto ToGNFLeftRG = registration::AbstractRegister < ToGNF, grammar::RightRG < >, const grammar::LeftRG < > & > ( ToGNF::convert, "grammar" ).setDocumentation ( +"Implements transformation of a grammar into greibach normal form.\n\ +\n\ +@param grammar the transformed grammar\n\ +@return an grammar in greibach normal form equivalent to the @p grammar" ); + +auto ToGNFRightLG = registration::AbstractRegister < ToGNF, grammar::GNF < DefaultSymbolType, ext::variant < DefaultSymbolType, DefaultSymbolType > >, const grammar::RightLG < > & > ( ToGNF::convert, "grammar" ).setDocumentation ( +"Implements transformation of a grammar into greibach normal form.\n\ +\n\ +@param grammar the transformed grammar\n\ +@return an grammar in greibach normal form equivalent to the @p grammar" ); + +auto ToGNFRightRG = registration::AbstractRegister < ToGNF, grammar::RightRG < >, const grammar::RightRG < > & > ( ToGNF::convert, "grammar" ).setDocumentation ( +"Implements transformation of a grammar into greibach normal form.\n\ +\n\ +@param grammar the transformed grammar\n\ +@return an grammar in greibach normal form equivalent to the @p grammar" ); } /* namespace simplify */ diff --git a/alib2algo/src/grammar/simplify/ToGNF.h b/alib2algo/src/grammar/simplify/ToGNF.h index a441a997ff..a6bd4f1515 100644 --- a/alib2algo/src/grammar/simplify/ToGNF.h +++ b/alib2algo/src/grammar/simplify/ToGNF.h @@ -31,6 +31,10 @@ namespace grammar { namespace simplify { +/** + * Implements transformation of a grammar into greibach normal form. + * + */ class ToGNF { template < class TerminalSymbolType, class NonterminalSymbolType > static grammar::EpsilonFreeCFG < TerminalSymbolType, NonterminalSymbolType > assignNonterminals(const grammar::EpsilonFreeCFG < TerminalSymbolType, NonterminalSymbolType > & origGrammar); @@ -38,22 +42,120 @@ class ToGNF { static grammar::GNF < TerminalSymbolType, ext::variant < TerminalSymbolType, NonterminalSymbolType > > convertInternal( const grammar::EpsilonFreeCFG < TerminalSymbolType, NonterminalSymbolType > & origGrammar ); public: + /** + * Implements transformation of a grammar into greibach normal form. + * + * \tparam TerminalSymbolType the type of terminals in the transformed grammar + * \tparam NonterminalSymbolType the type of nonterminals in the transformed grammar + * + * \param grammar the transformed grammar + * + * \return an grammar in greibach normal form equivalent to the @p grammar + */ template < class TerminalSymbolType, class NonterminalSymbolType > static grammar::GNF < TerminalSymbolType, ext::variant < TerminalSymbolType, NonterminalSymbolType > > convert( const grammar::CFG < TerminalSymbolType, NonterminalSymbolType > & grammar ); + + /** + * Implements transformation of a grammar into greibach normal form. + * + * \tparam TerminalSymbolType the type of terminals in the transformed grammar + * \tparam NonterminalSymbolType the type of nonterminals in the transformed grammar + * + * \param grammar the transformed grammar + * + * \return an grammar in greibach normal form equivalent to the @p grammar + */ template < class TerminalSymbolType, class NonterminalSymbolType > static grammar::GNF < TerminalSymbolType, ext::variant < TerminalSymbolType, NonterminalSymbolType > > convert ( const grammar::EpsilonFreeCFG < TerminalSymbolType, NonterminalSymbolType > & grammar ); + + /** + * Implements transformation of a grammar into greibach normal form. + * + * \tparam TerminalSymbolType the type of terminals in the transformed grammar + * \tparam NonterminalSymbolType the type of nonterminals in the transformed grammar + * + * \param grammar the transformed grammar + * + * \return an grammar in greibach normal form equivalent to the @p grammar + */ template < class TerminalSymbolType, class NonterminalSymbolType > static grammar::GNF < TerminalSymbolType, ext::variant < TerminalSymbolType, NonterminalSymbolType > > convert( const grammar::CNF < TerminalSymbolType, NonterminalSymbolType > & grammar ); + + /** + * Implements transformation of a grammar into greibach normal form. + * + * \tparam TerminalSymbolType the type of terminals in the transformed grammar + * \tparam NonterminalSymbolType the type of nonterminals in the transformed grammar + * + * \param grammar the transformed grammar + * + * \return an grammar in greibach normal form equivalent to the @p grammar + */ template < class TerminalSymbolType, class NonterminalSymbolType > static grammar::GNF < TerminalSymbolType, NonterminalSymbolType > convert( const grammar::GNF < TerminalSymbolType, NonterminalSymbolType > & grammar ); + + /** + * Implements transformation of a grammar into greibach normal form. + * + * \tparam TerminalSymbolType the type of terminals in the transformed grammar + * \tparam NonterminalSymbolType the type of nonterminals in the transformed grammar + * + * \param grammar the transformed grammar + * + * \return an grammar in greibach normal form equivalent to the @p grammar + */ template < class TerminalSymbolType, class NonterminalSymbolType > static grammar::GNF < TerminalSymbolType, ext::variant < TerminalSymbolType, NonterminalSymbolType > > convert( const grammar::LG < TerminalSymbolType, NonterminalSymbolType > & grammar ); + + /** + * Implements transformation of a grammar into greibach normal form. + * + * \tparam TerminalSymbolType the type of terminals in the transformed grammar + * \tparam NonterminalSymbolType the type of nonterminals in the transformed grammar + * + * \param grammar the transformed grammar + * + * \return an grammar in greibach normal form equivalent to the @p grammar + */ template < class TerminalSymbolType, class NonterminalSymbolType > static grammar::GNF < TerminalSymbolType, ext::variant < TerminalSymbolType, NonterminalSymbolType > > convert( const grammar::LeftLG < TerminalSymbolType, NonterminalSymbolType > & grammar ); + + /** + * Implements transformation of a grammar into greibach normal form. + * + * \tparam TerminalSymbolType the type of terminals in the transformed grammar + * \tparam NonterminalSymbolType the type of nonterminals in the transformed grammar + * + * \param grammar the transformed grammar + * + * \return an grammar in greibach normal form equivalent to the @p grammar + */ template < class TerminalSymbolType, class NonterminalSymbolType > static grammar::RightRG < TerminalSymbolType, NonterminalSymbolType > convert( const grammar::LeftRG < TerminalSymbolType, NonterminalSymbolType > & grammar ); + + /** + * Implements transformation of a grammar into greibach normal form. + * + * \tparam TerminalSymbolType the type of terminals in the transformed grammar + * \tparam NonterminalSymbolType the type of nonterminals in the transformed grammar + * + * \param grammar the transformed grammar + * + * \return an grammar in greibach normal form equivalent to the @p grammar + */ template < class TerminalSymbolType, class NonterminalSymbolType > static grammar::GNF < TerminalSymbolType, ext::variant < TerminalSymbolType, NonterminalSymbolType > > convert( const grammar::RightLG < TerminalSymbolType, NonterminalSymbolType > & grammar ); + + /** + * Implements transformation of a grammar into greibach normal form. + * + * \tparam TerminalSymbolType the type of terminals in the transformed grammar + * \tparam NonterminalSymbolType the type of nonterminals in the transformed grammar + * + * \param grammar the transformed grammar + * + * \return an grammar in greibach normal form equivalent to the @p grammar + */ template < class TerminalSymbolType, class NonterminalSymbolType > static grammar::RightRG < TerminalSymbolType, NonterminalSymbolType > convert( const grammar::RightRG < TerminalSymbolType, NonterminalSymbolType > & grammar ); }; diff --git a/alib2algo/src/grammar/simplify/Trim.cpp b/alib2algo/src/grammar/simplify/Trim.cpp index 5a0897ee39..7c326d530f 100644 --- a/alib2algo/src/grammar/simplify/Trim.cpp +++ b/alib2algo/src/grammar/simplify/Trim.cpp @@ -12,15 +12,59 @@ namespace grammar { namespace simplify { -auto TrimCFG = registration::AbstractRegister < Trim, grammar::CFG < >, const grammar::CFG < > & > ( Trim::trim ); -auto TrimEpsilonFreeCFG = registration::AbstractRegister < Trim, grammar::EpsilonFreeCFG < >, const grammar::EpsilonFreeCFG < > & > ( Trim::trim ); -auto TrimGNF = registration::AbstractRegister < Trim, grammar::GNF < >, const grammar::GNF < > & > ( Trim::trim ); -auto TrimCNF = registration::AbstractRegister < Trim, grammar::CNF < >, const grammar::CNF < > & > ( Trim::trim ); -auto TrimLG = registration::AbstractRegister < Trim, grammar::LG < >, const grammar::LG < > & > ( Trim::trim ); -auto TrimLeftLG = registration::AbstractRegister < Trim, grammar::LeftLG < >, const grammar::LeftLG < > & > ( Trim::trim ); -auto TrimLeftRG = registration::AbstractRegister < Trim, grammar::LeftRG < >, const grammar::LeftRG < > & > ( Trim::trim ); -auto TrimRightLG = registration::AbstractRegister < Trim, grammar::RightLG < >, const grammar::RightLG < > & > ( Trim::trim ); -auto TrimRightRG = registration::AbstractRegister < Trim, grammar::RightRG < >, const grammar::RightRG < > & > ( Trim::trim ); +auto TrimCFG = registration::AbstractRegister < Trim, grammar::CFG < >, const grammar::CFG < > & > ( Trim::trim, "grammar" ).setDocumentation ( +"Removes unproductive and unreachable symbols from the given grammar. Uses first the @sa UnproductiveSymbolsRemover and next @sa UnreachableSymbolsRemover in the process.\n\ +\n\ +@param grammar the context free grammar to trim\n\ +@return the trimmed grammar equivalent to @p grammar" ); + +auto TrimEpsilonFreeCFG = registration::AbstractRegister < Trim, grammar::EpsilonFreeCFG < >, const grammar::EpsilonFreeCFG < > & > ( Trim::trim, "grammar" ).setDocumentation ( +"Removes unproductive and unreachable symbols from the given grammar. Uses first the @sa UnproductiveSymbolsRemover and next @sa UnreachableSymbolsRemover in the process.\n\ +\n\ +@param grammar the context free grammar to trim\n\ +@return the trimmed grammar equivalent to @p grammar" ); + +auto TrimGNF = registration::AbstractRegister < Trim, grammar::GNF < >, const grammar::GNF < > & > ( Trim::trim, "grammar" ).setDocumentation ( +"Removes unproductive and unreachable symbols from the given grammar. Uses first the @sa UnproductiveSymbolsRemover and next @sa UnreachableSymbolsRemover in the process.\n\ +\n\ +@param grammar the context free grammar to trim\n\ +@return the trimmed grammar equivalent to @p grammar" ); + +auto TrimCNF = registration::AbstractRegister < Trim, grammar::CNF < >, const grammar::CNF < > & > ( Trim::trim, "grammar" ).setDocumentation ( +"Removes unproductive and unreachable symbols from the given grammar. Uses first the @sa UnproductiveSymbolsRemover and next @sa UnreachableSymbolsRemover in the process.\n\ +\n\ +@param grammar the context free grammar to trim\n\ +@return the trimmed grammar equivalent to @p grammar" ); + +auto TrimLG = registration::AbstractRegister < Trim, grammar::LG < >, const grammar::LG < > & > ( Trim::trim, "grammar" ).setDocumentation ( +"Removes unproductive and unreachable symbols from the given grammar. Uses first the @sa UnproductiveSymbolsRemover and next @sa UnreachableSymbolsRemover in the process.\n\ +\n\ +@param grammar the context free grammar to trim\n\ +@return the trimmed grammar equivalent to @p grammar" ); + +auto TrimLeftLG = registration::AbstractRegister < Trim, grammar::LeftLG < >, const grammar::LeftLG < > & > ( Trim::trim, "grammar" ).setDocumentation ( +"Removes unproductive and unreachable symbols from the given grammar. Uses first the @sa UnproductiveSymbolsRemover and next @sa UnreachableSymbolsRemover in the process.\n\ +\n\ +@param grammar the context free grammar to trim\n\ +@return the trimmed grammar equivalent to @p grammar" ); + +auto TrimLeftRG = registration::AbstractRegister < Trim, grammar::LeftRG < >, const grammar::LeftRG < > & > ( Trim::trim, "grammar" ).setDocumentation ( +"Removes unproductive and unreachable symbols from the given grammar. Uses first the @sa UnproductiveSymbolsRemover and next @sa UnreachableSymbolsRemover in the process.\n\ +\n\ +@param grammar the context free grammar to trim\n\ +@return the trimmed grammar equivalent to @p grammar" ); + +auto TrimRightLG = registration::AbstractRegister < Trim, grammar::RightLG < >, const grammar::RightLG < > & > ( Trim::trim, "grammar" ).setDocumentation ( +"Removes unproductive and unreachable symbols from the given grammar. Uses first the @sa UnproductiveSymbolsRemover and next @sa UnreachableSymbolsRemover in the process.\n\ +\n\ +@param grammar the context free grammar to trim\n\ +@return the trimmed grammar equivalent to @p grammar" ); + +auto TrimRightRG = registration::AbstractRegister < Trim, grammar::RightRG < >, const grammar::RightRG < > & > ( Trim::trim, "grammar" ).setDocumentation ( +"Removes unproductive and unreachable symbols from the given grammar. Uses first the @sa UnproductiveSymbolsRemover and next @sa UnreachableSymbolsRemover in the process.\n\ +\n\ +@param grammar the context free grammar to trim\n\ +@return the trimmed grammar equivalent to @p grammar" ); } /* namespace simplify */ diff --git a/alib2algo/src/grammar/simplify/Trim.h b/alib2algo/src/grammar/simplify/Trim.h index f6dc6834ef..3f826cf199 100644 --- a/alib2algo/src/grammar/simplify/Trim.h +++ b/alib2algo/src/grammar/simplify/Trim.h @@ -26,12 +26,22 @@ namespace grammar { namespace simplify { /** - * Implements algorithms from Melichar, chapter 3.3 + * Algorithm for the removal of dead symbols from a context free grammar. + * Firstly, it calls the unproductive symbols removal algorithm, then unreachable symbols removal algorithm. + * + * @sa grammar::simplify::UnproduciveSymbolsRemover + * @sa grammar::simplify::UnreachableSymbolsRemover */ class Trim { public: /** - * Removes unproductive and useless symbols - Melichar 3.12 + * Removes unproductive and unreachable symbols from the given grammar. Uses first the @sa UnproductiveSymbolsRemover and next @sa UnreachableSymbolsRemover in the process. + * + * \tparam T type of a finite automaton + * + * \param grammar the context free grammar to trim + * + * \return the trimmed grammar equivalent to @p grammar */ template<class T> static T trim( const T & grammar ); diff --git a/alib2algo/src/grammar/simplify/UnproductiveSymbolsRemover.cpp b/alib2algo/src/grammar/simplify/UnproductiveSymbolsRemover.cpp index 21c1149715..90558659e3 100644 --- a/alib2algo/src/grammar/simplify/UnproductiveSymbolsRemover.cpp +++ b/alib2algo/src/grammar/simplify/UnproductiveSymbolsRemover.cpp @@ -12,15 +12,59 @@ namespace grammar { namespace simplify { -auto UnproductiveSymbolsRemoverCFG = registration::AbstractRegister < UnproductiveSymbolsRemover, grammar::CFG < >, const grammar::CFG < > & > ( UnproductiveSymbolsRemover::remove ); -auto UnproductiveSymbolsRemoverEpsilonFreeCFG = registration::AbstractRegister < UnproductiveSymbolsRemover, grammar::EpsilonFreeCFG < >, const grammar::EpsilonFreeCFG < > & > ( UnproductiveSymbolsRemover::remove ); -auto UnproductiveSymbolsRemoverGNF = registration::AbstractRegister < UnproductiveSymbolsRemover, grammar::GNF < >, const grammar::GNF < > & > ( UnproductiveSymbolsRemover::remove ); -auto UnproductiveSymbolsRemoverCNF = registration::AbstractRegister < UnproductiveSymbolsRemover, grammar::CNF < >, const grammar::CNF < > & > ( UnproductiveSymbolsRemover::remove ); -auto UnproductiveSymbolsRemoverLG = registration::AbstractRegister < UnproductiveSymbolsRemover, grammar::LG < >, const grammar::LG < > & > ( UnproductiveSymbolsRemover::remove ); -auto UnproductiveSymbolsRemoverLeftLG = registration::AbstractRegister < UnproductiveSymbolsRemover, grammar::LeftLG < >, const grammar::LeftLG < > & > ( UnproductiveSymbolsRemover::remove ); -auto UnproductiveSymbolsRemoverLeftRG = registration::AbstractRegister < UnproductiveSymbolsRemover, grammar::LeftRG < >, const grammar::LeftRG < > & > ( UnproductiveSymbolsRemover::remove ); -auto UnproductiveSymbolsRemoverRightLG = registration::AbstractRegister < UnproductiveSymbolsRemover, grammar::RightLG < >, const grammar::RightLG < > & > ( UnproductiveSymbolsRemover::remove ); -auto UnproductiveSymbolsRemoverRightRG = registration::AbstractRegister < UnproductiveSymbolsRemover, grammar::RightRG < >, const grammar::RightRG < > & > ( UnproductiveSymbolsRemover::remove ); +auto UnproductiveSymbolsRemoverCFG = registration::AbstractRegister < UnproductiveSymbolsRemover, grammar::CFG < >, const grammar::CFG < > & > ( UnproductiveSymbolsRemover::remove, "grammar" ).setDocumentation ( +"Removes unproductive symbols.\n\ +\n\ +@param grammar the modified grammar\n\ +@return grammar equivalent to @p grammar without unproductive symbols" ); + +auto UnproductiveSymbolsRemoverEpsilonFreeCFG = registration::AbstractRegister < UnproductiveSymbolsRemover, grammar::EpsilonFreeCFG < >, const grammar::EpsilonFreeCFG < > & > ( UnproductiveSymbolsRemover::remove, "grammar" ).setDocumentation ( +"Removes unproductive symbols.\n\ +\n\ +@param grammar the modified grammar\n\ +@return grammar equivalent to @p grammar without unproductive symbols" ); + +auto UnproductiveSymbolsRemoverGNF = registration::AbstractRegister < UnproductiveSymbolsRemover, grammar::GNF < >, const grammar::GNF < > & > ( UnproductiveSymbolsRemover::remove, "grammar" ).setDocumentation ( +"Removes unproductive symbols.\n\ +\n\ +@param grammar the modified grammar\n\ +@return grammar equivalent to @p grammar without unproductive symbols" ); + +auto UnproductiveSymbolsRemoverCNF = registration::AbstractRegister < UnproductiveSymbolsRemover, grammar::CNF < >, const grammar::CNF < > & > ( UnproductiveSymbolsRemover::remove, "grammar" ).setDocumentation ( +"Removes unproductive symbols.\n\ +\n\ +@param grammar the modified grammar\n\ +@return grammar equivalent to @p grammar without unproductive symbols" ); + +auto UnproductiveSymbolsRemoverLG = registration::AbstractRegister < UnproductiveSymbolsRemover, grammar::LG < >, const grammar::LG < > & > ( UnproductiveSymbolsRemover::remove, "grammar" ).setDocumentation ( +"Removes unproductive symbols.\n\ +\n\ +@param grammar the modified grammar\n\ +@return grammar equivalent to @p grammar without unproductive symbols" ); + +auto UnproductiveSymbolsRemoverLeftLG = registration::AbstractRegister < UnproductiveSymbolsRemover, grammar::LeftLG < >, const grammar::LeftLG < > & > ( UnproductiveSymbolsRemover::remove, "grammar" ).setDocumentation ( +"Removes unproductive symbols.\n\ +\n\ +@param grammar the modified grammar\n\ +@return grammar equivalent to @p grammar without unproductive symbols" ); + +auto UnproductiveSymbolsRemoverLeftRG = registration::AbstractRegister < UnproductiveSymbolsRemover, grammar::LeftRG < >, const grammar::LeftRG < > & > ( UnproductiveSymbolsRemover::remove, "grammar" ).setDocumentation ( +"Removes unproductive symbols.\n\ +\n\ +@param grammar the modified grammar\n\ +@return grammar equivalent to @p grammar without unproductive symbols" ); + +auto UnproductiveSymbolsRemoverRightLG = registration::AbstractRegister < UnproductiveSymbolsRemover, grammar::RightLG < >, const grammar::RightLG < > & > ( UnproductiveSymbolsRemover::remove, "grammar" ).setDocumentation ( +"Removes unproductive symbols.\n\ +\n\ +@param grammar the modified grammar\n\ +@return grammar equivalent to @p grammar without unproductive symbols" ); + +auto UnproductiveSymbolsRemoverRightRG = registration::AbstractRegister < UnproductiveSymbolsRemover, grammar::RightRG < >, const grammar::RightRG < > & > ( UnproductiveSymbolsRemover::remove, "grammar" ).setDocumentation ( +"Removes unproductive symbols.\n\ +\n\ +@param grammar the modified grammar\n\ +@return grammar equivalent to @p grammar without unproductive symbols" ); } /* namespace simplify */ diff --git a/alib2algo/src/grammar/simplify/UnproductiveSymbolsRemover.h b/alib2algo/src/grammar/simplify/UnproductiveSymbolsRemover.h index 46627dcb9e..f74b6dbcb3 100644 --- a/alib2algo/src/grammar/simplify/UnproductiveSymbolsRemover.h +++ b/alib2algo/src/grammar/simplify/UnproductiveSymbolsRemover.h @@ -32,12 +32,24 @@ namespace grammar { namespace simplify { /** - * Implements algorithms from Melichar, chapter 3.3 + * Algorithm for the removal of unproductive symbols from a context free grammar. + * Unproductive symbol is a nonterminal symbol that can't be transformed to sentece by any sequence of derivations. + * + * @sa grammar::simplify::Trim + * @sa grammar::properties::ReachableSymbols */ class UnproductiveSymbolsRemover { public: - /** - * Removes unproductive (or useless - terminology) symbols - Melichar 3.12 + /* + * Removes unproductive symbols. + * + * \tparam T the type of modified grammar + * \tparam TerminalSymbolType the type of terminal symbols of the grammar + * \tparam NonterminalSymbolType the type of nonterminal symbols of the grammar + * + * \param grammar the modified grammar + * + * \return grammar equivalent to @p grammar without unproductive symbols */ template < class T, class TerminalSymbolType = typename grammar::TerminalSymbolTypeOfGrammar < T >, class NonterminalSymbolType = typename grammar::NonterminalSymbolTypeOfGrammar < T > > static T remove( const T & grammar ); diff --git a/alib2algo/src/grammar/simplify/UnreachableSymbolsRemover.cpp b/alib2algo/src/grammar/simplify/UnreachableSymbolsRemover.cpp index 9f63058122..c53597009f 100644 --- a/alib2algo/src/grammar/simplify/UnreachableSymbolsRemover.cpp +++ b/alib2algo/src/grammar/simplify/UnreachableSymbolsRemover.cpp @@ -12,15 +12,59 @@ namespace grammar { namespace simplify { -auto UnreachableSymbolsRemoverCFG = registration::AbstractRegister < UnreachableSymbolsRemover, grammar::CFG < >, const grammar::CFG < > & > ( UnreachableSymbolsRemover::remove ); -auto UnreachableSymbolsRemoverEpsilonFreeCFG = registration::AbstractRegister < UnreachableSymbolsRemover, grammar::EpsilonFreeCFG < >, const grammar::EpsilonFreeCFG < > & > ( UnreachableSymbolsRemover::remove ); -auto UnreachableSymbolsRemoverGNF = registration::AbstractRegister < UnreachableSymbolsRemover, grammar::GNF < >, const grammar::GNF < > & > ( UnreachableSymbolsRemover::remove ); -auto UnreachableSymbolsRemoverCNF = registration::AbstractRegister < UnreachableSymbolsRemover, grammar::CNF < >, const grammar::CNF < > & > ( UnreachableSymbolsRemover::remove ); -auto UnreachableSymbolsRemoverLG = registration::AbstractRegister < UnreachableSymbolsRemover, grammar::LG < >, const grammar::LG < > & > ( UnreachableSymbolsRemover::remove ); -auto UnreachableSymbolsRemoverLeftLG = registration::AbstractRegister < UnreachableSymbolsRemover, grammar::LeftLG < >, const grammar::LeftLG < > & > ( UnreachableSymbolsRemover::remove ); -auto UnreachableSymbolsRemoverLeftRG = registration::AbstractRegister < UnreachableSymbolsRemover, grammar::LeftRG < >, const grammar::LeftRG < > & > ( UnreachableSymbolsRemover::remove ); -auto UnreachableSymbolsRemoverRightLG = registration::AbstractRegister < UnreachableSymbolsRemover, grammar::RightLG < >, const grammar::RightLG < > & > ( UnreachableSymbolsRemover::remove ); -auto UnreachableSymbolsRemoverRightRG = registration::AbstractRegister < UnreachableSymbolsRemover, grammar::RightRG < >, const grammar::RightRG < > & > ( UnreachableSymbolsRemover::remove ); +auto UnreachableSymbolsRemoverCFG = registration::AbstractRegister < UnreachableSymbolsRemover, grammar::CFG < >, const grammar::CFG < > & > ( UnreachableSymbolsRemover::remove, "grammar" ).setDocumentation ( +"Removes unreachable symbols.\n\ +\n\ +@param grammar the modified grammar\n\ +@return grammar equivalent to @p grammar without unreachable symbols" ); + +auto UnreachableSymbolsRemoverEpsilonFreeCFG = registration::AbstractRegister < UnreachableSymbolsRemover, grammar::EpsilonFreeCFG < >, const grammar::EpsilonFreeCFG < > & > ( UnreachableSymbolsRemover::remove, "grammar" ).setDocumentation ( +"Removes unreachable symbols.\n\ +\n\ +@param grammar the modified grammar\n\ +@return grammar equivalent to @p grammar without unreachable symbols" ); + +auto UnreachableSymbolsRemoverGNF = registration::AbstractRegister < UnreachableSymbolsRemover, grammar::GNF < >, const grammar::GNF < > & > ( UnreachableSymbolsRemover::remove, "grammar" ).setDocumentation ( +"Removes unreachable symbols.\n\ +\n\ +@param grammar the modified grammar\n\ +@return grammar equivalent to @p grammar without unreachable symbols" ); + +auto UnreachableSymbolsRemoverCNF = registration::AbstractRegister < UnreachableSymbolsRemover, grammar::CNF < >, const grammar::CNF < > & > ( UnreachableSymbolsRemover::remove, "grammar" ).setDocumentation ( +"Removes unreachable symbols.\n\ +\n\ +@param grammar the modified grammar\n\ +@return grammar equivalent to @p grammar without unreachable symbols" ); + +auto UnreachableSymbolsRemoverLG = registration::AbstractRegister < UnreachableSymbolsRemover, grammar::LG < >, const grammar::LG < > & > ( UnreachableSymbolsRemover::remove, "grammar" ).setDocumentation ( +"Removes unreachable symbols.\n\ +\n\ +@param grammar the modified grammar\n\ +@return grammar equivalent to @p grammar without unreachable symbols" ); + +auto UnreachableSymbolsRemoverLeftLG = registration::AbstractRegister < UnreachableSymbolsRemover, grammar::LeftLG < >, const grammar::LeftLG < > & > ( UnreachableSymbolsRemover::remove, "grammar" ).setDocumentation ( +"Removes unreachable symbols.\n\ +\n\ +@param grammar the modified grammar\n\ +@return grammar equivalent to @p grammar without unreachable symbols" ); + +auto UnreachableSymbolsRemoverLeftRG = registration::AbstractRegister < UnreachableSymbolsRemover, grammar::LeftRG < >, const grammar::LeftRG < > & > ( UnreachableSymbolsRemover::remove, "grammar" ).setDocumentation ( +"Removes unreachable symbols.\n\ +\n\ +@param grammar the modified grammar\n\ +@return grammar equivalent to @p grammar without unreachable symbols" ); + +auto UnreachableSymbolsRemoverRightLG = registration::AbstractRegister < UnreachableSymbolsRemover, grammar::RightLG < >, const grammar::RightLG < > & > ( UnreachableSymbolsRemover::remove, "grammar" ).setDocumentation ( +"Removes unreachable symbols.\n\ +\n\ +@param grammar the modified grammar\n\ +@return grammar equivalent to @p grammar without unreachable symbols" ); + +auto UnreachableSymbolsRemoverRightRG = registration::AbstractRegister < UnreachableSymbolsRemover, grammar::RightRG < >, const grammar::RightRG < > & > ( UnreachableSymbolsRemover::remove, "grammar" ).setDocumentation ( +"Removes unreachable symbols.\n\ +\n\ +@param grammar the modified grammar\n\ +@return grammar equivalent to @p grammar without unreachable symbols" ); } /* namespace simplify */ diff --git a/alib2algo/src/grammar/simplify/UnreachableSymbolsRemover.h b/alib2algo/src/grammar/simplify/UnreachableSymbolsRemover.h index 0a2b65f419..ec7bd80a2a 100644 --- a/alib2algo/src/grammar/simplify/UnreachableSymbolsRemover.h +++ b/alib2algo/src/grammar/simplify/UnreachableSymbolsRemover.h @@ -31,12 +31,24 @@ namespace grammar { namespace simplify { /** - * Implements algorithms from Melichar, chapter 3.3 + * Algorithm for the removal of unreachable symbols from a context free grammar. + * Unreachable symbols is a symbol that is not accessible from the initial symbol of the automaton by any sequence of derivations. + * + * @sa grammar::simplify::Trim + * @sa grammar::properties::ReachableSymbols */ class UnreachableSymbolsRemover { public: /* - * Removes unreachable symbols - Melichar 3.9 + * Removes unreachable symbols. + * + * \tparam T the type of modified grammar + * \tparam TerminalSymbolType the type of terminal symbols of the grammar + * \tparam NonterminalSymbolType the type of nonterminal symbols of the grammar + * + * \param grammar the modified grammar + * + * \return grammar equivalent to @p grammar without unreachable symbols */ template < class T, class TerminalSymbolType = typename grammar::TerminalSymbolTypeOfGrammar < T >, class NonterminalSymbolType = typename grammar::NonterminalSymbolTypeOfGrammar < T > > static T remove( const T & grammar ); -- GitLab