From 121e16a711a08faf3ebe6991bd65db90380ab7da Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Mon, 13 May 2019 08:08:26 +0200 Subject: [PATCH] replace Epsilon with void type --- alib2algo/src/automaton/run/Run.h | 6 +- .../regexp/convert/ToAutomatonThompson.cpp | 36 +-- alib2algo/src/string/naive/ExactCompare.cpp | 7 - alib2algo/src/string/naive/ExactCompare.h | 19 -- alib2algo/src/string/naive/ExactEqual.cpp | 7 - alib2algo/src/string/naive/ExactEqual.h | 19 -- .../automaton/convert/FTAtoPDATest.cpp | 4 +- .../test-src/string/compare/compareTest.cpp | 2 - .../grammar/parsing/CornerSubstitution.cpp | 1 - .../parsing/DeterministicLL1Grammar.cpp | 14 +- .../parsing/DeterministicLL1ParseTable.cpp | 8 +- .../parsing/DeterministicLL1ParseTable.h | 6 +- .../grammar/parsing/ExtractRightContext.cpp | 1 - .../src/grammar/parsing/First.cpp | 38 +-- .../src/grammar/parsing/First.h | 43 ++-- .../src/grammar/parsing/Follow.cpp | 38 +-- .../src/grammar/parsing/Follow.h | 25 +- .../src/grammar/parsing/LL1ParseTable.cpp | 18 +- .../src/grammar/parsing/LL1ParseTable.h | 19 +- .../src/grammar/parsing/SLR1ParseTable.cpp | 4 +- .../test-src/grammar/parsing/FirstTest.cpp | 59 +++-- .../test-src/grammar/parsing/FollowTest.cpp | 43 ++-- .../grammar/parsing/LL1ParseTableTest.cpp | 9 +- alib2data/src/PrimitiveRegistrator.cpp | 12 +- alib2data/src/common/DefaultEpsilonType.h | 5 +- alib2data/src/string/CyclicString.cpp | 2 - alib2data/src/string/CyclicString.h | 19 -- alib2data/src/string/Epsilon.cpp | 19 -- alib2data/src/string/Epsilon.h | 221 ------------------ alib2data/src/string/LinearString.cpp | 2 - alib2data/src/string/LinearString.h | 19 -- alib2data/src/string/WildcardLinearString.cpp | 1 - alib2data/src/string/WildcardLinearString.h | 29 --- alib2data/src/string/xml/Epsilon.cpp | 21 -- alib2data/src/string/xml/Epsilon.h | 54 ----- alib2data/test-src/string/StringTest.cpp | 30 ++- alib2str/src/object/string/AnyObject.cpp | 5 +- alib2str/src/string/StringFromStringLexer.cpp | 5 - alib2str/src/string/StringFromStringLexer.h | 1 - alib2str/src/string/string/Epsilon.cpp | 18 -- alib2str/src/string/string/Epsilon.h | 53 ----- alib2str/test-src/string/StringTest.cpp | 14 -- 42 files changed, 209 insertions(+), 747 deletions(-) delete mode 100644 alib2data/src/string/Epsilon.cpp delete mode 100644 alib2data/src/string/Epsilon.h delete mode 100644 alib2data/src/string/xml/Epsilon.cpp delete mode 100644 alib2data/src/string/xml/Epsilon.h delete mode 100644 alib2str/src/string/string/Epsilon.cpp delete mode 100644 alib2str/src/string/string/Epsilon.h diff --git a/alib2algo/src/automaton/run/Run.h b/alib2algo/src/automaton/run/Run.h index 2303ffab6f..4e33b8a2cb 100644 --- a/alib2algo/src/automaton/run/Run.h +++ b/alib2algo/src/automaton/run/Run.h @@ -670,7 +670,7 @@ ext::tuple < bool, StateType, ext::set < unsigned >, ext::deque < PushdownStoreS symbolIter++; i++; } else { - callTransition = automaton.getCallTransitions ( ).find ( std::pair < StateType, ext::variant < EpsilonType, InputSymbolType > > ( state, EpsilonType ( ) ) ); + callTransition = automaton.getCallTransitions ( ).find ( std::make_pair ( state, ext::variant < EpsilonType, InputSymbolType >::template from < EpsilonType > ( ) ) ); } if ( callTransition != automaton.getCallTransitions ( ).end ( ) ) { @@ -687,7 +687,7 @@ ext::tuple < bool, StateType, ext::set < unsigned >, ext::deque < PushdownStoreS symbolIter++; i++; } else { - returnTransition = automaton.getReturnTransitions ( ).find ( std::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, PushdownStoreSymbolType > ( state, EpsilonType ( ), pushdownStore.back ( ) ) ); + returnTransition = automaton.getReturnTransitions ( ).find ( std::make_tuple ( state, ext::variant < EpsilonType, InputSymbolType >::template from < EpsilonType > ( ), pushdownStore.back ( ) ) ); } if ( returnTransition != automaton.getReturnTransitions ( ).end ( ) ) { @@ -705,7 +705,7 @@ ext::tuple < bool, StateType, ext::set < unsigned >, ext::deque < PushdownStoreS symbolIter++; i++; } else { - localTransition = automaton.getLocalTransitions ( ).find ( std::pair < StateType, ext::variant < EpsilonType, InputSymbolType > > ( state, EpsilonType ( ) ) ); + localTransition = automaton.getLocalTransitions ( ).find ( std::make_pair ( state, ext::variant < EpsilonType, InputSymbolType >::template from < EpsilonType > ( ) ) ); } if ( localTransition != automaton.getLocalTransitions ( ).end ( ) ) diff --git a/alib2algo/src/regexp/convert/ToAutomatonThompson.cpp b/alib2algo/src/regexp/convert/ToAutomatonThompson.cpp index 63663685d5..f81bb77b5f 100644 --- a/alib2algo/src/regexp/convert/ToAutomatonThompson.cpp +++ b/alib2algo/src/regexp/convert/ToAutomatonThompson.cpp @@ -72,12 +72,12 @@ void ToAutomatonThompson::Formal::visit(const regexp::FormalRegExpAlternation < automaton.addState(tail); alternation.getLeftElement().accept < void, ToAutomatonThompson::Formal, automaton::EpsilonNFA < > &, int &, const DefaultStateType * &, const DefaultStateType * & >(automaton, nextState, headArg, tailArg); - automaton.addTransition(head, string::Epsilon < >::EPSILON, *headArg); - automaton.addTransition(*tailArg, string::Epsilon < >::EPSILON, tail); + automaton.addTransition(head, *headArg); + automaton.addTransition(*tailArg, tail); alternation.getRightElement().accept < void, ToAutomatonThompson::Formal, automaton::EpsilonNFA < > &, int &, const DefaultStateType * &, const DefaultStateType * & >(automaton, nextState, headArg, tailArg); - automaton.addTransition(head, string::Epsilon < >::EPSILON, *headArg); - automaton.addTransition(*tailArg, string::Epsilon < >::EPSILON, tail); + automaton.addTransition(head, *headArg); + automaton.addTransition(*tailArg, tail); headArg = &(*automaton.getStates().find(head)); tailArg = &(*automaton.getStates().find(tail)); @@ -89,7 +89,7 @@ void ToAutomatonThompson::Formal::visit(const regexp::FormalRegExpConcatenation const DefaultStateType* leftTail = tailArg; concatenation.getRightElement().accept < void, ToAutomatonThompson::Formal, automaton::EpsilonNFA < > &, int &, const DefaultStateType * &, const DefaultStateType * & >(automaton, nextState, headArg, tailArg); - automaton.addTransition(*leftTail, string::Epsilon < >::EPSILON, *headArg); + automaton.addTransition(*leftTail, *headArg); headArg = &(*automaton.getStates().find(*leftHead)); // tailArg = tailArg; @@ -102,10 +102,10 @@ void ToAutomatonThompson::Formal::visit(const regexp::FormalRegExpIteration < De automaton.addState(tail); iteration.getElement().accept < void, ToAutomatonThompson::Formal, automaton::EpsilonNFA < > &, int &, const DefaultStateType * &, const DefaultStateType * & >(automaton, nextState, headArg, tailArg); - automaton.addTransition(head, string::Epsilon < >::EPSILON, *headArg); - automaton.addTransition(head, string::Epsilon < >::EPSILON, tail); - automaton.addTransition(*tailArg, string::Epsilon < >::EPSILON, tail); - automaton.addTransition(*tailArg, string::Epsilon < >::EPSILON, *headArg); + automaton.addTransition(head, *headArg); + automaton.addTransition(head, tail); + automaton.addTransition(*tailArg, tail); + automaton.addTransition(*tailArg, *headArg); headArg = &(*automaton.getStates().find(head)); tailArg = &(*automaton.getStates().find(tail)); @@ -128,7 +128,7 @@ void ToAutomatonThompson::Formal::visit(const regexp::FormalRegExpEpsilon < Defa automaton.addState(head); automaton.addState(tail); - automaton.addTransition(head, string::Epsilon < >::EPSILON, tail); + automaton.addTransition(head, tail); headArg = &(*automaton.getStates().find(head)); tailArg = &(*automaton.getStates().find(tail)); } @@ -153,8 +153,8 @@ void ToAutomatonThompson::Unbounded::visit(const regexp::UnboundedRegExpAlternat for(const UnboundedRegExpElement < DefaultSymbolType > & element : alternation.getElements()) { element.accept < void, ToAutomatonThompson::Unbounded, automaton::EpsilonNFA < > &, int &, const DefaultStateType * &, const DefaultStateType * & >(automaton, nextState, headArg, tailArg); - automaton.addTransition(head, string::Epsilon < >::EPSILON, *headArg); - automaton.addTransition(*tailArg, string::Epsilon < >::EPSILON, tail); + automaton.addTransition(head, *headArg); + automaton.addTransition(*tailArg, tail); } headArg = &(*automaton.getStates().find(head)); @@ -169,7 +169,7 @@ void ToAutomatonThompson::Unbounded::visit(const regexp::UnboundedRegExpConcaten } for(size_t i = 1; i < tails.size(); i++) - automaton.addTransition(*tails[i-1].second, string::Epsilon < >::EPSILON, *tails[i].first); + automaton.addTransition(*tails[i-1].second, *tails[i].first); headArg = tails[0].first; tailArg = tails[tails.size()-1].second; @@ -182,10 +182,10 @@ void ToAutomatonThompson::Unbounded::visit(const regexp::UnboundedRegExpIteratio automaton.addState(tail); iteration.getElement().accept < void, ToAutomatonThompson::Unbounded, automaton::EpsilonNFA < > &, int &, const DefaultStateType * &, const DefaultStateType * & >(automaton, nextState, headArg, tailArg); - automaton.addTransition(head, string::Epsilon < >::EPSILON, *headArg); - automaton.addTransition(head, string::Epsilon < >::EPSILON, tail); - automaton.addTransition(*tailArg, string::Epsilon < >::EPSILON, tail); - automaton.addTransition(*tailArg, string::Epsilon < >::EPSILON, *headArg); + automaton.addTransition(head, *headArg); + automaton.addTransition(head, tail); + automaton.addTransition(*tailArg, tail); + automaton.addTransition(*tailArg, *headArg); headArg = &(*automaton.getStates().find(head)); tailArg = &(*automaton.getStates().find(tail)); @@ -208,7 +208,7 @@ void ToAutomatonThompson::Unbounded::visit(const regexp::UnboundedRegExpEpsilon automaton.addState(head); automaton.addState(tail); - automaton.addTransition(head, string::Epsilon < >::EPSILON, tail); + automaton.addTransition(head, tail); headArg = &(*automaton.getStates().find(head)); tailArg = &(*automaton.getStates().find(tail)); } diff --git a/alib2algo/src/string/naive/ExactCompare.cpp b/alib2algo/src/string/naive/ExactCompare.cpp index 6012247067..ef5ed276ac 100644 --- a/alib2algo/src/string/naive/ExactCompare.cpp +++ b/alib2algo/src/string/naive/ExactCompare.cpp @@ -11,13 +11,6 @@ namespace string { namespace naive { -auto ExactCompareEpsilon = registration::AbstractRegister < ExactCompare, int, const string::Epsilon < > &, const string::Epsilon < > & > ( ExactCompare::compare, "u", "v" ).setDocumentation ( -"Implementation of exact comparison of strings.\n\ -\n\ -@param u the first string to compare\n\ -@param v the second string to compare\n\ -@return zero as epsilons are equal" ); - auto ExactCompareLinearString = registration::AbstractRegister < ExactCompare, int, const string::LinearString < > &, const string::LinearString < > & > ( ExactCompare::compare, "u", "v" ).setDocumentation ( "Implementation of exact comparison of strings.\n\ \n\ diff --git a/alib2algo/src/string/naive/ExactCompare.h b/alib2algo/src/string/naive/ExactCompare.h index 6f263b9cd3..6ca0e72697 100644 --- a/alib2algo/src/string/naive/ExactCompare.h +++ b/alib2algo/src/string/naive/ExactCompare.h @@ -10,7 +10,6 @@ #include <string/LinearString.h> #include <string/CyclicString.h> -#include <string/Epsilon.h> namespace string { @@ -22,19 +21,6 @@ namespace naive { */ class ExactCompare { public: - /** - * Implementation of exact comparison of strings. - * - * \tparam SymbolType the of symbols in the string - * - * \param u the first string to compare - * \param v the second string to compare - * - * \return zero as epsilons are equal - */ - template < class SymbolType > - static int compare(const string::Epsilon < SymbolType >& u, const string::Epsilon < SymbolType >& v); - /** * Implementation of exact comparison of strings. * @@ -62,11 +48,6 @@ public: static int compare(const string::CyclicString < SymbolType >& u, const string::CyclicString < SymbolType >& v); }; -template < class SymbolType > -int ExactCompare::compare ( const string::Epsilon < SymbolType > &, const string::Epsilon < SymbolType > & ) { - return 0; -} - template < class SymbolType > int ExactCompare::compare ( const string::LinearString < SymbolType > & u, const string::LinearString < SymbolType > & v ) { int n = ( int ) u.getContent ( ).size ( ), m = ( int ) v.getContent ( ).size ( ); diff --git a/alib2algo/src/string/naive/ExactEqual.cpp b/alib2algo/src/string/naive/ExactEqual.cpp index 682d3639f3..23f32d25e2 100644 --- a/alib2algo/src/string/naive/ExactEqual.cpp +++ b/alib2algo/src/string/naive/ExactEqual.cpp @@ -11,13 +11,6 @@ namespace string { namespace naive { -auto ExactEqualEpsilon = registration::AbstractRegister < ExactEqual, bool, const string::Epsilon < > &, const string::Epsilon < > & > ( ExactEqual::equals, "u", "v" ).setDocumentation ( -"Implements exact equality test of string contents.\n\ -\n\ -@param u the first string to compare\n\ -@param v the second string to compare\n\ -@return true as epsilons are equal" ); - auto ExactEqualLinearString = registration::AbstractRegister < ExactEqual, bool, const string::LinearString < > &, const string::LinearString < > & > ( ExactEqual::equals, "u", "v" ).setDocumentation ( "Implements exact equality test of string contents.\n\ \n\ diff --git a/alib2algo/src/string/naive/ExactEqual.h b/alib2algo/src/string/naive/ExactEqual.h index f22eb8a042..d9eb92be45 100644 --- a/alib2algo/src/string/naive/ExactEqual.h +++ b/alib2algo/src/string/naive/ExactEqual.h @@ -10,7 +10,6 @@ #include <string/LinearString.h> #include <string/CyclicString.h> -#include <string/Epsilon.h> namespace string { @@ -22,19 +21,6 @@ namespace naive { */ class ExactEqual { public: - /** - * Implements exact equality test of string contents. - * - * \tparam SymbolType the of symbols in the string - * - * \param u the first string to compare - * \param v the second string to compare - * - * \return true as epsilons are equal - */ - template < class SymbolType > - static bool equals(const string::Epsilon < SymbolType >& u, const string::Epsilon < SymbolType >& v); - /** * Implements exact equality test of string contents. * @@ -62,11 +48,6 @@ public: static bool equals(const string::CyclicString < SymbolType >& u, const string::CyclicString < SymbolType >& v); }; -template < class SymbolType > -bool ExactEqual::equals ( const string::Epsilon < SymbolType > &, const string::Epsilon < SymbolType > & ) { - return true; -} - template < class SymbolType > bool ExactEqual::equals ( const string::LinearString < SymbolType > & u, const string::LinearString < SymbolType > & v ) { int n = ( int ) u.getContent ( ).size ( ), m = ( int ) v.getContent ( ).size ( ); diff --git a/alib2algo/test-src/automaton/convert/FTAtoPDATest.cpp b/alib2algo/test-src/automaton/convert/FTAtoPDATest.cpp index f71056d9df..5b2abbecaa 100644 --- a/alib2algo/test-src/automaton/convert/FTAtoPDATest.cpp +++ b/alib2algo/test-src/automaton/convert/FTAtoPDATest.cpp @@ -41,7 +41,7 @@ TEST_CASE ( "FTAtoPDA", "[unit][algo][automaton][convert]" ) { automaton.addFinalState(DefaultStateType(3)); - automaton::DPDA < ext::variant < common::ranked_symbol < object::Object, unsigned int >, alphabet::EndSymbol >, string::Epsilon < >, ext::variant < object::Object, alphabet::BottomOfTheStackSymbol >, char > res = automaton::convert::ToPostfixPushdownAutomaton::convert(automaton); + automaton::DPDA < ext::variant < common::ranked_symbol < object::Object, unsigned int >, alphabet::EndSymbol >, DefaultEpsilonType, ext::variant < object::Object, alphabet::BottomOfTheStackSymbol >, char > res = automaton::convert::ToPostfixPushdownAutomaton::convert(automaton); CHECK(res.getStates().size() == 2); CHECK(res.getTransitions().size() == 5); CHECK(res.getFinalStates().size() == 1); @@ -72,7 +72,7 @@ TEST_CASE ( "FTAtoPDA", "[unit][algo][automaton][convert]" ) { automaton.addFinalState(DefaultStateType(3)); - automaton::NPDA < ext::variant < common::ranked_symbol < object::Object, unsigned int >, alphabet::EndSymbol >, string::Epsilon < >, ext::variant < object::Object, alphabet::BottomOfTheStackSymbol >, char > res = automaton::convert::ToPostfixPushdownAutomaton::convert ( automaton ); + automaton::NPDA < ext::variant < common::ranked_symbol < object::Object, unsigned int >, alphabet::EndSymbol >, DefaultEpsilonType, ext::variant < object::Object, alphabet::BottomOfTheStackSymbol >, char > res = automaton::convert::ToPostfixPushdownAutomaton::convert ( automaton ); CHECK(res.getStates().size() == 2); CHECK(res.getTransitions().size() == 5); diff --git a/alib2algo/test-src/string/compare/compareTest.cpp b/alib2algo/test-src/string/compare/compareTest.cpp index 06a20a2612..87d8549382 100644 --- a/alib2algo/test-src/string/compare/compareTest.cpp +++ b/alib2algo/test-src/string/compare/compareTest.cpp @@ -5,8 +5,6 @@ #include "string/simplify/NormalizeRotation.h" #include "string/LinearString.h" #include "string/CyclicString.h" -#include "string/Epsilon.h" - TEST_CASE ( "String Compare", "[unit][algo][string][compare]" ) { SECTION ( "Cyclic String Equality" ) { diff --git a/alib2algo_experimental/src/grammar/parsing/CornerSubstitution.cpp b/alib2algo_experimental/src/grammar/parsing/CornerSubstitution.cpp index c2f23ff290..7b171c7a7a 100644 --- a/alib2algo_experimental/src/grammar/parsing/CornerSubstitution.cpp +++ b/alib2algo_experimental/src/grammar/parsing/CornerSubstitution.cpp @@ -10,7 +10,6 @@ #include "CornerSubstitution.h" #include <grammar/ContextFree/CFG.h> -#include <common/DefaultEpsilonType.h> namespace grammar { diff --git a/alib2algo_experimental/src/grammar/parsing/DeterministicLL1Grammar.cpp b/alib2algo_experimental/src/grammar/parsing/DeterministicLL1Grammar.cpp index dfb44b6647..9a18642f80 100644 --- a/alib2algo_experimental/src/grammar/parsing/DeterministicLL1Grammar.cpp +++ b/alib2algo_experimental/src/grammar/parsing/DeterministicLL1Grammar.cpp @@ -31,17 +31,17 @@ grammar::CFG < > DeterministicLL1Grammar::convert ( const grammar::CFG < > & par grammar::CFG < > grammar = param; while ( true ) { - ext::map < ext::pair < ext::variant < DefaultSymbolType, string::Epsilon < > >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > > parseTable = LL1ParseTable::parseTable ( grammar ); + ext::map < ext::pair < ext::variant < DefaultSymbolType, DefaultEpsilonType >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > > parseTable = LL1ParseTable::parseTable ( grammar ); bool deterministic = true; - for ( const std::pair < const ext::pair < ext::variant < DefaultSymbolType, string::Epsilon < > >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > > & elem : parseTable ) + for ( const std::pair < const ext::pair < ext::variant < DefaultSymbolType, DefaultEpsilonType >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > > & elem : parseTable ) if ( elem.second.size ( ) > 1 ) - if ( elem.first.first.is < string::Epsilon < > > ( ) ) + if ( elem.first.first.is < DefaultEpsilonType > ( ) ) throw exception::CommonException ( "Cant handle conflict in epsilon" ); - for ( const std::pair < const ext::pair < ext::variant < DefaultSymbolType, string::Epsilon < > >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > > & elem : parseTable ) { - if ( elem.first.first.is < string::Epsilon < > > ( ) ) continue; + for ( const std::pair < const ext::pair < ext::variant < DefaultSymbolType, DefaultEpsilonType >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > > & elem : parseTable ) { + if ( elem.first.first.is < DefaultEpsilonType > ( ) ) continue; const DefaultSymbolType & terminal = elem.first.first.get < DefaultSymbolType > ( ); const DefaultSymbolType & nonterminal = elem.first.second; @@ -58,8 +58,8 @@ grammar::CFG < > DeterministicLL1Grammar::convert ( const grammar::CFG < > & par if ( !deterministic ) continue; - for ( const std::pair < const ext::pair < ext::variant < DefaultSymbolType, string::Epsilon < > >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > > & elem : parseTable ) { - if ( elem.first.first.is < string::Epsilon < > > ( ) ) continue; + for ( const std::pair < const ext::pair < ext::variant < DefaultSymbolType, DefaultEpsilonType >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > > & elem : parseTable ) { + if ( elem.first.first.is < DefaultEpsilonType > ( ) ) continue; const DefaultSymbolType & terminal = elem.first.first.get < DefaultSymbolType > ( ); const DefaultSymbolType & nonterminal = elem.first.second; diff --git a/alib2algo_experimental/src/grammar/parsing/DeterministicLL1ParseTable.cpp b/alib2algo_experimental/src/grammar/parsing/DeterministicLL1ParseTable.cpp index 472b3f6fad..ac43d999aa 100644 --- a/alib2algo_experimental/src/grammar/parsing/DeterministicLL1ParseTable.cpp +++ b/alib2algo_experimental/src/grammar/parsing/DeterministicLL1ParseTable.cpp @@ -13,15 +13,15 @@ namespace grammar { namespace parsing { -ext::map < ext::pair < ext::variant < DefaultSymbolType, string::Epsilon < > >, DefaultSymbolType >, ext::vector < DefaultSymbolType > > DeterministicLL1ParseTable::parseTable ( const ext::map < ext::pair < ext::variant < DefaultSymbolType, string::Epsilon < > >, DefaultSymbolType >, ext::set < ext::vector < DefaultSymbolType > > > & parseTable ) { +ext::map < ext::pair < ext::variant < DefaultSymbolType, DefaultEpsilonType >, DefaultSymbolType >, ext::vector < DefaultSymbolType > > DeterministicLL1ParseTable::parseTable ( const ext::map < ext::pair < ext::variant < DefaultSymbolType, DefaultEpsilonType >, DefaultSymbolType >, ext::set < ext::vector < DefaultSymbolType > > > & parseTable ) { - for ( const std::pair < const ext::pair < ext::variant < DefaultSymbolType, string::Epsilon < > >, DefaultSymbolType >, ext::set < ext::vector < DefaultSymbolType > > > & elem : parseTable ) + for ( const std::pair < const ext::pair < ext::variant < DefaultSymbolType, DefaultEpsilonType >, DefaultSymbolType >, ext::set < ext::vector < DefaultSymbolType > > > & elem : parseTable ) if ( elem.second.size ( ) > 1 ) throw exception::CommonException ( "Cant handle conflict in epsilon" ); - ext::map < ext::pair < ext::variant < DefaultSymbolType, string::Epsilon < > >, DefaultSymbolType >, ext::vector < DefaultSymbolType > > res; + ext::map < ext::pair < ext::variant < DefaultSymbolType, DefaultEpsilonType >, DefaultSymbolType >, ext::vector < DefaultSymbolType > > res; - for ( const std::pair < const ext::pair < ext::variant < DefaultSymbolType, string::Epsilon < > >, DefaultSymbolType >, ext::set < ext::vector < DefaultSymbolType > > > & elem : parseTable ) + for ( const std::pair < const ext::pair < ext::variant < DefaultSymbolType, DefaultEpsilonType >, DefaultSymbolType >, ext::set < ext::vector < DefaultSymbolType > > > & elem : parseTable ) if ( elem.second.size ( ) == 1 ) res.insert ( std::make_pair ( elem.first, * elem.second.begin ( ) ) ); diff --git a/alib2algo_experimental/src/grammar/parsing/DeterministicLL1ParseTable.h b/alib2algo_experimental/src/grammar/parsing/DeterministicLL1ParseTable.h index 27ada3ab4f..388e6f8016 100644 --- a/alib2algo_experimental/src/grammar/parsing/DeterministicLL1ParseTable.h +++ b/alib2algo_experimental/src/grammar/parsing/DeterministicLL1ParseTable.h @@ -8,19 +8,21 @@ #ifndef DETERMINISTIC_LL_1_PARSE_TABLE_H_ #define DETERMINISTIC_LL_1_PARSE_TABLE_H_ -#include <string/Epsilon.h> #include <alib/vector> #include <alib/variant> #include <alib/set> #include <alib/map> +#include <common/DefaultEpsilonType.h> +#include <common/DefaultSymbolType.h> + namespace grammar { namespace parsing { class DeterministicLL1ParseTable { public: - static ext::map < ext::pair < ext::variant < DefaultSymbolType, string::Epsilon < > >, DefaultSymbolType >, ext::vector < DefaultSymbolType > > parseTable ( const ext::map < ext::pair < ext::variant < DefaultSymbolType, string::Epsilon < > >, DefaultSymbolType >, ext::set < ext::vector < DefaultSymbolType > > > & parseTable ); + static ext::map < ext::pair < ext::variant < DefaultSymbolType, DefaultEpsilonType >, DefaultSymbolType >, ext::vector < DefaultSymbolType > > parseTable ( const ext::map < ext::pair < ext::variant < DefaultSymbolType, DefaultEpsilonType >, DefaultSymbolType >, ext::set < ext::vector < DefaultSymbolType > > > & parseTable ); }; } /* namespace parsing */ diff --git a/alib2algo_experimental/src/grammar/parsing/ExtractRightContext.cpp b/alib2algo_experimental/src/grammar/parsing/ExtractRightContext.cpp index c7e39b422e..c70f2f44c5 100644 --- a/alib2algo_experimental/src/grammar/parsing/ExtractRightContext.cpp +++ b/alib2algo_experimental/src/grammar/parsing/ExtractRightContext.cpp @@ -9,7 +9,6 @@ #include "First.h" #include "common/Substitute.h" #include <grammar/ContextFree/CFG.h> -#include <common/DefaultEpsilonType.h> namespace grammar { diff --git a/alib2algo_experimental/src/grammar/parsing/First.cpp b/alib2algo_experimental/src/grammar/parsing/First.cpp index 67da8ec0c1..239487fb23 100644 --- a/alib2algo_experimental/src/grammar/parsing/First.cpp +++ b/alib2algo_experimental/src/grammar/parsing/First.cpp @@ -23,25 +23,25 @@ namespace grammar { namespace parsing { -auto FirstCFG = registration::AbstractRegister < First, ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > >, const grammar::CFG < > & > ( First::first ); -auto FirstEpsilonFreeCFG = registration::AbstractRegister < First, ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > >, const grammar::EpsilonFreeCFG < > & > ( First::first ); -auto FirstGNF = registration::AbstractRegister < First, ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > >, const grammar::GNF < > & > ( First::first ); -auto FirstCNF = registration::AbstractRegister < First, ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > >, const grammar::CNF < > & > ( First::first ); -auto FirstLG = registration::AbstractRegister < First, ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > >, const grammar::LG < > & > ( First::first ); -auto FirstLeftLG = registration::AbstractRegister < First, ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > >, const grammar::LeftLG < > & > ( First::first ); -auto FirstLeftRG = registration::AbstractRegister < First, ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > >, const grammar::LeftRG < > & > ( First::first ); -auto FirstRightLG = registration::AbstractRegister < First, ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > >, const grammar::RightLG < > & > ( First::first ); -auto FirstRightRG = registration::AbstractRegister < First, ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > >, const grammar::RightRG < > & > ( First::first ); - -auto FirstCFG2 = registration::AbstractRegister < First, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > >, const grammar::CFG < > &, const ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > & > ( First::first ); -auto FirstEpsilonFreeCFG2 = registration::AbstractRegister < First, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > >, const grammar::EpsilonFreeCFG < > &, const ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > & > ( First::first ); -auto FirstGNF2 = registration::AbstractRegister < First, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > >, const grammar::GNF < > &, const ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > & > ( First::first ); -auto FirstCNF2 = registration::AbstractRegister < First, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > >, const grammar::CNF < > &, const ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > & > ( First::first ); -auto FirstLG2 = registration::AbstractRegister < First, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > >, const grammar::LG < > &, const ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > & > ( First::first ); -auto FirstLeftLG2 = registration::AbstractRegister < First, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > >, const grammar::LeftLG < > &, const ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > & > ( First::first ); -auto FirstLeftRG2 = registration::AbstractRegister < First, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > >, const grammar::LeftRG < > &, const ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > & > ( First::first ); -auto FirstRightLG2 = registration::AbstractRegister < First, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > >, const grammar::RightLG < > &, const ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > & > ( First::first ); -auto FirstRightRG2 = registration::AbstractRegister < First, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > >, const grammar::RightRG < > &, const ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > & > ( First::first ); +auto FirstCFG = registration::AbstractRegister < First, ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > >, const grammar::CFG < > & > ( First::first ); +auto FirstEpsilonFreeCFG = registration::AbstractRegister < First, ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > >, const grammar::EpsilonFreeCFG < > & > ( First::first ); +auto FirstGNF = registration::AbstractRegister < First, ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > >, const grammar::GNF < > & > ( First::first ); +auto FirstCNF = registration::AbstractRegister < First, ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > >, const grammar::CNF < > & > ( First::first ); +auto FirstLG = registration::AbstractRegister < First, ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > >, const grammar::LG < > & > ( First::first ); +auto FirstLeftLG = registration::AbstractRegister < First, ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > >, const grammar::LeftLG < > & > ( First::first ); +auto FirstLeftRG = registration::AbstractRegister < First, ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > >, const grammar::LeftRG < > & > ( First::first ); +auto FirstRightLG = registration::AbstractRegister < First, ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > >, const grammar::RightLG < > & > ( First::first ); +auto FirstRightRG = registration::AbstractRegister < First, ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > >, const grammar::RightRG < > & > ( First::first ); + +auto FirstCFG2 = registration::AbstractRegister < First, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > >, const grammar::CFG < > &, const ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > & > ( First::first ); +auto FirstEpsilonFreeCFG2 = registration::AbstractRegister < First, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > >, const grammar::EpsilonFreeCFG < > &, const ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > & > ( First::first ); +auto FirstGNF2 = registration::AbstractRegister < First, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > >, const grammar::GNF < > &, const ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > & > ( First::first ); +auto FirstCNF2 = registration::AbstractRegister < First, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > >, const grammar::CNF < > &, const ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > & > ( First::first ); +auto FirstLG2 = registration::AbstractRegister < First, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > >, const grammar::LG < > &, const ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > & > ( First::first ); +auto FirstLeftLG2 = registration::AbstractRegister < First, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > >, const grammar::LeftLG < > &, const ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > & > ( First::first ); +auto FirstLeftRG2 = registration::AbstractRegister < First, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > >, const grammar::LeftRG < > &, const ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > & > ( First::first ); +auto FirstRightLG2 = registration::AbstractRegister < First, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > >, const grammar::RightLG < > &, const ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > & > ( First::first ); +auto FirstRightRG2 = registration::AbstractRegister < First, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > >, const grammar::RightRG < > &, const ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > & > ( First::first ); } /* namespace parsing */ diff --git a/alib2algo_experimental/src/grammar/parsing/First.h b/alib2algo_experimental/src/grammar/parsing/First.h index a81cb197a3..677292b9d0 100644 --- a/alib2algo_experimental/src/grammar/parsing/First.h +++ b/alib2algo_experimental/src/grammar/parsing/First.h @@ -12,34 +12,35 @@ #include <alib/set> #include <alib/variant> -#include <string/Epsilon.h> #include <grammar/Grammar.h> #include <grammar/RawRules.h> +#include <common/DefaultEpsilonType.h> + namespace grammar { namespace parsing { class First { template < class TerminalSymbolType, class NonterminalSymbolType > - static ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > first ( const ext::set < TerminalSymbolType > & terminals, const ext::set < NonterminalSymbolType > & nonterminals, const ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > > & firstOfNonterminal, const ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > & rhs ); + static ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > first ( const ext::set < TerminalSymbolType > & terminals, const ext::set < NonterminalSymbolType > & nonterminals, const ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > > & firstOfNonterminal, const ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > & rhs ); template < class TerminalSymbolType, class NonterminalSymbolType > - static ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > > first ( const ext::set < TerminalSymbolType > & terminals, const ext::set < NonterminalSymbolType > & nonterminals, const ext::map < NonterminalSymbolType, ext::set < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > > > & rules ); + static ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > > first ( const ext::set < TerminalSymbolType > & terminals, const ext::set < NonterminalSymbolType > & nonterminals, const ext::map < NonterminalSymbolType, ext::set < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > > > & rules ); public: template < class T, class TerminalSymbolType = typename grammar::TerminalSymbolTypeOfGrammar < T >, class NonterminalSymbolType = typename grammar::NonterminalSymbolTypeOfGrammar < T > > - static ext::map < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > >, ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > > first ( const T & grammar ); + static ext::map < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > >, ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > > first ( const T & grammar ); template < class T, class TerminalSymbolType = typename grammar::TerminalSymbolTypeOfGrammar < T >, class NonterminalSymbolType = typename grammar::NonterminalSymbolTypeOfGrammar < T > > - static ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > first ( const T & grammar, const ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > & rhs ); + static ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > first ( const T & grammar, const ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > & rhs ); }; template < class TerminalSymbolType, class NonterminalSymbolType > -ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > First::first ( const ext::set < TerminalSymbolType > & terminals, const ext::set < NonterminalSymbolType > & nonterminals, const ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > > & firstOfNonterminal, const ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > & rhs ) { +ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > First::first ( const ext::set < TerminalSymbolType > & terminals, const ext::set < NonterminalSymbolType > & nonterminals, const ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > > & firstOfNonterminal, const ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > & rhs ) { // 1. FIRST(\varepsilon) = { \varepsilon } if ( rhs.size ( ) == 0 ) { - return { string::Epsilon < TerminalSymbolType >::EPSILON }; + return { ext::variant < TerminalSymbolType, DefaultEpsilonType >::template from < DefaultEpsilonType > ( ) }; } // 2. FIRST(a) = { a } forall a \in T @@ -48,16 +49,16 @@ ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolTy } // 4. FIRST(A \alpha) = first(A) if A \in N and \varepsilon \notin first(A) - else if ( nonterminals.count ( rhs[0] ) && !firstOfNonterminal.find ( rhs[0] )->second.count ( ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > >::template from < string::Epsilon < TerminalSymbolType > > ( ) ) ) { + else if ( nonterminals.count ( rhs[0] ) && !firstOfNonterminal.find ( rhs[0] )->second.count ( ext::variant < TerminalSymbolType, DefaultEpsilonType >::template from < DefaultEpsilonType > ( ) ) ) { return firstOfNonterminal.find ( rhs[0] )->second; } // 5. FIRST(A \alpha) = (first(A) - \varepsilon) \cup FIRST(\alpha) if A \in N and \varepsilon \in first(A) - else if ( nonterminals.count ( rhs[0] ) && firstOfNonterminal.find ( rhs[0] )->second.count ( ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > >::template from < string::Epsilon < TerminalSymbolType > > ( ) ) ) { - ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > res = firstOfNonterminal.find ( rhs[0] )->second; - res.erase ( string::Epsilon < TerminalSymbolType >::EPSILON ); + else if ( nonterminals.count ( rhs[0] ) && firstOfNonterminal.find ( rhs[0] )->second.count ( ext::variant < TerminalSymbolType, DefaultEpsilonType >::template from < DefaultEpsilonType > ( ) ) ) { + ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > res = firstOfNonterminal.find ( rhs[0] )->second; + res.erase ( ext::variant < TerminalSymbolType, DefaultEpsilonType >::template from < DefaultEpsilonType > ( ) ); - ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > next = first ( terminals, nonterminals, firstOfNonterminal, ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > ( rhs.begin ( ) + 1, rhs.end ( ) ) ); + ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > next = first ( terminals, nonterminals, firstOfNonterminal, ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > ( rhs.begin ( ) + 1, rhs.end ( ) ) ); res.insert ( next.begin ( ), next.end ( ) ); return res; } else { @@ -66,7 +67,7 @@ ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolTy } template < class TerminalSymbolType, class NonterminalSymbolType > -ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > > First::first ( const ext::set < TerminalSymbolType > & terminals, const ext::set < NonterminalSymbolType > & nonterminals, const ext::map < NonterminalSymbolType, ext::set < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > > > & rules ) { +ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > > First::first ( const ext::set < TerminalSymbolType > & terminals, const ext::set < NonterminalSymbolType > & nonterminals, const ext::map < NonterminalSymbolType, ext::set < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > > > & rules ) { /* * * 1. foreach A \in N: first(A) = \emptyset @@ -75,17 +76,17 @@ ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, * 3. repeat step 2 if at least one set first(A) has changed * */ - ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > > firstOfNonterminal1; + ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > > firstOfNonterminal1; for ( const NonterminalSymbolType & nonterminal : nonterminals ) firstOfNonterminal1[nonterminal]; - ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > > firstOfNonterminal2 = firstOfNonterminal1; + ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > > firstOfNonterminal2 = firstOfNonterminal1; do { for ( const std::pair < const NonterminalSymbolType, ext::set < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > > > & rule : rules ) for ( const ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > & rhs : rule.second ) { - ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > newFirst = first ( terminals, nonterminals, firstOfNonterminal1, rhs ); + ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > newFirst = first ( terminals, nonterminals, firstOfNonterminal1, rhs ); firstOfNonterminal2[rule.first].insert ( newFirst.begin ( ), newFirst.end ( ) ); } @@ -101,12 +102,12 @@ ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, } template < class T, class TerminalSymbolType, class NonterminalSymbolType > -ext::map < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > >, ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > > First::first ( const T & grammar ) { +ext::map < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > >, ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > > First::first ( const T & grammar ) { auto rawRules = grammar::RawRules::getRawRules ( grammar ); - ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > > firstNt = first ( grammar.getTerminalAlphabet ( ), grammar.getNonterminalAlphabet ( ), rawRules ); + ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > > firstNt = first ( grammar.getTerminalAlphabet ( ), grammar.getNonterminalAlphabet ( ), rawRules ); - ext::map < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > >, ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > > res; + ext::map < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > >, ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > > res; for ( const std::pair < const NonterminalSymbolType, ext::set < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > > > & rule : rawRules ) for ( const ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > & rhs : rule.second ) @@ -116,10 +117,10 @@ ext::map < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolTyp } template < class T, class TerminalSymbolType, class NonterminalSymbolType > -ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > First::first ( const T & grammar, const ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > & rhs ) { +ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > First::first ( const T & grammar, const ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > & rhs ) { auto rawRules = grammar::RawRules::getRawRules ( grammar ); - ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > > firstNt = first ( grammar.getTerminalAlphabet ( ), grammar.getNonterminalAlphabet ( ), rawRules ); + ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > > firstNt = first ( grammar.getTerminalAlphabet ( ), grammar.getNonterminalAlphabet ( ), rawRules ); return first ( grammar.getTerminalAlphabet ( ), grammar.getNonterminalAlphabet ( ), firstNt, rhs ); } diff --git a/alib2algo_experimental/src/grammar/parsing/Follow.cpp b/alib2algo_experimental/src/grammar/parsing/Follow.cpp index e204ce3182..554cb36888 100644 --- a/alib2algo_experimental/src/grammar/parsing/Follow.cpp +++ b/alib2algo_experimental/src/grammar/parsing/Follow.cpp @@ -22,25 +22,25 @@ namespace grammar { namespace parsing { -auto FollowCFG = registration::AbstractRegister < Follow, ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > >, const grammar::CFG < > & > ( Follow::follow ); -auto FollowEpsilonFreeCFG = registration::AbstractRegister < Follow, ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > >, const grammar::EpsilonFreeCFG < > & > ( Follow::follow ); -auto FollowGNF = registration::AbstractRegister < Follow, ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > >, const grammar::GNF < > & > ( Follow::follow ); -auto FollowCNF = registration::AbstractRegister < Follow, ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > >, const grammar::CNF < > & > ( Follow::follow ); -auto FollowLG = registration::AbstractRegister < Follow, ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > >, const grammar::LG < > & > ( Follow::follow ); -auto FollowLeftLG = registration::AbstractRegister < Follow, ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > >, const grammar::LeftLG < > & > ( Follow::follow ); -auto FollowLeftRG = registration::AbstractRegister < Follow, ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > >, const grammar::LeftRG < > & > ( Follow::follow ); -auto FollowRightLG = registration::AbstractRegister < Follow, ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > >, const grammar::RightLG < > & > ( Follow::follow ); -auto FollowRightRG = registration::AbstractRegister < Follow, ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > >, const grammar::RightRG < > & > ( Follow::follow ); - -auto FollowCFG2 = registration::AbstractRegister < Follow, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > >, const grammar::CFG < > &, const DefaultSymbolType & > ( Follow::follow ); -auto FollowEpsilonFreeCFG2 = registration::AbstractRegister < Follow, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > >, const grammar::EpsilonFreeCFG < > &, const DefaultSymbolType & > ( Follow::follow ); -auto FollowGNF2 = registration::AbstractRegister < Follow, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > >, const grammar::GNF < > &, const DefaultSymbolType & > ( Follow::follow ); -auto FollowCNF2 = registration::AbstractRegister < Follow, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > >, const grammar::CNF < > &, const DefaultSymbolType & > ( Follow::follow ); -auto FollowLG2 = registration::AbstractRegister < Follow, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > >, const grammar::LG < > &, const DefaultSymbolType & > ( Follow::follow ); -auto FollowLeftLG2 = registration::AbstractRegister < Follow, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > >, const grammar::LeftLG < > &, const DefaultSymbolType & > ( Follow::follow ); -auto FollowLeftRG2 = registration::AbstractRegister < Follow, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > >, const grammar::LeftRG < > &, const DefaultSymbolType & > ( Follow::follow ); -auto FollowRightLG2 = registration::AbstractRegister < Follow, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > >, const grammar::RightLG < > &, const DefaultSymbolType & > ( Follow::follow ); -auto FollowRightRG2 = registration::AbstractRegister < Follow, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > >, const grammar::RightRG < > &, const DefaultSymbolType & > ( Follow::follow ); +auto FollowCFG = registration::AbstractRegister < Follow, ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > >, const grammar::CFG < > & > ( Follow::follow ); +auto FollowEpsilonFreeCFG = registration::AbstractRegister < Follow, ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > >, const grammar::EpsilonFreeCFG < > & > ( Follow::follow ); +auto FollowGNF = registration::AbstractRegister < Follow, ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > >, const grammar::GNF < > & > ( Follow::follow ); +auto FollowCNF = registration::AbstractRegister < Follow, ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > >, const grammar::CNF < > & > ( Follow::follow ); +auto FollowLG = registration::AbstractRegister < Follow, ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > >, const grammar::LG < > & > ( Follow::follow ); +auto FollowLeftLG = registration::AbstractRegister < Follow, ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > >, const grammar::LeftLG < > & > ( Follow::follow ); +auto FollowLeftRG = registration::AbstractRegister < Follow, ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > >, const grammar::LeftRG < > & > ( Follow::follow ); +auto FollowRightLG = registration::AbstractRegister < Follow, ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > >, const grammar::RightLG < > & > ( Follow::follow ); +auto FollowRightRG = registration::AbstractRegister < Follow, ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > >, const grammar::RightRG < > & > ( Follow::follow ); + +auto FollowCFG2 = registration::AbstractRegister < Follow, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > >, const grammar::CFG < > &, const DefaultSymbolType & > ( Follow::follow ); +auto FollowEpsilonFreeCFG2 = registration::AbstractRegister < Follow, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > >, const grammar::EpsilonFreeCFG < > &, const DefaultSymbolType & > ( Follow::follow ); +auto FollowGNF2 = registration::AbstractRegister < Follow, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > >, const grammar::GNF < > &, const DefaultSymbolType & > ( Follow::follow ); +auto FollowCNF2 = registration::AbstractRegister < Follow, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > >, const grammar::CNF < > &, const DefaultSymbolType & > ( Follow::follow ); +auto FollowLG2 = registration::AbstractRegister < Follow, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > >, const grammar::LG < > &, const DefaultSymbolType & > ( Follow::follow ); +auto FollowLeftLG2 = registration::AbstractRegister < Follow, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > >, const grammar::LeftLG < > &, const DefaultSymbolType & > ( Follow::follow ); +auto FollowLeftRG2 = registration::AbstractRegister < Follow, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > >, const grammar::LeftRG < > &, const DefaultSymbolType & > ( Follow::follow ); +auto FollowRightLG2 = registration::AbstractRegister < Follow, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > >, const grammar::RightLG < > &, const DefaultSymbolType & > ( Follow::follow ); +auto FollowRightRG2 = registration::AbstractRegister < Follow, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > >, const grammar::RightRG < > &, const DefaultSymbolType & > ( Follow::follow ); } /* namespace parsing */ diff --git a/alib2algo_experimental/src/grammar/parsing/Follow.h b/alib2algo_experimental/src/grammar/parsing/Follow.h index 42396a77f7..ea65471c9a 100644 --- a/alib2algo_experimental/src/grammar/parsing/Follow.h +++ b/alib2algo_experimental/src/grammar/parsing/Follow.h @@ -17,7 +17,6 @@ #include <exception/CommonException.h> #include <grammar/Grammar.h> -#include <string/Epsilon.h> #include "First.h" @@ -27,18 +26,18 @@ namespace parsing { class Follow { template < class T, class TerminalSymbolType, class NonterminalSymbolType > - static void follow ( const T & grammar, ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > > & followSet ); + static void follow ( const T & grammar, ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > > & followSet ); public: template < class T, class TerminalSymbolType = typename grammar::TerminalSymbolTypeOfGrammar < T >, class NonterminalSymbolType = typename grammar::NonterminalSymbolTypeOfGrammar < T > > - static ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > > follow ( const T & grammar ); + static ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > > follow ( const T & grammar ); template < class T, class NonterminalSymbolType, class TerminalSymbolType = typename grammar::TerminalSymbolTypeOfGrammar < T > > - static ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > follow ( const T & grammar, const NonterminalSymbolType & nt ); + static ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > follow ( const T & grammar, const NonterminalSymbolType & nt ); }; template < class T, class TerminalSymbolType, class NonterminalSymbolType > -void Follow::follow ( const T & grammar, ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > > & followSet ) { +void Follow::follow ( const T & grammar, ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > > & followSet ) { auto rawRules = grammar::RawRules::getRawRules ( grammar ); for ( const std::pair < const NonterminalSymbolType, ext::set < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > > > & rule : rawRules ) { const NonterminalSymbolType & X = rule.first; @@ -51,10 +50,10 @@ void Follow::follow ( const T & grammar, ext::map < NonterminalSymbolType, ext:: if ( ! grammar.getNonterminalAlphabet ( ).count ( Y ) ) continue; - ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > firstBeta = First::first ( grammar, ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > ( std::next ( it ), rhs.end ( ) ) ); + ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > firstBeta = First::first ( grammar, ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > ( std::next ( it ), rhs.end ( ) ) ); - if ( firstBeta.count ( ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > >::template from < string::Epsilon < TerminalSymbolType > > ( ) ) ) { - firstBeta.erase ( ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > >::template from < string::Epsilon < TerminalSymbolType > > ( ) ); + if ( firstBeta.count ( ext::variant < TerminalSymbolType, DefaultEpsilonType >::template from < DefaultEpsilonType > ( ) ) ) { + firstBeta.erase ( ext::variant < TerminalSymbolType, DefaultEpsilonType >::template from < DefaultEpsilonType > ( ) ); followSet [ Y.template get < TerminalSymbolType > ( ) ].insert ( followSet[X].begin ( ), followSet[X].end ( ) ); } @@ -65,7 +64,7 @@ void Follow::follow ( const T & grammar, ext::map < NonterminalSymbolType, ext:: } template < class T, class TerminalSymbolType, class NonterminalSymbolType > -ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > > Follow::follow ( const T & grammar ) { +ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > > Follow::follow ( const T & grammar ) { /* * 1. Follow(S) = { \varepsilon } * Follow(A) = {} forall A \in N, A \neq S @@ -77,14 +76,14 @@ ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, * 3. goto 2 if any follow set was changed in prev step. */ - ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > > followSet1; + ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > > followSet1; for ( const NonterminalSymbolType & symb : grammar.getNonterminalAlphabet ( ) ) followSet1[symb]; - followSet1[grammar.getInitialSymbol ( )] = { ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > >::template from < string::Epsilon < TerminalSymbolType > > ( ) }; + followSet1[grammar.getInitialSymbol ( )] = { ext::variant < TerminalSymbolType, DefaultEpsilonType >::template from < DefaultEpsilonType > ( ) }; - ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > > followSet2 = followSet1; + ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > > followSet2 = followSet1; do { follow ( grammar, followSet2 ); @@ -99,7 +98,7 @@ ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, } template < class T, class NonterminalSymbolType, class TerminalSymbolType > -ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > Follow::follow ( const T & grammar, const NonterminalSymbolType & nt ) { +ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > Follow::follow ( const T & grammar, const NonterminalSymbolType & nt ) { if ( ! grammar.getNonterminalAlphabet ( ).count ( nt ) ) throw exception::CommonException ( "Follow: Given symbol is not nonterminal." ); diff --git a/alib2algo_experimental/src/grammar/parsing/LL1ParseTable.cpp b/alib2algo_experimental/src/grammar/parsing/LL1ParseTable.cpp index b1834d71ce..e966d7a333 100644 --- a/alib2algo_experimental/src/grammar/parsing/LL1ParseTable.cpp +++ b/alib2algo_experimental/src/grammar/parsing/LL1ParseTable.cpp @@ -22,15 +22,15 @@ namespace grammar { namespace parsing { -auto LL1ParseTableCFG = registration::AbstractRegister < LL1ParseTable, ext::map < ext::pair < ext::variant < DefaultSymbolType, string::Epsilon < > >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > >, const grammar::CFG < > & > ( LL1ParseTable::parseTable ); -auto LL1ParseTableEpsilonFreeCFG = registration::AbstractRegister < LL1ParseTable, ext::map < ext::pair < ext::variant < DefaultSymbolType, string::Epsilon < > >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > >, const grammar::EpsilonFreeCFG < > & > ( LL1ParseTable::parseTable ); -auto LL1ParseTableGNF = registration::AbstractRegister < LL1ParseTable, ext::map < ext::pair < ext::variant < DefaultSymbolType, string::Epsilon < > >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > >, const grammar::GNF < > & > ( LL1ParseTable::parseTable ); -auto LL1ParseTableCNF = registration::AbstractRegister < LL1ParseTable, ext::map < ext::pair < ext::variant < DefaultSymbolType, string::Epsilon < > >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > >, const grammar::CNF < > & > ( LL1ParseTable::parseTable ); -auto LL1ParseTableLG = registration::AbstractRegister < LL1ParseTable, ext::map < ext::pair < ext::variant < DefaultSymbolType, string::Epsilon < > >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > >, const grammar::LG < > & > ( LL1ParseTable::parseTable ); -auto LL1ParseTableLeftLG = registration::AbstractRegister < LL1ParseTable, ext::map < ext::pair < ext::variant < DefaultSymbolType, string::Epsilon < > >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > >, const grammar::LeftLG < > & > ( LL1ParseTable::parseTable ); -auto LL1ParseTableLeftRG = registration::AbstractRegister < LL1ParseTable, ext::map < ext::pair < ext::variant < DefaultSymbolType, string::Epsilon < > >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > >, const grammar::LeftRG < > & > ( LL1ParseTable::parseTable ); -auto LL1ParseTableRightLG = registration::AbstractRegister < LL1ParseTable, ext::map < ext::pair < ext::variant < DefaultSymbolType, string::Epsilon < > >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > >, const grammar::RightLG < > & > ( LL1ParseTable::parseTable ); -auto LL1ParseTableRightRG = registration::AbstractRegister < LL1ParseTable, ext::map < ext::pair < ext::variant < DefaultSymbolType, string::Epsilon < > >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > >, const grammar::RightRG < > & > ( LL1ParseTable::parseTable ); +auto LL1ParseTableCFG = registration::AbstractRegister < LL1ParseTable, ext::map < ext::pair < ext::variant < DefaultSymbolType, DefaultEpsilonType >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > >, const grammar::CFG < > & > ( LL1ParseTable::parseTable ); +auto LL1ParseTableEpsilonFreeCFG = registration::AbstractRegister < LL1ParseTable, ext::map < ext::pair < ext::variant < DefaultSymbolType, DefaultEpsilonType >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > >, const grammar::EpsilonFreeCFG < > & > ( LL1ParseTable::parseTable ); +auto LL1ParseTableGNF = registration::AbstractRegister < LL1ParseTable, ext::map < ext::pair < ext::variant < DefaultSymbolType, DefaultEpsilonType >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > >, const grammar::GNF < > & > ( LL1ParseTable::parseTable ); +auto LL1ParseTableCNF = registration::AbstractRegister < LL1ParseTable, ext::map < ext::pair < ext::variant < DefaultSymbolType, DefaultEpsilonType >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > >, const grammar::CNF < > & > ( LL1ParseTable::parseTable ); +auto LL1ParseTableLG = registration::AbstractRegister < LL1ParseTable, ext::map < ext::pair < ext::variant < DefaultSymbolType, DefaultEpsilonType >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > >, const grammar::LG < > & > ( LL1ParseTable::parseTable ); +auto LL1ParseTableLeftLG = registration::AbstractRegister < LL1ParseTable, ext::map < ext::pair < ext::variant < DefaultSymbolType, DefaultEpsilonType >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > >, const grammar::LeftLG < > & > ( LL1ParseTable::parseTable ); +auto LL1ParseTableLeftRG = registration::AbstractRegister < LL1ParseTable, ext::map < ext::pair < ext::variant < DefaultSymbolType, DefaultEpsilonType >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > >, const grammar::LeftRG < > & > ( LL1ParseTable::parseTable ); +auto LL1ParseTableRightLG = registration::AbstractRegister < LL1ParseTable, ext::map < ext::pair < ext::variant < DefaultSymbolType, DefaultEpsilonType >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > >, const grammar::RightLG < > & > ( LL1ParseTable::parseTable ); +auto LL1ParseTableRightRG = registration::AbstractRegister < LL1ParseTable, ext::map < ext::pair < ext::variant < DefaultSymbolType, DefaultEpsilonType >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > >, const grammar::RightRG < > & > ( LL1ParseTable::parseTable ); } /* namespace parsing */ diff --git a/alib2algo_experimental/src/grammar/parsing/LL1ParseTable.h b/alib2algo_experimental/src/grammar/parsing/LL1ParseTable.h index a9610072c5..f1f82356e3 100644 --- a/alib2algo_experimental/src/grammar/parsing/LL1ParseTable.h +++ b/alib2algo_experimental/src/grammar/parsing/LL1ParseTable.h @@ -14,7 +14,6 @@ #include <alib/map> #include <grammar/Grammar.h> -#include <string/Epsilon.h> #include "First.h" #include "Follow.h" @@ -26,31 +25,31 @@ namespace parsing { class LL1ParseTable { public: template < class T, class TerminalSymbolType = typename grammar::TerminalSymbolTypeOfGrammar < T >, class NonterminalSymbolType = typename grammar::NonterminalSymbolTypeOfGrammar < T > > - static ext::map < ext::pair < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > >, NonterminalSymbolType >, ext::set < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > > > parseTable ( const T & grammar ); + static ext::map < ext::pair < ext::variant < TerminalSymbolType, DefaultEpsilonType >, NonterminalSymbolType >, ext::set < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > > > parseTable ( const T & grammar ); }; template < class T, class TerminalSymbolType, class NonterminalSymbolType > -ext::map < ext::pair < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > >, NonterminalSymbolType >, ext::set < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > > > LL1ParseTable::parseTable ( const T & grammar ) { - ext::map < ext::pair < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > >, NonterminalSymbolType >, ext::set < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > > > res; +ext::map < ext::pair < ext::variant < TerminalSymbolType, DefaultEpsilonType >, NonterminalSymbolType >, ext::set < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > > > LL1ParseTable::parseTable ( const T & grammar ) { + ext::map < ext::pair < ext::variant < TerminalSymbolType, DefaultEpsilonType >, NonterminalSymbolType >, ext::set < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > > > res; - ext::map < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > >, ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > > first = First::first ( grammar ); - ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > > > follow = Follow::follow ( grammar ); + ext::map < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > >, ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > > first = First::first ( grammar ); + ext::map < NonterminalSymbolType, ext::set < ext::variant < TerminalSymbolType, DefaultEpsilonType > > > follow = Follow::follow ( grammar ); auto rawRules = grammar::RawRules::getRawRules ( grammar ); for ( const std::pair < const NonterminalSymbolType, ext::set < ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > > > & transition : rawRules ) { const NonterminalSymbolType & lhs = transition.first; for ( const ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > & rhs : transition.second ) { - for ( const ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > & firstElem : first[rhs] ) { - if ( firstElem.template is < string::Epsilon < TerminalSymbolType > > ( ) ) + for ( const ext::variant < TerminalSymbolType, DefaultEpsilonType > & firstElem : first[rhs] ) { + if ( firstElem.template is < DefaultEpsilonType > ( ) ) continue; res [ ext::make_pair ( firstElem, lhs ) ].insert ( rhs ); } - if ( first[rhs].count ( ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > >::template from < string::Epsilon < TerminalSymbolType > > ( ) ) ) - for ( const ext::variant < TerminalSymbolType, string::Epsilon < TerminalSymbolType > > & followElem : follow[lhs] ) + if ( first[rhs].count ( ext::variant < TerminalSymbolType, DefaultEpsilonType >::template from < DefaultEpsilonType > ( ) ) ) + for ( const ext::variant < TerminalSymbolType, DefaultEpsilonType > & followElem : follow[lhs] ) res [ ext::make_pair ( followElem, lhs ) ].insert ( rhs ); } diff --git a/alib2algo_experimental/src/grammar/parsing/SLR1ParseTable.cpp b/alib2algo_experimental/src/grammar/parsing/SLR1ParseTable.cpp index 1d3993cd18..31a7e6336a 100644 --- a/alib2algo_experimental/src/grammar/parsing/SLR1ParseTable.cpp +++ b/alib2algo_experimental/src/grammar/parsing/SLR1ParseTable.cpp @@ -41,9 +41,9 @@ LRActionTable SLR1ParseTable::getActionTable ( grammar::CFG < > originalGrammar continue; } - ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > followSet = grammar::parsing::Follow::follow ( augmentedGrammar, leftHandSide ); + ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > followSet = grammar::parsing::Follow::follow ( augmentedGrammar, leftHandSide ); ext::pair < DefaultSymbolType, ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > currentRule = { leftHandSide, rightHandSide }; - for ( const ext::variant < DefaultSymbolType, string::Epsilon < > > & followSymbol : followSet ) { + for ( const ext::variant < DefaultSymbolType, DefaultEpsilonType > & followSymbol : followSet ) { if ( followSymbol.is < DefaultSymbolType > ( ) ) { insertToActionTable(actionTable, { state, followSymbol.get < DefaultSymbolType > ( ) }, { LRAction::Reduce, currentRule } ); } else { diff --git a/alib2algo_experimental/test-src/grammar/parsing/FirstTest.cpp b/alib2algo_experimental/test-src/grammar/parsing/FirstTest.cpp index 3885752c5d..21a4b883b5 100644 --- a/alib2algo_experimental/test-src/grammar/parsing/FirstTest.cpp +++ b/alib2algo_experimental/test-src/grammar/parsing/FirstTest.cpp @@ -2,7 +2,6 @@ #include "grammar/parsing/First.h" #include "grammar/ContextFree/CFG.h" -#include "string/Epsilon.h" TEST_CASE ( "LL1 First", "[unit][grammar]" ) { SECTION ( "Test 1" ) { @@ -35,30 +34,30 @@ TEST_CASE ( "LL1 First", "[unit][grammar]" ) { grammar.addRule ( nF, rhsF2 ); // -------------------------------------------------- - ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > > first; + ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > > first; - first[rhsE1] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { + first[rhsE1] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { tA, tL }; - first[rhsE2] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { + first[rhsE2] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { tA, tL }; - first[rhsT1] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { + first[rhsT1] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { tA, tL }; - first[rhsT2] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { + first[rhsT2] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { tA, tL }; - first[rhsF1] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { + first[rhsF1] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { tA }; - first[rhsF2] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { + first[rhsF2] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { tL }; // -------------------------------------------------- - ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > > firstAlgo; + ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > > firstAlgo; for ( const auto & rule : grammar::RawRules::getRawRules ( grammar ) ) for ( const auto & rhs : rule.second ) @@ -117,53 +116,53 @@ TEST_CASE ( "LL1 First", "[unit][grammar]" ) { grammar.addRule ( nF, rhsF2 ); // -------------------------------------------------- - ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > > first; + ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > > first; - first[rhsS1] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { + first[rhsS1] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { tA, tB }; - first[rhsS2] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { + first[rhsS2] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { tD }; - first[rhsS3] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { + first[rhsS3] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { tC }; - first[rhsA1] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { + first[rhsA1] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { tA }; - first[rhsA2] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { + first[rhsA2] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { tB }; - first[rhsB1] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { + first[rhsB1] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { tA }; - first[rhsB2] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { + first[rhsB2] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { tB }; - first[rhsC1] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { + first[rhsC1] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { tA }; - first[rhsC2] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { + first[rhsC2] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { tE }; - first[rhsD1] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { + first[rhsD1] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { tC }; - first[rhsE1] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { + first[rhsE1] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { tC }; - first[rhsE2] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { - string::Epsilon < >::EPSILON + first[rhsE2] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { + ext::variant < DefaultSymbolType, DefaultEpsilonType >::template from < DefaultEpsilonType > ( ) }; - first[rhsF1] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { + first[rhsF1] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { tE }; - first[rhsF2] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { - string::Epsilon < >::EPSILON + first[rhsF2] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { + ext::variant < DefaultSymbolType, DefaultEpsilonType >::template from < DefaultEpsilonType > ( ) }; // -------------------------------------------------- - ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > > firstAlgo; + ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > > firstAlgo; for ( const auto & rule : grammar::RawRules::getRawRules ( grammar ) ) for ( const auto & rhs : rule.second ) @@ -186,7 +185,7 @@ TEST_CASE ( "LL1 First", "[unit][grammar]" ) { grammar.addRule ( A, ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > { A, c } ); grammar.addRule ( A, ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > { d } ); - ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > > res = { { { d }, { d } }, { { A, c }, { d } } }; + ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > > res = { { { d }, { d } }, { { A, c }, { d } } }; CHECK ( res == grammar::parsing::First::first ( grammar ) ); } @@ -213,9 +212,9 @@ TEST_CASE ( "LL1 First", "[unit][grammar]" ) { grammar.addRule ( B, ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > { f, S } ); grammar.addRule ( B, ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > { } ); - ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > > res = + ext::map < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > >, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > > res = { - { { A, a }, { c, f, a } }, { { b, S }, { b } }, { { c, A, d }, { c } }, { { B }, { f, string::Epsilon < >::EPSILON } }, { { f, S }, { f } }, { { }, { string::Epsilon < >::EPSILON } } + { { A, a }, { c, f, a } }, { { b, S }, { b } }, { { c, A, d }, { c } }, { { B }, { f, ext::variant < DefaultSymbolType, DefaultEpsilonType >::template from < DefaultEpsilonType > ( ) } }, { { f, S }, { f } }, { { }, { ext::variant < DefaultSymbolType, DefaultEpsilonType >::template from < DefaultEpsilonType > ( ) } } }; CHECK ( res == grammar::parsing::First::first ( grammar ) ); } diff --git a/alib2algo_experimental/test-src/grammar/parsing/FollowTest.cpp b/alib2algo_experimental/test-src/grammar/parsing/FollowTest.cpp index dece54940d..7a8bd8d7e8 100644 --- a/alib2algo_experimental/test-src/grammar/parsing/FollowTest.cpp +++ b/alib2algo_experimental/test-src/grammar/parsing/FollowTest.cpp @@ -2,7 +2,6 @@ #include "grammar/parsing/Follow.h" #include "grammar/ContextFree/CFG.h" -#include "string/Epsilon.h" TEST_CASE ( "LL1 Follow", "[unit][grammar]" ) { SECTION ( "Test 1" ) { @@ -35,21 +34,21 @@ TEST_CASE ( "LL1 Follow", "[unit][grammar]" ) { grammar.addRule ( nF, rhsF2 ); // -------------------------------------------------- - ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > > follow; + ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > > follow; - follow[nE] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { - string::Epsilon < >::EPSILON, tP, tR + follow[nE] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { + ext::variant < DefaultSymbolType, DefaultEpsilonType >::template from < DefaultEpsilonType > ( ), tP, tR }; - follow[nT] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { - string::Epsilon < >::EPSILON, tP, tR, tS + follow[nT] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { + ext::variant < DefaultSymbolType, DefaultEpsilonType >::template from < DefaultEpsilonType > ( ), tP, tR, tS }; - follow[nF] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { - string::Epsilon < >::EPSILON, tP, tR, tS + follow[nF] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { + ext::variant < DefaultSymbolType, DefaultEpsilonType >::template from < DefaultEpsilonType > ( ), tP, tR, tS }; // -------------------------------------------------- - ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > > followAlgo; + ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > > followAlgo; for ( const auto & nt : grammar.getNonterminalAlphabet ( ) ) followAlgo[nt] = grammar::parsing::Follow::follow ( grammar, nt ); @@ -107,33 +106,33 @@ TEST_CASE ( "LL1 Follow", "[unit][grammar]" ) { grammar.addRule ( nF, rhsF2 ); // -------------------------------------------------- - ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > > follow; + ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > > follow; - follow[nS] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { - string::Epsilon < >::EPSILON + follow[nS] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { + ext::variant < DefaultSymbolType, DefaultEpsilonType >::template from < DefaultEpsilonType > ( ) }; - follow[nA] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { - string::Epsilon < >::EPSILON + follow[nA] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { + ext::variant < DefaultSymbolType, DefaultEpsilonType >::template from < DefaultEpsilonType > ( ) }; - follow[nB] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { + follow[nB] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { tD }; - follow[nC] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { - string::Epsilon < >::EPSILON + follow[nC] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { + ext::variant < DefaultSymbolType, DefaultEpsilonType >::template from < DefaultEpsilonType > ( ) }; - follow[nD] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { + follow[nD] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { tD }; - follow[nE] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { - string::Epsilon < >::EPSILON + follow[nE] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { + ext::variant < DefaultSymbolType, DefaultEpsilonType >::template from < DefaultEpsilonType > ( ) }; - follow[nF] = ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > { + follow[nF] = ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > { tD }; // -------------------------------------------------- - ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, string::Epsilon < > > > > followAlgo; + ext::map < DefaultSymbolType, ext::set < ext::variant < DefaultSymbolType, DefaultEpsilonType > > > followAlgo; for ( const auto & nt : grammar.getNonterminalAlphabet ( ) ) followAlgo[nt] = grammar::parsing::Follow::follow ( grammar, nt ); diff --git a/alib2algo_experimental/test-src/grammar/parsing/LL1ParseTableTest.cpp b/alib2algo_experimental/test-src/grammar/parsing/LL1ParseTableTest.cpp index fda66736dd..9aa2188691 100644 --- a/alib2algo_experimental/test-src/grammar/parsing/LL1ParseTableTest.cpp +++ b/alib2algo_experimental/test-src/grammar/parsing/LL1ParseTableTest.cpp @@ -2,7 +2,6 @@ #include "grammar/parsing/LL1ParseTable.h" #include "grammar/ContextFree/CFG.h" -#include "string/Epsilon.h" TEST_CASE ( "LL1 Parse Table", "[unit][grammar]" ) { SECTION ( "Test 1" ) { @@ -41,14 +40,14 @@ TEST_CASE ( "LL1 Parse Table", "[unit][grammar]" ) { grammar.addRule ( nF, rhsF2 ); // -------------------------------------------------- - ext::map < ext::pair < ext::variant < DefaultSymbolType, string::Epsilon < > >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > > parseTable; + ext::map < ext::pair < ext::variant < DefaultSymbolType, DefaultEpsilonType >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > > parseTable; parseTable[ext::make_pair ( tA, nE )].insert ( rhsE1 ); parseTable[ext::make_pair ( tL, nE )].insert ( rhsE1 ); parseTable[ext::make_pair ( tP, nEp )].insert ( rhsEp1 ); parseTable[ext::make_pair ( tR, nEp )].insert ( rhsEp2 ); - parseTable[ext::make_pair ( string::Epsilon < >::EPSILON, nEp )].insert ( rhsEp2 ); + parseTable[ext::make_pair ( ext::variant < DefaultSymbolType, DefaultEpsilonType >::template from < DefaultEpsilonType > ( ), nEp )].insert ( rhsEp2 ); parseTable[ext::make_pair ( tA, nT )].insert ( rhsT1 ); parseTable[ext::make_pair ( tL, nT )].insert ( rhsT1 ); @@ -56,14 +55,14 @@ TEST_CASE ( "LL1 Parse Table", "[unit][grammar]" ) { parseTable[ext::make_pair ( tS, nTp )].insert ( rhsTp1 ); parseTable[ext::make_pair ( tP, nTp )].insert ( rhsTp2 ); parseTable[ext::make_pair ( tR, nTp )].insert ( rhsTp2 ); - parseTable[ext::make_pair ( string::Epsilon < >::EPSILON, nTp )].insert ( rhsTp2 ); + parseTable[ext::make_pair ( ext::variant < DefaultSymbolType, DefaultEpsilonType >::template from < DefaultEpsilonType > ( ), nTp )].insert ( rhsTp2 ); parseTable[ext::make_pair ( tA, nF )].insert ( rhsF1 ); parseTable[ext::make_pair ( tL, nF )].insert ( rhsF2 ); // -------------------------------------------------- - ext::map < ext::pair < ext::variant < DefaultSymbolType, string::Epsilon < > >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > > parseTableAlgo = grammar::parsing::LL1ParseTable::parseTable ( grammar ); + ext::map < ext::pair < ext::variant < DefaultSymbolType, DefaultEpsilonType >, DefaultSymbolType >, ext::set < ext::vector < ext::variant < DefaultSymbolType, DefaultSymbolType > > > > parseTableAlgo = grammar::parsing::LL1ParseTable::parseTable ( grammar ); CHECK ( parseTable == parseTableAlgo ); } diff --git a/alib2data/src/PrimitiveRegistrator.cpp b/alib2data/src/PrimitiveRegistrator.cpp index 6e33adc20e..b7237acf1a 100644 --- a/alib2data/src/PrimitiveRegistrator.cpp +++ b/alib2data/src/PrimitiveRegistrator.cpp @@ -23,7 +23,9 @@ #include <alphabet/xml/RankedSymbol.h> #include <string/xml/LinearString.h> -#include <string/xml/Epsilon.h> + +#include <common/DefaultEpsilonType.h> +#include <object/xml/Void.h> namespace { @@ -43,8 +45,8 @@ public: abstraction::XmlParserRegistry::registerXmlParser < object::Object > ( "DefaultStateType" ); core::xmlApi < object::Object >::template registerXmlWriter < ext::set < common::ranked_symbol < object::Object, unsigned > > > ( ); - core::xmlApi < object::Object >::template registerXmlWriter < ext::pair < ext::set < ext::pair < object::Object, object::Object > >, ext::variant < string::Epsilon < object::Object >, object::Object > > > ( ); - core::xmlApi < object::Object >::template registerXmlWriter < ext::pair < object::Object, ext::variant < string::Epsilon < object::Object >, object::Object > > > ( ); + core::xmlApi < object::Object >::template registerXmlWriter < ext::pair < ext::set < ext::pair < object::Object, object::Object > >, ext::variant < DefaultEpsilonType, object::Object > > > ( ); + core::xmlApi < object::Object >::template registerXmlWriter < ext::pair < object::Object, ext::variant < DefaultEpsilonType, object::Object > > > ( ); core::xmlApi < object::Object >::template registerXmlWriter < ext::set < common::ranked_symbol < ext::pair < object::Object, unsigned int >, unsigned int > > > ( ); core::xmlApi < object::Object >::template registerXmlWriter < common::ranked_symbol < ext::pair < object::Object, unsigned int>, unsigned int > > ( ); } @@ -56,8 +58,8 @@ public: abstraction::XmlParserRegistry::unregisterXmlParser ( "DefaultStateType" ); core::xmlApi < object::Object >::template unregisterXmlWriter < ext::set < common::ranked_symbol < object::Object, unsigned > > > ( ); - core::xmlApi < object::Object >::template unregisterXmlWriter < ext::pair < ext::set < ext::pair < object::Object, object::Object > >, ext::variant < string::Epsilon < object::Object >, object::Object > > > ( ); - core::xmlApi < object::Object >::template unregisterXmlWriter < ext::pair < object::Object, ext::variant < string::Epsilon < object::Object >, object::Object > > > ( ); + core::xmlApi < object::Object >::template unregisterXmlWriter < ext::pair < ext::set < ext::pair < object::Object, object::Object > >, ext::variant < DefaultEpsilonType, object::Object > > > ( ); + core::xmlApi < object::Object >::template unregisterXmlWriter < ext::pair < object::Object, ext::variant < DefaultEpsilonType, object::Object > > > ( ); core::xmlApi < object::Object >::template unregisterXmlWriter < ext::set < common::ranked_symbol < ext::pair < object::Object, unsigned int >, unsigned int > > > ( ); core::xmlApi < object::Object >::template unregisterXmlWriter < common::ranked_symbol < ext::pair < object::Object, unsigned int>, unsigned int > > ( ); } diff --git a/alib2data/src/common/DefaultEpsilonType.h b/alib2data/src/common/DefaultEpsilonType.h index 3d10482199..a11b5faa88 100644 --- a/alib2data/src/common/DefaultEpsilonType.h +++ b/alib2data/src/common/DefaultEpsilonType.h @@ -8,9 +8,6 @@ #ifndef DEFAULT_EPSILON_TYPE_H_ #define DEFAULT_EPSILON_TYPE_H_ -#include <common/DefaultSymbolType.h> -#include <string/Epsilon.h> - -typedef string::Epsilon < DefaultSymbolType > DefaultEpsilonType; +typedef void DefaultEpsilonType; #endif /* DEFAULT_EPSILON_TYPE_H_ */ diff --git a/alib2data/src/string/CyclicString.cpp b/alib2data/src/string/CyclicString.cpp index 9dbb4daa82..8b3f225e6b 100644 --- a/alib2data/src/string/CyclicString.cpp +++ b/alib2data/src/string/CyclicString.cpp @@ -14,8 +14,6 @@ template class string::CyclicString < >; namespace { -static auto CyclicStringFromEpsilon = registration::CastRegister < string::CyclicString < >, string::Epsilon < > > ( ); - static auto valuePrinter = registration::ValuePrinterRegister < string::CyclicString < > > ( ); } /* namespace */ diff --git a/alib2data/src/string/CyclicString.h b/alib2data/src/string/CyclicString.h index 2dcd4f54ad..1482cd16e0 100644 --- a/alib2data/src/string/CyclicString.h +++ b/alib2data/src/string/CyclicString.h @@ -40,8 +40,6 @@ #include <core/normalize.hpp> #include <alphabet/common/SymbolNormalize.h> -#include "Epsilon.h" - namespace string { class GeneralAlphabet; @@ -102,13 +100,6 @@ public: */ explicit CyclicString ( const char * str ); - /** - * \brief Creates a new instance of the string based on an epsilon. It copies the alphabet and sets the content to empty. - * - * \param epsilon the epsilon to base the string on - */ - explicit CyclicString ( const Epsilon < SymbolType > & epsilon ); - /** * Getter of the alphabet. * @@ -199,12 +190,6 @@ public: explicit operator std::string ( ) const; }; -} /* namespace string */ - -#include "Epsilon.h" - -namespace string { - template < class SymbolType > CyclicString < SymbolType >::CyclicString(ext::set<SymbolType> alphabet, ext::vector<SymbolType> str) : core::Components < CyclicString, ext::set < SymbolType >, component::Set, GeneralAlphabet > ( std::move ( alphabet ) ) { setContent(std::move(str)); @@ -226,10 +211,6 @@ template < class SymbolType > CyclicString < SymbolType >::CyclicString(const char* str) : CyclicString((std::string) str) { } -template < class SymbolType > -CyclicString < SymbolType >::CyclicString(const Epsilon < SymbolType > & epsilon) : CyclicString ( epsilon.getAlphabet( ), ext::vector < SymbolType > ( ) ) { -} - template < class SymbolType > const ext::vector < SymbolType > & CyclicString < SymbolType >::getContent ( ) const & { return this->m_Data; diff --git a/alib2data/src/string/Epsilon.cpp b/alib2data/src/string/Epsilon.cpp deleted file mode 100644 index eaafbc38e8..0000000000 --- a/alib2data/src/string/Epsilon.cpp +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Epsilon.cpp - * - * Created on: Jan 30, 2014 - * Author: Jan Travnicek - */ - -#include "Epsilon.h" - -#include <registration/ValuePrinterRegistration.hpp> -#include <registration/CastRegistration.hpp> - -template class string::Epsilon < >; - -namespace { - -static auto valuePrinter = registration::ValuePrinterRegister < string::Epsilon < > > ( ); - -} /* namespace */ diff --git a/alib2data/src/string/Epsilon.h b/alib2data/src/string/Epsilon.h deleted file mode 100644 index 29e226c0d0..0000000000 --- a/alib2data/src/string/Epsilon.h +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Epsilon.h - * - * This file is part of Algorithms library toolkit. - * Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz) - - * Algorithms library toolkit is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - - * Algorithms library toolkit is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>. - * - * Created on: Nov 23, 2013 - * Author: Jan Travnicek - */ - -#ifndef EPSILON_H_ -#define EPSILON_H_ - -#include <alib/set> -#include <alib/vector> -#include <alib/compare> - -#include <core/components.hpp> - -#include <common/DefaultSymbolType.h> - -#include <exception/CommonException.h> - -#include <core/normalize.hpp> -#include <alphabet/common/SymbolNormalize.h> - -namespace string { - -class GeneralAlphabet; - -/** - * \brief - * Representation of epsilon - - * \details - * Definition is similar to a linear string however cyclic. - * S = (A, C), - * A (Alphabet) = finite set of symbols, - * C (Content) = linear representation of cyclic string in some rotation - * - * Note that two same cyclic strings compare not equal in different rotation. In order to either normalize rotation or compare without influence of particular rotation, use respective algoritm. - * - * \tparam SymbolType used for the terminal alphabet - */ -template < class SymbolType = DefaultSymbolType > -class Epsilon final : public ext::CompareOperators < Epsilon < SymbolType > >, public core::Components < Epsilon < SymbolType >, ext::set < SymbolType >, component::Set, GeneralAlphabet > { -public: - /** - * \brief Creates a new instance of the epsilon - */ - Epsilon ( ); - - /** - * \brief Creates a new instance of the epsilon with a concrete alphabet. - * - * \param alphabet the initial alphabet of the string - */ - Epsilon ( ext::set < SymbolType > alphabet ); - - /** - * Getter of the alphabet. - * - * \returns the alphabet of the string - */ - const ext::set < SymbolType > & getAlphabet ( ) const & { - return this->template accessComponent < GeneralAlphabet > ( ).get ( ); - } - - /** - * Getter of the alphabet. - * - * \returns the alphabet of the string - */ - ext::set < SymbolType > && getAlphabet ( ) && { - return std::move ( this->template accessComponent < GeneralAlphabet > ( ).get ( ) ); - } - - /** - * Adder of an alphabet symbols. - * - * \param symbols the new symbols to be added to the alphabet - */ - void extendAlphabet ( ext::set < SymbolType > symbols ) { - this->template accessComponent < GeneralAlphabet > ( ).add ( std::move ( symbols ) ); - } - - /** - * The actual compare method - * - * \param other the other instance - * - * \returns the actual relation between two by type same string instances - */ - int compare ( const Epsilon & other ) const; - - /** - * Print this object as raw representation to ostream. - * - * \param out ostream where to print - * \param instance object to print - * - * \returns modified output stream - */ - friend std::ostream & operator << ( std::ostream & out, const Epsilon & instance ) { - return out << "(Epsilon "; - out << "alphabet = " << instance.getAlphabet ( ); - out << ")"; - } - - /** - * Casts this instance to as compact as possible string representation. - * - * \returns string representation of the object - */ - explicit operator std::string ( ) const; - - /** - * Prepared defaultly constructed epsilon instance. - */ - static Epsilon EPSILON; -}; - -template < class SymbolType > -Epsilon < SymbolType >::Epsilon ( ext::set < SymbolType > alphabet ) : core::Components < Epsilon, ext::set < SymbolType >, component::Set, GeneralAlphabet > ( std::move ( alphabet ) ) { -} - -template < class SymbolType > -Epsilon < SymbolType >::Epsilon() : Epsilon ( ext::set< SymbolType > ( ) ) { -} - -template < class SymbolType > -int Epsilon < SymbolType >::compare(const Epsilon& other) const { - static ext::compare<ext::set<SymbolType>> comp; - return comp(getAlphabet(), other.getAlphabet()); -} - -template < class SymbolType > -Epsilon < SymbolType >::operator std::string ( ) const { - return "E"; -} - -template < class SymbolType > -Epsilon < SymbolType > Epsilon < SymbolType >::EPSILON = Epsilon < SymbolType >(); - -} /* namespace string */ - -namespace core { - -/** - * Helper class specifying constraints for the epsilon's internal alphabet component. - * - * \tparam SymbolType used for the alphabet of the epsilon. - */ -template < class SymbolType > -class SetConstraint< string::Epsilon < SymbolType >, SymbolType, string::GeneralAlphabet > { -public: - /** - * Returns true as the epsilon represents empty string. - * - * \param epsilon the tested epsilon - * \param symbol the tested symbol - * - * \returns true - */ - static bool used ( const string::Epsilon < SymbolType > &, const SymbolType & ) { - return false; - } - - /** - * Returns true as all symbols are possibly available to be in an alphabet. - * - * \param string the tested string - * \param symbol the tested symbol - * - * \returns true - */ - static bool available ( const string::Epsilon < SymbolType > &, const SymbolType & ) { - return true; - } - - /** - * All symbols are valid as symbols of an alphabet. - * - * \param string the tested string - * \param symbol the tested symbol - */ - static void valid ( const string::Epsilon < SymbolType > &, const SymbolType & ) { - } -}; - -/** - * Helper for normalisation of types specified by templates used as internal datatypes of symbols. - * - * \returns new instance of the string with default template parameters or unmodified instance if the template parameters were already default ones - */ -template < class SymbolType > -struct normalize < string::Epsilon < SymbolType > > { - static string::Epsilon < > eval ( string::Epsilon < SymbolType > && value ) { - ext::set < DefaultSymbolType > alphabet = alphabet::SymbolNormalize::normalizeAlphabet ( std::move ( value ).getAlphabet ( ) ); - return string::Epsilon < > ( std::move ( alphabet ) ); - } -}; - -} /* namespace core */ - -extern template class string::Epsilon < >; - -#endif /* EPSILON_H_ */ diff --git a/alib2data/src/string/LinearString.cpp b/alib2data/src/string/LinearString.cpp index 0e5a859d8b..a41d5b977d 100644 --- a/alib2data/src/string/LinearString.cpp +++ b/alib2data/src/string/LinearString.cpp @@ -20,8 +20,6 @@ static auto components = registration::ComponentRegister < string::LinearString static auto LinearStringFromString = registration::CastRegister < string::LinearString < char >, std::string > ( ); -static auto LinearStringFromEpsilon = registration::CastRegister < string::LinearString < >, string::Epsilon < > > ( ); - static auto LinearStringSet = registration::SetRegister < string::LinearString < > > ( ); static auto valuePrinter = registration::ValuePrinterRegister < string::LinearString < > > ( ); diff --git a/alib2data/src/string/LinearString.h b/alib2data/src/string/LinearString.h index df50c3eb4f..680d4b01b5 100644 --- a/alib2data/src/string/LinearString.h +++ b/alib2data/src/string/LinearString.h @@ -40,8 +40,6 @@ #include <core/normalize.hpp> #include <alphabet/common/SymbolNormalize.h> -#include "Epsilon.h" - namespace string { class GeneralAlphabet; @@ -99,13 +97,6 @@ public: */ explicit LinearString ( const char * str ); - /** - * \brief Creates a new instance of the string based on an epsilon. It copies the alphabet and sets the content to empty. - * - * \param epsilon the epsilon to base the string on - */ - explicit LinearString ( const Epsilon < SymbolType > & epsilon ); - /** * Getter of the alphabet. * @@ -203,12 +194,6 @@ public: explicit operator std::string ( ) const; }; -} /* namespace string */ - -#include "Epsilon.h" - -namespace string { - template < class SymbolType > LinearString < SymbolType >::LinearString(ext::set<SymbolType> alphabet, ext::vector<SymbolType> str) : core::Components < LinearString, ext::set < SymbolType >, component::Set, GeneralAlphabet > ( std::move ( alphabet ) ) { setContent(std::move(str)); @@ -230,10 +215,6 @@ template < class SymbolType > LinearString < SymbolType >::LinearString(const char* str) : LinearString ( ( std::string ) str ) { } -template < class SymbolType > -LinearString < SymbolType >::LinearString(const Epsilon < SymbolType > & epsilon) : LinearString ( epsilon.getAlphabet( ), ext::vector < SymbolType > ( ) ) { -} - template < class SymbolType > void LinearString < SymbolType >::appendSymbol ( SymbolType symbol ) { if ( getAlphabet().count ( symbol ) == 0 ) diff --git a/alib2data/src/string/WildcardLinearString.cpp b/alib2data/src/string/WildcardLinearString.cpp index 94641254d0..8bb66be8fa 100644 --- a/alib2data/src/string/WildcardLinearString.cpp +++ b/alib2data/src/string/WildcardLinearString.cpp @@ -18,7 +18,6 @@ namespace { static auto components = registration::ComponentRegister < string::WildcardLinearString < > > ( ); static auto WildcardLinearStringFromString = registration::CastRegister < string::WildcardLinearString < char >, std::string > ( ); -static auto WildcardLinearStringFromEpsilon = registration::CastRegister < string::WildcardLinearString < >, string::Epsilon < > > ( ); static auto WildcardLinearStringFromLinearString = registration::CastRegister < string::WildcardLinearString < >, string::LinearString < > > ( ); static auto valuePrinter = registration::ValuePrinterRegister < string::WildcardLinearString < > > ( ); diff --git a/alib2data/src/string/WildcardLinearString.h b/alib2data/src/string/WildcardLinearString.h index a81e37ff28..0638e104bc 100644 --- a/alib2data/src/string/WildcardLinearString.h +++ b/alib2data/src/string/WildcardLinearString.h @@ -93,21 +93,6 @@ public: */ explicit WildcardLinearString ( const char * str , char wildcard ); - /** - * \brief Creates a new instance of the string based on an epsilon. It copies the alphabet and sets the content to empty. The wildcard is set from the the parametery. - * - * \param epsilon the epsilon to base the string on - * \param wildcard the explicit wildcard symbol - */ - explicit WildcardLinearString ( const Epsilon < SymbolType > & epsilon, SymbolType wildcard ); - - /** - * \brief Creates a new instance of the string based on an epsilon. It copies the alphabet and sets the content to empty. The wildcard is defaultly constructed. - * - * \param epsilon the epsilon to base the string on - */ - explicit WildcardLinearString ( const Epsilon < SymbolType > & epsilon ); - /** * \brief Creates a new instance of the string based on a linear string. It copies the alphabet and content. The wildcard is set from the the parametery. * @@ -251,12 +236,6 @@ public: }; -} /* namespace string */ - -#include "Epsilon.h" - -namespace string { - template < class SymbolType > WildcardLinearString < SymbolType >::WildcardLinearString(ext::set<SymbolType> alphabet, ext::vector<SymbolType> str, SymbolType wildcard) : core::Components < WildcardLinearString, ext::set < SymbolType >, component::Set, GeneralAlphabet, SymbolType, component::Value, WildcardSymbol > ( std::move ( alphabet ), std::move(wildcard) ) { setContent(std::move(str)); @@ -278,14 +257,6 @@ template < class SymbolType > WildcardLinearString < SymbolType >::WildcardLinearString(const char* str, char wildcard) : WildcardLinearString ( ( std::string ) str, wildcard ) { } -template < class SymbolType > -WildcardLinearString < SymbolType >::WildcardLinearString(const Epsilon < SymbolType > & epsilon, SymbolType wildcard) : WildcardLinearString ( epsilon.getAlphabet( ) + ext::set < SymbolType > { wildcard }, ext::vector < SymbolType > ( ), wildcard ) { -} - -template < class SymbolType > -WildcardLinearString < SymbolType >::WildcardLinearString(const Epsilon < SymbolType > & epsilon ) : WildcardLinearString ( epsilon, alphabet::WildcardSymbol::instance < SymbolType > ( ) ) { -} - template < class SymbolType > WildcardLinearString < SymbolType >::WildcardLinearString(const LinearString < SymbolType > & string, SymbolType wildcard) : WildcardLinearString ( string.getAlphabet( ) + ext::set < SymbolType > { wildcard }, string.getContent ( ), wildcard ) { } diff --git a/alib2data/src/string/xml/Epsilon.cpp b/alib2data/src/string/xml/Epsilon.cpp deleted file mode 100644 index 969866625e..0000000000 --- a/alib2data/src/string/xml/Epsilon.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Epsilon.cpp - * - * Created on: Jan 30, 2014 - * Author: Jan Travnicek - */ - -#include "Epsilon.h" - -#include <object/Object.h> - -#include <registration/XmlRegistration.hpp> - -namespace { - -static auto xmlWrite = registration::XmlWriterRegister < string::Epsilon < > > ( ); -static auto xmlRead = registration::XmlReaderRegister < string::Epsilon < > > ( ); - -static auto xmlGroup = registration::XmlRegisterTypeInGroup < object::Object, string::Epsilon < > > ( ); - -} /* namespace */ diff --git a/alib2data/src/string/xml/Epsilon.h b/alib2data/src/string/xml/Epsilon.h deleted file mode 100644 index 5993b7bf2f..0000000000 --- a/alib2data/src/string/xml/Epsilon.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Epsilon.h - * - * Created on: Dec 1, 2017 - * Author: Jan Travnicek - */ - -#ifndef _XML_EPSILON_H_ -#define _XML_EPSILON_H_ - -#include <string/Epsilon.h> -#include <core/xmlApi.hpp> - -#include <string/xml/common/StringFromXmlParserCommon.h> -#include <string/xml/common/StringToXmlComposerCommon.h> - -namespace core { - -template < typename SymbolType > -struct xmlApi < string::Epsilon < SymbolType > > { - static string::Epsilon < SymbolType > parse ( ext::deque < sax::Token >::iterator & input ); - static bool first ( const ext::deque < sax::Token >::const_iterator & input ); - static std::string xmlTagName ( ); - static void compose ( ext::deque < sax::Token > & output, const string::Epsilon < SymbolType > & data ); -}; - -template < typename SymbolType > -string::Epsilon < SymbolType > xmlApi < string::Epsilon < SymbolType > >::parse ( ext::deque < sax::Token >::iterator & input ) { - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); - ext::set < SymbolType > alphabet = string::StringFromXmlParserCommon::parseAlphabet < SymbolType > ( input ); - sax::FromXMLParserHelper::popToken ( input, sax::Token::TokenType::END_ELEMENT, xmlTagName ( ) ); - return string::Epsilon < SymbolType > ( std::move ( alphabet ) ); -} - -template < typename SymbolType > -bool xmlApi < string::Epsilon < SymbolType > >::first ( const ext::deque < sax::Token >::const_iterator & input ) { - return sax::FromXMLParserHelper::isToken ( input, sax::Token::TokenType::START_ELEMENT, xmlTagName ( ) ); -} - -template < typename SymbolType > -std::string xmlApi < string::Epsilon < SymbolType > >::xmlTagName ( ) { - return "Epsilon"; -} - -template < typename SymbolType > -void xmlApi < string::Epsilon < SymbolType > >::compose ( ext::deque < sax::Token > & output, const string::Epsilon < SymbolType > & input ) { - output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::START_ELEMENT ); - string::StringToXmlComposerCommon::compose ( output, input.getAlphabet ( ) ); - output.emplace_back ( xmlTagName ( ), sax::Token::TokenType::END_ELEMENT ); -} - -} /* namespace core */ - -#endif /* _XML_EPSILON_H_ */ diff --git a/alib2data/test-src/string/StringTest.cpp b/alib2data/test-src/string/StringTest.cpp index a990a0988d..70c0b58a32 100644 --- a/alib2data/test-src/string/StringTest.cpp +++ b/alib2data/test-src/string/StringTest.cpp @@ -9,8 +9,6 @@ #include "string/xml/LinearString.h" #include "string/CyclicString.h" #include "string/xml/CyclicString.h" -#include "string/Epsilon.h" -#include "string/xml/Epsilon.h" #include "factory/XmlDataFactory.hpp" @@ -62,30 +60,30 @@ TEST_CASE ( "String", "[unit][data][string]" ) { } SECTION ( "String in map" ) { - ext::map < ext::variant < string::Epsilon < >, int >, int > testMap; - ext::variant < string::Epsilon < >, int > epsVar { - string::Epsilon < > { } + ext::map < ext::variant < string::LinearString < >, int >, int > testMap; + ext::variant < string::LinearString < >, int > epsVar { + string::LinearString < > { } }; - CHECK ( string::Epsilon < >::EPSILON == epsVar.get < string::Epsilon < > > ( ) ); - CHECK ( epsVar.get < string::Epsilon < > > ( ) == string::Epsilon < >::EPSILON ); + CHECK ( string::LinearString < > ( ) == epsVar.get < string::LinearString < > > ( ) ); + CHECK ( epsVar.get < string::LinearString < > > ( ) == string::LinearString < > ( ) ); - std::pair < ext::variant < string::Epsilon < >, int >, int > epsVarPair = std::make_pair ( epsVar, 10 ); - CHECK ( string::Epsilon < >::EPSILON == epsVarPair.first.get < string::Epsilon < > > ( ) ); - CHECK ( epsVarPair.first.get < string::Epsilon < > > ( ) == string::Epsilon < >::EPSILON ); + std::pair < ext::variant < string::LinearString < >, int >, int > epsVarPair = std::make_pair ( epsVar, 10 ); + CHECK ( string::LinearString < > ( ) == epsVarPair.first.get < string::LinearString < > > ( ) ); + CHECK ( epsVarPair.first.get < string::LinearString < > > ( ) == string::LinearString < > ( ) ); - testMap.insert ( std::make_pair ( ext::variant < string::Epsilon < >, int > { string::Epsilon < > { } + testMap.insert ( std::make_pair ( ext::variant < string::LinearString < >, int > { string::LinearString < > { } }, 10 ) ); - CHECK ( testMap.find ( ext::variant < string::Epsilon < >, int > { string::Epsilon < > { } + CHECK ( testMap.find ( ext::variant < string::LinearString < >, int > { string::LinearString < > { } } ) != testMap.end ( ) ); for ( const auto & entry : testMap ) { - CHECK ( entry.first.is < string::Epsilon < > > ( ) ); + CHECK ( entry.first.is < string::LinearString < > > ( ) ); - if ( entry.first.is < string::Epsilon < > > ( ) ) - CHECK ( string::Epsilon < >::EPSILON == entry.first.get < string::Epsilon < > > ( ) ); + if ( entry.first.is < string::LinearString < > > ( ) ) + CHECK ( string::LinearString < > ( ) == entry.first.get < string::LinearString < > > ( ) ); - CHECK ( entry.first.get < string::Epsilon < > > ( ) == string::Epsilon < >::EPSILON ); + CHECK ( entry.first.get < string::LinearString < > > ( ) == string::LinearString < > ( ) ); } } diff --git a/alib2str/src/object/string/AnyObject.cpp b/alib2str/src/object/string/AnyObject.cpp index f89e7c78d5..79c2619b88 100644 --- a/alib2str/src/object/string/AnyObject.cpp +++ b/alib2str/src/object/string/AnyObject.cpp @@ -10,14 +10,15 @@ #include <container/string/ObjectsPair.h> #include <container/string/ObjectsSet.h> #include <container/string/ObjectsVariant.h> -#include <string/string/Epsilon.h> #include <alphabet/string/RankedSymbol.h> #include <registration/StringRegistration.hpp> +#include <common/DefaultEpsilonType.h> + namespace { -static auto stringWriteGroup1 = registration::StringWriterRegisterTypeInGroup < object::Object, ext::pair < ext::set < ext::pair < object::Object, object::Object > >, ext::variant < string::Epsilon < object::Object >, object::Object > > > ( ); +static auto stringWriteGroup1 = registration::StringWriterRegisterTypeInGroup < object::Object, ext::pair < ext::set < ext::pair < object::Object, object::Object > >, ext::variant < DefaultEpsilonType, object::Object > > > ( ); static auto stringWriteGroup2 = registration::StringWriterRegisterTypeInGroup < object::Object, ext::set < ext::pair < object::Object, object::Object > > > ( ); static auto stringWriteGroup3 = registration::StringWriterRegisterTypeInGroup < object::Object, ext::pair < object::Object, unsigned > > ( ); static auto stringWriteGroup4 = registration::StringWriterRegisterTypeInGroup < object::Object, ext::pair < unsigned, unsigned > > ( ); diff --git a/alib2str/src/string/StringFromStringLexer.cpp b/alib2str/src/string/StringFromStringLexer.cpp index 2e2c3a890b..9b5a8cc9dc 100644 --- a/alib2str/src/string/StringFromStringLexer.cpp +++ b/alib2str/src/string/StringFromStringLexer.cpp @@ -56,11 +56,6 @@ L1: if(in.eof()) { token.type = TokenType::TEOF; return token; - } else if(character == 'E') { - token.type = TokenType::EPSILON; - token.value += character; - token.raw += character; - return token; } else if(character == '$') { token.type = TokenType::TERM; token.value += character; diff --git a/alib2str/src/string/StringFromStringLexer.h b/alib2str/src/string/StringFromStringLexer.h index 12e4e666da..58b8ca44cc 100644 --- a/alib2str/src/string/StringFromStringLexer.h +++ b/alib2str/src/string/StringFromStringLexer.h @@ -20,7 +20,6 @@ public: LESS, GREATER, QUOTE, - EPSILON, TERM, TEOF, ERROR diff --git a/alib2str/src/string/string/Epsilon.cpp b/alib2str/src/string/string/Epsilon.cpp deleted file mode 100644 index 69125bf4a1..0000000000 --- a/alib2str/src/string/string/Epsilon.cpp +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Epsilon.cpp - * - * Created on: Sep 27, 2017 - * Author: Jan Travnicek - */ - -#include "Epsilon.h" -#include <string/String.h> - -#include <registration/StringRegistration.hpp> - -namespace { - -static auto stringWrite = registration::StringWriterRegister < string::Epsilon < > > ( ); -static auto stringReader = registration::StringReaderRegister < string::String, string::Epsilon < > > ( ); - -} /* namespace */ diff --git a/alib2str/src/string/string/Epsilon.h b/alib2str/src/string/string/Epsilon.h deleted file mode 100644 index 9024d69c8a..0000000000 --- a/alib2str/src/string/string/Epsilon.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Epsilon.h - * - * Created on: Sep 27, 2017 - * Author: Jan Travnicek - */ - -#ifndef _STRING_EPSILON_H_ -#define _STRING_EPSILON_H_ - -#include <string/Epsilon.h> -#include <core/stringApi.hpp> - -#include <string/StringFromStringLexer.h> - -#include <string/string/common/StringFromStringParserCommon.h> -#include <string/string/common/StringToStringComposerCommon.h> - -namespace core { - -template<class SymbolType > -struct stringApi < string::Epsilon < SymbolType > > { - static string::Epsilon < SymbolType > parse ( std::istream & input ); - static bool first ( std::istream & input ); - static void compose ( std::ostream & output, const string::Epsilon < SymbolType > & string ); -}; - -template<class SymbolType > -string::Epsilon < SymbolType > stringApi < string::Epsilon < SymbolType > >::parse ( std::istream & input ) { - string::StringFromStringLexer::Token token = string::StringFromStringLexer::next ( input ); - if ( token.type == string::StringFromStringLexer::TokenType::EPSILON ) { - return string::Epsilon < SymbolType > ( ); - } else { - throw exception::CommonException ( "Unrecognised Epsilon token." ); - } -} - -template<class SymbolType > -bool stringApi < string::Epsilon < SymbolType > >::first ( std::istream & input ) { - string::StringFromStringLexer::Token token = string::StringFromStringLexer::next ( input ); - bool res = token.type == string::StringFromStringLexer::TokenType::EPSILON; - string::StringFromStringLexer::putback ( input, token ); - return res; -} - -template<class SymbolType > -void stringApi < string::Epsilon < SymbolType > >::compose ( std::ostream & output, const string::Epsilon < SymbolType > & ) { - output << "#E"; -} - -} /* namespace core */ - -#endif /* _STRING_EPSILON_H_ */ diff --git a/alib2str/test-src/string/StringTest.cpp b/alib2str/test-src/string/StringTest.cpp index 4502ff64d9..8057528d88 100644 --- a/alib2str/test-src/string/StringTest.cpp +++ b/alib2str/test-src/string/StringTest.cpp @@ -6,7 +6,6 @@ #include "sax/SaxComposeInterface.h" #include "string/string/LinearString.h" -#include "string/string/Epsilon.h" #include "factory/StringDataFactory.hpp" @@ -38,18 +37,5 @@ TEST_CASE ( "String Test", "[unit][str][string]" ) { CHECK( string == string2 ); } - { - std::string input = "#E"; - string::Epsilon < > string = factory::StringDataFactory::fromString (input); - - std::string output = factory::StringDataFactory::toString(string); - - CAPTURE ( input, output ); - CHECK( input == output ); - - string::Epsilon < > string2 = factory::StringDataFactory::fromString (output); - - CHECK ( string == string2 ); - } } } -- GitLab