TuringSim
C++ framework to simulate abstract computing models
simplePushdownMachine.h
1 #pragma once
2 
3 #include <machine/PDM/stateAcceptingPushdownMachine.h>
4 #include <transition/PDM/simplePushdownMachineTransition.h>
5 
6 namespace TuringSim::Machine::PDM {
24  template<
25  typename StateType,
26  typename LetterType,
27  typename StackSymbolType,
28  bool deterministic,
29  AcceptingStyle acceptingStyle = AcceptingStyle::Accepting,
30  template <typename...> class TransitionContainer_ = std::vector,
31  template <typename...> class InitialStateContainer_ = std::vector,
32  typename AcceptingConstructorArgs = typename impl_details_::StateAcceptingMachineArgs<StateType, acceptingStyle>::AcceptingConstructorArgs
33  >
35 
52  template<
53  typename StateType_,
54  typename LetterType_,
55  typename StackSymbolType_,
56  bool deterministic,
57  AcceptingStyle acceptingStyle,
58  template <typename...> class TransitionContainer_,
59  template <typename...> class InitialStateContainer_,
60  typename... Args
61  >
63  StateType_,
64  LetterType_,
65  StackSymbolType_,
66  deterministic,
67  acceptingStyle,
68  TransitionContainer_,
69  InitialStateContainer_,
70  std::tuple<Args...>
71  > : public PushdownMachine<Transition::PDM::SimplePushdownMachineTransition<StateType_, LetterType_, StackSymbolType_>, deterministic, acceptingStyle, TransitionContainer_, InitialStateContainer_> {
74  public:
75  using typename PushdownMachine_::WordType;
76  using typename PushdownMachine_::StackType;
77  using typename PushdownMachine_::StateType;
78  using typename PushdownMachine_::LetterType;
79  using typename PushdownMachine_::IsAccepting;
80  using typename PushdownMachine_::StorageType;
81  using typename PushdownMachine_::IsAlternating;
82  using typename PushdownMachine_::TransitionType;
83  using typename PushdownMachine_::ApplyHelperType;
84  using typename PushdownMachine_::IsDeterministic;
85  using typename PushdownMachine_::StackSymbolType;
86  using typename PushdownMachine_::TransitionContainer;
87  using typename PushdownMachine_::InitialStateContainer;
88  using typename PushdownMachine_::OptionalHelpedTransition;
89 
90  static_assert(std::is_same_v<StateType, typename TransitionType::StateType>);
91  static_assert(std::is_same_v<StorageType, typename TransitionType::StorageType>);
92  static_assert(std::is_same_v<TransitionType, TransitionType_>);
93  static_assert(std::is_same_v<ApplyHelperType, typename TransitionType::ApplyHelperType>);
94  static_assert(std::is_same_v<ApplyHelperType, std::monostate>);
95  static_assert(std::is_same_v<IsDeterministic, std::integral_constant<bool, deterministic>>);
96  static_assert(std::is_same_v<TransitionContainer, TransitionContainer_<std::pair<const TransitionType&, ApplyHelperType>>>);
97  static_assert(std::is_same_v<InitialStateContainer, InitialStateContainer_<StateType>>);
98  static_assert(std::is_same_v<OptionalHelpedTransition, std::optional<std::pair<const TransitionType&, ApplyHelperType>>>);
99 
100  static_assert(std::is_same_v<StorageType, Transition::PDM::PushdownMachineStorage<LetterType, StackSymbolType>>,
101  "StorageType should be a word and a stack.");
102  static_assert(std::is_same_v<TransitionType_, TransitionType>,
103  "TransitionType must be SimplePushdownTransition");
104  static_assert(std::is_same_v<std::tuple<Args...>, typename impl_details_::StateAcceptingMachineArgs<StateType, acceptingStyle>::AcceptingConstructorArgs>,
105  "The only valid value for AcceptingConstructorArgs is the default parameter.");
106 
109 
113  SimplePushdownMachine(Args... acceptingArgs) :
114  PushdownMachine_(acceptingArgs...)
115  {}
116 
130  virtual ~SimplePushdownMachine() override = default;
131 
132 #pragma clang diagnostic push
133 #pragma clang diagnostic ignored "-Wunused-parameter"
134 
154  virtual bool isHaltingConfiguration(const StateType& state, const StorageType& storage) const noexcept override final {
155  return storage.isEndOfWord();
156  }
157 #pragma clang diagnostic pop
158  };
159 }
TuringSim::Machine::PDM::SimplePushdownMachine
The class to represent a pushdown machine with simple transitions.
Definition: simplePushdownMachine.h:34
TuringSim::Transition::PDM::PushdownMachineStorage
std::tuple< Memory::Word::Word< WordAlphabet >, Memory::Stack::Stack< StackAlphabet > > PushdownMachineStorage
The type of the memory of a pushdown machine from the types of letters and symbols on the stack.
Definition: pushdownMachineTransition.h:15
TuringSim::Machine::impl_details_::StateAcceptingMachineArgs
This class provide a single type AcceptingConstructorArgs that is the tuple of parameters used to dec...
Definition: stateAcceptingMachine.h:38
TuringSim::Machine::PDM::SimplePushdownMachine< StateType_, LetterType_, StackSymbolType_, deterministic, acceptingStyle, TransitionContainer_, InitialStateContainer_, std::tuple< Args... > >::SimplePushdownMachine
SimplePushdownMachine(Args... acceptingArgs)
Builds a SimplePushdownMachine given a set of accepting states.
Definition: simplePushdownMachine.h:113
TuringSim::Machine::PDM
Namespace of pushdown machines, that is whose storage is a word and a stack.
Definition: deterministicSimplePushdownMachine.h:6
TuringSim::Machine::PDM::SimplePushdownMachine< StateType_, LetterType_, StackSymbolType_, deterministic, acceptingStyle, TransitionContainer_, InitialStateContainer_, std::tuple< Args... > >::operator=
SimplePushdownMachine & operator=(SimplePushdownMachine &&)=default
The default move assignment operator.
TuringSim::Machine::PDM::SimplePushdownMachine< StateType_, LetterType_, StackSymbolType_, deterministic, acceptingStyle, TransitionContainer_, InitialStateContainer_, std::tuple< Args... > >::operator=
SimplePushdownMachine & operator=(const SimplePushdownMachine &)=default
The default copy assignment operator.
TuringSim::Machine::PDM::SimplePushdownMachine< StateType_, LetterType_, StackSymbolType_, deterministic, acceptingStyle, TransitionContainer_, InitialStateContainer_, std::tuple< Args... > >::SimplePushdownMachine
SimplePushdownMachine()=delete
The deleted default constructor.
TuringSim::Machine::PDM::PushdownMachine
The class to represent a pushdown machine.
Definition: pushdownMachine.h:32
TuringSim::Machine::PDM::SimplePushdownMachine< StateType_, LetterType_, StackSymbolType_, deterministic, acceptingStyle, TransitionContainer_, InitialStateContainer_, std::tuple< Args... > >::SimplePushdownMachine
SimplePushdownMachine(const SimplePushdownMachine &)=default
The default copy constructor.
TuringSim::Transition::PDM::SimplePushdownMachineTransition
Transition of pushdown machines, i.e. transition on a word and a stack.
Definition: simplePushdownMachineTransition.h:20
TuringSim::Machine::PDM::SimplePushdownMachine< StateType_, LetterType_, StackSymbolType_, deterministic, acceptingStyle, TransitionContainer_, InitialStateContainer_, std::tuple< Args... > >::~SimplePushdownMachine
virtual ~SimplePushdownMachine() override=default
The default virtual destructor.
TuringSim::Machine::AcceptingStyle
AcceptingStyle
Whether the machine is accepting, alternating or nothing.
Definition: acceptingMachine.h:11
TuringSim::Machine::PDM::SimplePushdownMachine< StateType_, LetterType_, StackSymbolType_, deterministic, acceptingStyle, TransitionContainer_, InitialStateContainer_, std::tuple< Args... > >::isHaltingConfiguration
virtual bool isHaltingConfiguration(const StateType &state, const StorageType &storage) const noexcept override final
Test if a given configuration is a halting one.
Definition: simplePushdownMachine.h:154
TuringSim::Machine::PDM::SimplePushdownMachine< StateType_, LetterType_, StackSymbolType_, deterministic, acceptingStyle, TransitionContainer_, InitialStateContainer_, std::tuple< Args... > >::SimplePushdownMachine
SimplePushdownMachine(SimplePushdownMachine &&)=default
The default move constructor.