|
TuringSim
C++ framework to simulate abstract computing models
|
3 #include <utils/visitor.h>
4 #include <state/mConfiguration/mConfiguration.h>
5 #include <symbol/symbolPattern.h>
57 virtual bool match(
const T& e)
const override {
return (symbols.find(e) == symbols.end()) == neg; }
82 return symbols < other.symbols;
92 template <
typename CharT =
char,
typename Traits = std::
char_traits<CharT>>
99 for (
const T &symbol: pattern.symbols) {
106 os <<
"{" << symbol <<
"}";
113 std::set<T> symbols{};
123 template <
typename KeyType,
typename ValueType,
typename SymbolType>
157 constexpr
bool matchAccordingToPredicate(
const std::map<KeyType, ValueType>& context,
const std::function<
bool(
const ValueType&)>& predicate)
const {
158 for(
const KeyType& key : keys) {
159 typename std::map<KeyType, ValueType>::const_iterator it = context.find(key);
160 if(it != context.end()) {
161 if(predicate(it->second)) {
186 if(neg < other.neg) {
189 if(neg > other.neg) {
192 return keys < other.keys;
201 if(neg != other.neg) {
204 if(keys.size() != other.keys.size()) {
207 for(
const KeyType& key : keys) {
208 typename std::map<KeyType, KeyType>::const_iterator it = rewriting.find(key);
209 if(it == rewriting.end()) {
212 if(other.keys.find(it->second) == other.keys.end()) {
226 template <
typename CharT =
char,
typename Traits = std::
char_traits<CharT>>
228 using Utils::Debug::operator<<;
238 std::set<KeyType> keys{};
246 template <
typename SymbolType>
279 return m_conf.isLeaf() && m_conf.getNode() == symbol;
310 template <
typename KeyType,
typename ValueType,
typename SymbolType>
318 constexpr
MixedSymbolPattern(
const std::set<KeyType>& symbols,
const std::set<KeyType>& keys,
bool neg) : symbols(symbols), keys(keys), neg(neg) {}
334 if(!neg && symbols.find(symbol) != symbols.end()) {
337 if(neg && symbols.find(symbol) != symbols.end()) {
340 for(
const KeyType& key : keys) {
341 typename std::map<KeyType, ValueType>::const_iterator it = context.find(key);
342 if(it != context.end()) {
343 if(predicate(it->second)) {
366 if(neg < other.neg) {
369 if(neg > other.neg) {
372 if(symbols < other.symbols) {
375 if(symbols > other.symbols) {
378 return keys < other.keys;
387 if(neg != other.neg) {
390 if(symbols != other.symbols) {
393 if(keys.size() != other.keys.size()) {
396 for(
const KeyType& key : keys) {
397 typename std::map<KeyType, KeyType>::const_iterator it = rewriting.find(key);
398 if(it == rewriting.end()) {
401 if(other.keys.find(it->second) == other.keys.end()) {
415 template <
typename CharT =
char,
typename Traits = std::
char_traits<CharT>>
417 using Utils::Debug::operator<<;
427 std::set<SymbolType> symbols{};
428 std::set<KeyType> keys{};
436 template <
typename SymbolType>
456 [&symbol](
const std::shared_ptr<const State::MConfiguration::MConfiguration<SymbolType>>& m_conf) ->
bool {
457 return m_conf->isLeaf() && m_conf->getNode() == symbol;
498 template<
typename T,
typename CharT =
char,
typename Traits = std::
char_traits<CharT>>
constexpr TuringStyleDynamicSymbolPattern(const std::set< SymbolType > &keys)
Make a dynamic pattern that accepts a set of keys.
constexpr bool operator<(const MixedSymbolPattern< KeyType, ValueType, SymbolType > &other) const
Less than operator, total order.
constexpr DynamicSymbolPattern(const std::set< KeyType > &keys)
Make a dynamic pattern that accepts a set of keys.
Visitor(Ts...) -> Visitor< Ts... >
The deduction guide for Visitor, useless since C++20.
SymbolType SymbolType
The type of symbols.
constexpr bool operator<(const TuringStyleMixedSymbolPattern< SymbolType > &other) const
Less than.
The base class for m-configurations.
A symbol pattern as used by Turing. Such a pattern accept or reject a finite explicit set of symbols.
virtual bool match(const SymbolType &symbol, const std::map< SymbolType, State::MConfiguration::MConfiguration< SymbolType >> &context) const override
Check is a symbol is accepted.
constexpr bool operator!=(const TuringStyleMixedSymbolPattern< SymbolType > &other) const
Non-equality operator.
virtual bool match(const SymbolType &symbol, const std::map< SymbolType, std::shared_ptr< const State::MConfiguration::MConfiguration< SymbolType >>> &context) const noexcept override
Check is a symbol is accepted.
constexpr bool operator<(const DynamicSymbolPattern< KeyType, ValueType, SymbolType > &other) const
Less than operator.
The namespace for symbol patterns.
constexpr bool matchAccordingToPredicate(const SymbolType &symbol, const std::map< KeyType, ValueType > &context, const std::function< bool(const ValueType &)> &predicate) const
Test if a key match a given predicate in a given context.
friend std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const TuringStyleConstantSymbolPattern &pattern)
Debug printer.
constexpr bool matchAccordingToPredicate(const std::map< KeyType, ValueType > &context, const std::function< bool(const ValueType &)> &predicate) const
Test if a key match a given predicate in a given context.
constexpr bool operator!=(const MixedSymbolPattern< KeyType, ValueType, SymbolType > &other) const
Non-equality operator.
constexpr DynamicSymbolPattern(const std::set< KeyType > &keys, bool neg)
Make a dynamic pattern that accepts or rejects a set of keys.
friend std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const MixedSymbolPattern< KeyType, ValueType, SymbolType > &pattern)
Debug printer for MixedSymbolPattern.
constexpr DynamicSymbolPattern(bool neg)
Produce a trivial pattern.
A dynamic symbol pattern where accepted/rejected letters are identified by keys, and interpreted in a...
constexpr bool operator!=(const DynamicSymbolPattern< KeyType, ValueType, SymbolType > &other) const
Non-equality operator.
constexpr bool operator==(const MixedSymbolPattern< KeyType, ValueType, SymbolType > &other) const
Equality operator.
constexpr DynamicSymbolPattern(const KeyType &key)
Make a dynamic pattern that accepts a single key.
constexpr bool isAlphaEquivalent(const MixedSymbolPattern< KeyType, ValueType, SymbolType > &other, const std::map< KeyType, KeyType > &rewriting) const
Test if, given a renaming of keys, *this is alpha-equivalent to another DynamicSymbolPattern.
A MixedSymbolPattern with a predicate adapted to m-configuration.
constexpr TuringStyleConstantSymbolPattern(const T &e)
Construct a pattern which accept only one symbol.
constexpr TuringStyleDynamicSymbolPattern(bool neg)
Produce a trivial pattern.
constexpr bool isAlphaEquivalent(const DynamicSymbolPattern< KeyType, ValueType, SymbolType > &other, const std::map< KeyType, KeyType > &rewriting) const
Test if, given a renaming of keys, *this is alpha-equivalent to another DynamicSymbolPattern.
constexpr TuringStyleConstantSymbolPattern(bool neg)
Constructs a trivial pattern: a pattern that accepts everything or nothing.
Base class to store any symbol pattern on one letter.
std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const TuringStyleSymbolPattern< T > &pattern)
a printer for TuringStyleConstantSymbolPattern
friend std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const DynamicSymbolPattern< KeyType, ValueType, SymbolType > &pattern)
Debug printer for DynamicSymbolPattern.
constexpr bool operator!=(const TuringStyleDynamicSymbolPattern< SymbolType > &other) const
Non-equality operator.
constexpr TuringStyleDynamicSymbolPattern(const std::set< SymbolType > &keys, bool neg)
Make a dynamic pattern that accepts or rejects a set of keys.
constexpr bool operator==(const TuringStyleMixedSymbolPattern< SymbolType > &other) const
Equality operator.
virtual bool match(const T &e) const override
Test if a letter matches the pattern.
constexpr bool operator<(const TuringStyleConstantSymbolPattern< T > &other) const
Less than operator. Total order.
constexpr bool operator<(const TuringStyleDynamicSymbolPattern< SymbolType > &other) const
Less than operator. Total order.
constexpr bool operator==(const TuringStyleDynamicSymbolPattern< SymbolType > &other) const
Equality operator.
A DynamicSymbolPattern with a predicate adapted to m-configuration.
constexpr bool operator==(const TuringStyleConstantSymbolPattern< T > &other) const
Equality operator.
constexpr bool operator==(const DynamicSymbolPattern< KeyType, ValueType, SymbolType > &other) const
Equality operator.
constexpr TuringStyleMixedSymbolPattern(const std::set< SymbolType > &symbols, const std::set< SymbolType > &keys, bool neg)
Build a TuringStyleMixedSymbolPattern from components.
constexpr MixedSymbolPattern(const std::set< KeyType > &symbols, const std::set< KeyType > &keys, bool neg)
Builds a new MixedSymbolPattern.
constexpr TuringStyleConstantSymbolPattern(const std::set< T > &v, bool b)
Construct a pattern which accept or reject a sequence of symbols.
std::variant< TuringStyleConstantSymbolPattern< T >, TuringStyleDynamicSymbolPattern< T > > TuringStyleSymbolPattern
a TuringStyleConstantSymbolPattern or a TuringStyleDynamicSymbolPattern.
std::function< std::basic_ostream< CharT, Traits > &(std::basic_ostream< CharT, Traits > &)> debug(const T &s)
Generic debug printing function.
A dynamic symbol pattern where some accepted/rejected symbols are explicit and constant,...
constexpr bool operator!=(const TuringStyleConstantSymbolPattern< T > &other) const
Non-equality operator.
constexpr TuringStyleConstantSymbolPattern(const std::set< T > &v)
Construct a pattern which accept a sequence of symbols.
constexpr TuringStyleDynamicSymbolPattern(const SymbolType &key)
Make a dynamic pattern that accepts a single key.