diff --git a/alib2algo/src/grammar/simplify/Rename.cpp b/alib2algo/src/grammar/simplify/Rename.cpp index 57f0cd654c576aea08532c00ef397cb40e63af61..b8b8c466d136f7ad4069a5051f9585606cc20c79 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 195d73c82b1dc869a40eabee55012aefbb82096b..2cc1cce88c59185b12da8b2638be4df8fc62c632 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 cc3496e996c25dfda28ce7fe211dc9cede46fb71..72c048d74d6fe5c1b84f49ba14861f66e905328a 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 dd7d4d2839a0c646ba8575d01a8426000d5a216f..9035cd29eaece1b31b9d2503f4f76372356af103 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 412797732ba76abe6953e277ea8d69cdb1d6b97c..084c8f11133068c65dfb70239e0c5b8fc607cacf 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 a441a997fff77a82e1812ca7015cbb7b516c7d4c..a6bd4f15155696c5e948383c176f45e9a4ff8b79 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 5a0897ee39c5a109265024de462d18a5c3ef34d3..7c326d530f88a287d9569dbfa18f4d4387820e58 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 f6dc6834ef842ec1255e9029886d483b1a904fbb..3f826cf1991b5b326a3ab3e49eebf3e6d4873937 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 21c114971555c617ee33335fc12aaeae09380269..90558659e35da5ca219ea3ef29f704e49e4ce79c 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 46627dcb9eef070423454d1c8fede720e8d606dc..f74b6dbcb3efb5e69c1c2b3e159865c571c62386 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 9f630581225222e7f03ffd8aa89bb3c1bcf18683..c53597009f2abc141c36429745c81adbe3c8cc9b 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 0a2b65f419f663cf8f627b373d5d60b7ee7f55f2..ec7bd80a2a07c858c8eefe2205aa3e6ad2b000f9 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 );