|
TuringSim
C++ framework to simulate abstract computing models
|
3 #include <memory/word.h>
4 #include <memory/stack.h>
5 #include <transition/PDM/pushdownMachineTransition.h>
18 typename StackSymbolType_
32 static_assert(std::is_same_v<StateType, StateType_>);
33 static_assert(std::is_same_v<ApplyHelperType, std::monostate>);
46 std::optional<LetterType> preLetter,
47 std::vector<StackSymbolType> preSymbols,
49 std::vector<StackSymbolType> postSymbols) :
52 preSymbols(preSymbols),
54 postSymbols(postSymbols)
84 return this->
matchFromCurrentLetter(state, std::get<WordType>(storage).front_opt(), std::get<StackType>(storage));
96 if(state != preState || (!letter && preLetter) || (letter && preLetter && *letter != *preLetter)) {
100 size_t preSymbolsSize = preSymbols.size();
102 std::vector<StackSymbolType> tops = stack.
tops(preSymbolsSize);
104 if(tops != preSymbols) {
111 return {std::monostate{}};
114 #pragma clang diagnostic push
115 #pragma clang diagnostic ignored "-Wunused-parameter"
129 size_t preSymbolsSize = preSymbols.size();
130 std::get<StackType>(storage).pops(preSymbolsSize);
131 std::get<StackType>(storage).pushs(postSymbols);
133 std::get<WordType>(storage).read();
137 #pragma clang diagnostic pop
164 return preSymbols.size();
169 std::optional<LetterType> preLetter;
170 std::vector<StackSymbolType> preSymbols;
172 std::vector<StackSymbolType> postSymbols;
const StateType & getPreState() const noexcept
Get the pre-state.
virtual StateType apply(const StateType &state, StorageType &storage, ApplyHelperType &&helper, bool &running) const override final
Apply a previously matching transition and return the new state.
StorageType_ StorageType
The type of storage.
virtual std::optional< ApplyHelperType > matchFromCurrentLetter(const StateType &state, const std::optional< LetterType > &letter, const StackType &stack) const
Test whether the transition matches a configuration. Returned optional is empty iff the transition do...
GeneralPushdownMachineTransition & operator=(GeneralPushdownMachineTransition &&)=default
The default move assignment operator.
const std::vector< StackSymbolType > & getPreSymbols() const noexcept
Get the pre-symbols.
size_t getPreSymbolsSize() const noexcept
Get the size of stack needed by this transition.
GeneralPushdownMachineTransition(StateType preState, std::optional< LetterType > preLetter, std::vector< StackSymbolType > preSymbols, StateType postState, std::vector< StackSymbolType > postSymbols)
Builds a GeneralPushdownMachineTransition from its components.
GeneralPushdownMachineTransition(const GeneralPushdownMachineTransition &)=default
The default copy constructor.
virtual std::optional< ApplyHelperType > match(const StateType &state, const StorageType &storage) const override final
Test whether the transition matches a configuration. Returned optional is empty iff the transition do...
Class to represent a stack memory.
GeneralPushdownMachineTransition(GeneralPushdownMachineTransition &&)=default
The default move constructor.
LetterType_ LetterType
The type of letter of the word.
Transition of pushdown machines, i.e. transition on a word and a stack.
std::vector< T > tops(size_t nb) const
Get the top elements of the stack.
ApplyHelperType_ ApplyHelperType
The type of apply helpers.
StackSymbolType_ StackSymbolType
The type of symbols in the stack.
Memory::Stack::Stack< StackSymbolType_ > StackType
The type of the stack of a machine with such transition.
GeneralPushdownMachineTransition & operator=(const GeneralPushdownMachineTransition &)=default
The default copy assignment operator.
Transition of pushdown machines, i.e. transition on a word and a stack.
StateType_ StateType
The type of states.
Exception thrown when we try to pop or top an empty stack, or pops or tops a too small stack.
virtual ~GeneralPushdownMachineTransition()=default
The default virtual destructor.
const std::optional< LetterType > & getPreLetter() const noexcept
Get the pre-letter.
Memory::Word::Word< LetterType_ > WordType
The type of words read by a machine with such transition.
Transitions for pushdown machines.