27#include <ext/algorithm>
45class TerminalAlphabet;
46class NonterminalAlphabet;
63template <
class SymbolType = DefaultSymbolType >
64class ContextPreservingUnrestrictedGrammar final :
public core::Components < ContextPreservingUnrestrictedGrammar < SymbolType >, ext::set < SymbolType >, component::Set, std::tuple < TerminalAlphabet, NonterminalAlphabet >, SymbolType, component::Value, InitialSymbol > {
145 return this->
template accessComponent < InitialSymbol > ( ).get ( );
154 return std::move ( this->
template accessComponent < InitialSymbol > ( ).
get ( ) );
165 return this->
template accessComponent < InitialSymbol > ( ).set ( std::move ( symbol ) );
174 return this->
template accessComponent < NonterminalAlphabet > ( ).get ( );
183 return std::move ( this->
template accessComponent < NonterminalAlphabet > ( ).
get ( ) );
194 return this->
template accessComponent < NonterminalAlphabet > ( ).add ( std::move ( symbol ) );
203 this->
template accessComponent < NonterminalAlphabet > ( ).set ( std::move ( symbols ) );
212 return this->
template accessComponent < TerminalAlphabet > ( ).get ( );
221 return std::move ( this->
template accessComponent < TerminalAlphabet > ( ).
get ( ) );
232 return this->
template accessComponent < TerminalAlphabet > ( ).add ( std::move ( symbol ) );
241 this->
template accessComponent < TerminalAlphabet > ( ).set ( std::move ( symbols ) );
275 return out <<
"(ContextPreservingUnrestrictedGrammar"
279 <<
" rules = " << instance.
getRules ( )
284template <
class SymbolType >
288template <
class SymbolType >
289ContextPreservingUnrestrictedGrammar < SymbolType >::ContextPreservingUnrestrictedGrammar (
ext::set < SymbolType > nonterminalAlphabet,
ext::set < SymbolType > terminalAlphabet,
SymbolType initialSymbol ) :
core::Components <
ContextPreservingUnrestrictedGrammar,
ext::set < SymbolType >, component::Set, std::tuple < TerminalAlphabet, NonterminalAlphabet >,
SymbolType, component::Value, InitialSymbol > ( std::move ( terminalAlphabet), std::move ( nonterminalAlphabet ), std::move ( initialSymbol ) ) {
292template <
class SymbolType >
295 if ( !getTerminalAlphabet ( ).count ( symbol ) && !getNonterminalAlphabet ( ).count ( symbol ) )
298 if ( !getNonterminalAlphabet ( ).count ( leftHandSide ) )
302 if ( !getTerminalAlphabet ( ).count ( symbol ) && !getNonterminalAlphabet ( ).count ( symbol ) )
305 for (
const SymbolType & symbol : rightHandSide )
306 if ( !getTerminalAlphabet ( ).count ( symbol ) && !getNonterminalAlphabet ( ).count ( symbol ) )
309 return rules [
ext::make_tuple ( std::move ( lContext ), std::move ( leftHandSide ), std::move ( rContext ) ) ].insert ( std::move ( rightHandSide ) ).second;
312template <
class SymbolType >
315 if ( !getTerminalAlphabet ( ).count ( symbol ) && !getNonterminalAlphabet ( ).count ( symbol ) )
318 if ( !getNonterminalAlphabet ( ).count ( leftHandSide ) )
322 if ( !getTerminalAlphabet ( ).count ( symbol ) && !getNonterminalAlphabet ( ).count ( symbol ) )
327 if ( !getTerminalAlphabet ( ).count ( symbol ) && !getNonterminalAlphabet ( ).count ( symbol ) )
333template <
class SymbolType >
338template <
class SymbolType >
340 return std::move ( rules );
343template <
class SymbolType >
345 return rules [
ext::make_tuple ( lContext, leftHandSide, rContext ) ].erase ( rightHandSide );
357template <
class SymbolType >
370 for (
const SymbolType & lCont : std::get < 0 > ( rule.first ) )
371 if ( lCont == symbol )
374 for (
const SymbolType & rCont : std::get < 2 > ( rule.first ) )
375 if ( rCont == symbol )
379 if ( std::find ( rhs.
begin ( ), rhs.
end ( ), symbol ) != rhs.
end ( ) )
408 if (
grammar.template accessComponent < grammar::NonterminalAlphabet > ( ).get ( ).count ( symbol ) )
418template <
class SymbolType >
431 for (
const SymbolType & lCont : std::get < 0 > ( rule.first ) )
432 if ( lCont == symbol )
435 if ( std::get < 1 > ( rule.first ) == symbol )
438 for (
const SymbolType & rCont : std::get < 2 > ( rule.first ) )
439 if ( rCont == symbol )
443 if ( std::find ( rhs.
begin ( ), rhs.
end ( ), symbol ) != rhs.
end ( ) )
448 return grammar.template accessComponent < grammar::InitialSymbol > ( ).get ( ) == symbol;
472 if (
grammar.template accessComponent < grammar::TerminalAlphabet > ( ).get ( ).count ( symbol ) )
482template <
class SymbolType >
494 return grammar.template accessComponent < grammar::NonterminalAlphabet > ( ).get ( ).count ( symbol );
512template <
class SymbolType >
531 res.addRules ( std::move ( lContext ), std::move ( lhs ), std::move ( rContext ), std::move ( rhs ) );
static ext::set< DefaultSymbolType > normalizeAlphabet(ext::set< SymbolType > &&symbols)
Definition: SymbolNormalize.h:50
static ext::vector< DefaultSymbolType > normalizeSymbols(ext::vector< SymbolType > &&symbols)
Definition: SymbolNormalize.h:86
static DefaultSymbolType normalizeSymbol(SymbolType &&symbol)
Definition: SymbolNormalize.h:68
Definition: components.hpp:181
static void valid(const grammar::ContextPreservingUnrestrictedGrammar< SymbolType > &, const SymbolType &)
Definition: ContextPreservingUnrestrictedGrammar.h:503
static bool available(const grammar::ContextPreservingUnrestrictedGrammar< SymbolType > &grammar, const SymbolType &symbol)
Definition: ContextPreservingUnrestrictedGrammar.h:493
Definition: components.hpp:25
static bool used(const grammar::ContextPreservingUnrestrictedGrammar< SymbolType > &grammar, const SymbolType &symbol)
Definition: ContextPreservingUnrestrictedGrammar.h:429
static void valid(const grammar::ContextPreservingUnrestrictedGrammar< SymbolType > &grammar, const SymbolType &symbol)
Definition: ContextPreservingUnrestrictedGrammar.h:471
static bool available(const grammar::ContextPreservingUnrestrictedGrammar< SymbolType > &, const SymbolType &)
Definition: ContextPreservingUnrestrictedGrammar.h:459
static void valid(const grammar::ContextPreservingUnrestrictedGrammar< SymbolType > &grammar, const SymbolType &symbol)
Definition: ContextPreservingUnrestrictedGrammar.h:407
static bool used(const grammar::ContextPreservingUnrestrictedGrammar< SymbolType > &grammar, const SymbolType &symbol)
Definition: ContextPreservingUnrestrictedGrammar.h:368
static bool available(const grammar::ContextPreservingUnrestrictedGrammar< SymbolType > &, const SymbolType &)
Definition: ContextPreservingUnrestrictedGrammar.h:395
Definition: setComponents.hpp:26
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
Class extending the tuple class from the standard library. Original reason is to allow printing of th...
Definition: tuple.hpp:42
Class extending the vector class from the standard library. Original reason is to allow printing of t...
Definition: vector.hpp:45
auto begin() &
Inherited behavior of begin for non-const instance.
Definition: vector.hpp:125
auto end() &
Inherited behavior of end for non-const instance.
Definition: vector.hpp:155
Context preserving unrestricted grammar. Type 0 in Chomsky hierarchy. Generates recursively enumerabl...
Definition: ContextPreservingUnrestrictedGrammar.h:64
bool addNonterminalSymbol(SymbolType symbol)
Definition: ContextPreservingUnrestrictedGrammar.h:193
const ext::map< ext::tuple< ext::vector< SymbolType >, SymbolType, ext::vector< SymbolType > >, ext::set< ext::vector< SymbolType > > > & getRules() const &
Definition: ContextPreservingUnrestrictedGrammar.h:334
void addRules(ext::vector< SymbolType > lContext, SymbolType leftHandSide, ext::vector< SymbolType > rContext, ext::set< ext::vector< SymbolType > > rightHandSide)
Add new rules of a grammar.
Definition: ContextPreservingUnrestrictedGrammar.h:313
void setNonterminalAlphabet(ext::set< SymbolType > symbols)
Definition: ContextPreservingUnrestrictedGrammar.h:202
bool addRule(ext::vector< SymbolType > lContext, SymbolType leftHandSide, ext::vector< SymbolType > rContext, ext::vector< SymbolType > rightHandSide)
Add a new rule of a grammar.
Definition: ContextPreservingUnrestrictedGrammar.h:293
const ext::set< SymbolType > & getNonterminalAlphabet() const &
Definition: ContextPreservingUnrestrictedGrammar.h:173
friend ext::ostream & operator<<(ext::ostream &out, const ContextPreservingUnrestrictedGrammar &instance)
Definition: ContextPreservingUnrestrictedGrammar.h:274
ext::set< SymbolType > && getNonterminalAlphabet() &&
Definition: ContextPreservingUnrestrictedGrammar.h:182
auto operator<=>(const ContextPreservingUnrestrictedGrammar &other) const
Definition: ContextPreservingUnrestrictedGrammar.h:251
bool removeRule(const ext::vector< SymbolType > &lContext, const SymbolType &leftHandSide, const ext::vector< SymbolType > &rContext, const ext::vector< SymbolType > &rightHandSide)
Definition: ContextPreservingUnrestrictedGrammar.h:344
ContextPreservingUnrestrictedGrammar(SymbolType initialSymbol)
Creates a new instance of the grammar with a concrete initial symbol.
Definition: ContextPreservingUnrestrictedGrammar.h:285
const ext::set< SymbolType > & getTerminalAlphabet() const &
Definition: ContextPreservingUnrestrictedGrammar.h:211
bool setInitialSymbol(SymbolType symbol)
Definition: ContextPreservingUnrestrictedGrammar.h:164
void setTerminalAlphabet(ext::set< SymbolType > symbols)
Definition: ContextPreservingUnrestrictedGrammar.h:240
bool operator==(const ContextPreservingUnrestrictedGrammar &other) const
Definition: ContextPreservingUnrestrictedGrammar.h:262
const SymbolType & getInitialSymbol() const &
Definition: ContextPreservingUnrestrictedGrammar.h:144
SymbolType && getInitialSymbol() &&
Definition: ContextPreservingUnrestrictedGrammar.h:153
bool addTerminalSymbol(SymbolType symbol)
Definition: ContextPreservingUnrestrictedGrammar.h:231
ext::set< SymbolType > && getTerminalAlphabet() &&
Definition: ContextPreservingUnrestrictedGrammar.h:220
Definition: GrammarException.h:15
typename T::SymbolType SymbolType
Definition: ReachableStates.h:176
return res
Definition: MinimizeByPartitioning.h:145
Definition: normalize.hpp:10
constexpr tuple< Elements &... > tie(Elements &... args) noexcept
Helper of extended tuple of references construction. The tuple is constructed to reffer to values in ...
Definition: tuple.hpp:218
reference_mover< T > make_mover(T ¶m)
Move adaptor construction function specialized to lvalue reference parameter.
Definition: iterator.hpp:468
std::string to_string(const T &value)
To string method designated for objects that can be casted to string.
Definition: string.hpp:131
constexpr auto make_tuple(Elements &&... args)
Helper of extended tuple construction. The tuple is constructed from values pack, types are deduced.
Definition: tuple.hpp:203
auto begin(Container &&cont) -> decltype(std::forward(cont).begin())
Definition: iterator.hpp:900
Definition: ToAutomaton.h:24
void end()
Definition: measurements.cpp:19
auto & get(ext::ptr_array< Type, N > &tpl)
Specialisation of get function for pointer arrays.
Definition: ptr_array.hpp:693
static grammar::ContextPreservingUnrestrictedGrammar< > eval(grammar::ContextPreservingUnrestrictedGrammar< SymbolType > &&value)
Definition: ContextPreservingUnrestrictedGrammar.h:514
Definition: normalize.hpp:13