diff --git a/alib2data/src/automaton/FSM/CompactNFA.h b/alib2data/src/automaton/FSM/CompactNFA.h index d71a4149cd9b3a44d1b91e374c80cab5ffd67dd9..93b76f523a71a23e5c4b2a63776d22bf307f0e23 100644 --- a/alib2data/src/automaton/FSM/CompactNFA.h +++ b/alib2data/src/automaton/FSM/CompactNFA.h @@ -324,7 +324,7 @@ public: /** * \brief Add a transition to the automaton. * - * \details The transition is in a form A times a -> B, where A, B \in Q and a \in T* + * \details The transition is in a form A \times a -> B, where A, B \in Q and a \in T* * * \param current the source state (A) * \param input the list of input symbols (a) @@ -339,7 +339,7 @@ public: /** * \brief Add a transitions to the automaton. * - * \details The transition is in a form A times a -> P(Q), where A \in Q, a \in T*, P(Q) is a powerset of states. + * \details The transition is in a form A \times a -> P(Q), where A \in Q, a \in T*, P(Q) is a powerset of states. * * \param current the source state (A) * \param input the list of input symbols (a) @@ -352,7 +352,7 @@ public: /** * \brief Removes a transition from the automaton. * - * \details The transition is in a form A times a -> B, where A, B \in Q and a \in T* + * \details The transition is in a form A \times a -> B, where A, B \in Q and a \in T* * * \param current the source state (A) * \param input the list of input symbols (a) diff --git a/alib2data/src/automaton/FSM/DFA.h b/alib2data/src/automaton/FSM/DFA.h index 5a7dc73779d9aee2cbbec729c06e00e3ef834c5b..48fb24540c1a050fa1ecaceb4611c8a0423fe8dd 100644 --- a/alib2data/src/automaton/FSM/DFA.h +++ b/alib2data/src/automaton/FSM/DFA.h @@ -293,7 +293,7 @@ public: /** * \brief Add a transition to the automaton. * - * \details The transition is in a form A times a -> B, where A, B \in Q and a \in T + * \details The transition is in a form A \times a -> B, where A, B \in Q and a \in T * * \param current the source state (A) * \param input the input symbol (a) @@ -308,7 +308,7 @@ public: /** * \brief Removes a transition from the automaton. * - * \details The transition is in a form A times a -> B, where A, B \in Q and a \in T + * \details The transition is in a form A \times a -> B, where A, B \in Q and a \in T * * \param current the source state (A) * \param input the input symbol (a) diff --git a/alib2data/src/automaton/FSM/EpsilonNFA.h b/alib2data/src/automaton/FSM/EpsilonNFA.h index 3dfa7f708536b5d5bc4ab3e3e2c504c34685489f..415542dea47b0ebbd9dbebfc29362e2ca53325a9 100644 --- a/alib2data/src/automaton/FSM/EpsilonNFA.h +++ b/alib2data/src/automaton/FSM/EpsilonNFA.h @@ -315,7 +315,7 @@ public: /** * \brief Add a transition to the automaton. * - * \details The transition is in a form A times a -> B, where A, B \in Q and a \in T \cup \{\epsilon\} + * \details The transition is in a form A \times a -> B, where A, B \in Q and a \in T \cup \{\epsilon\} * * \param current the source state (A) * \param input the input symbol or epsilon (a) @@ -330,7 +330,7 @@ public: /** * \brief Add a transition to the automaton. * - * \details The transition is in a form A times a -> B, where A, B \in Q and a \in T + * \details The transition is in a form A \times a -> B, where A, B \in Q and a \in T * * \param current the source state (A) * \param input the input symbol (a) @@ -345,7 +345,7 @@ public: /** * \brief Add a transition to the automaton. * - * \details The transition is in a form A times \epsilon -> B, where A, B \in Q + * \details The transition is in a form A \times \epsilon -> B, where A, B \in Q * * \param current the source state (A) * \param next the target state (B) @@ -359,7 +359,7 @@ public: /** * \brief Add a transitions to the automaton. * - * \details The transition is in a form A times a -> P(Q), where A \in Q, a \in T \cup \{\epsilon\}, P(Q) is a powerset of states. + * \details The transition is in a form A \times a -> P(Q), where A \in Q, a \in T \cup \{\epsilon\}, P(Q) is a powerset of states. * * \param current the source state (A) * \param input the input symbol or epsilon (a) @@ -372,7 +372,7 @@ public: /** * \brief Add a transitions to the automaton. * - * \details The transition is in a form A times a -> P(Q), where A \in Q, a \in T, P(Q) is a powerset of states. + * \details The transition is in a form A \times a -> P(Q), where A \in Q, a \in T, P(Q) is a powerset of states. * * \param current the source state (A) * \param input the input symbol (a) @@ -385,7 +385,7 @@ public: /** * \brief Add a transitions to the automaton. * - * \details The transition is in a form A times \epsilon -> P(Q), where A \in Q, P(Q) is a powerset of states. + * \details The transition is in a form A \times \epsilon -> P(Q), where A \in Q, P(Q) is a powerset of states. * * \param current the source state (A) * \param next the target states (P(Q)) @@ -397,7 +397,7 @@ public: /** * \brief Removes a transition from the automaton. * - * \details The transition is in a form A times a -> B, where A, B \in Q and a \in T + * \details The transition is in a form A \times a -> B, where A, B \in Q and a \in T * * \param current the source state (A) * \param input the input symbol (a) @@ -410,7 +410,7 @@ public: /** * \brief Removes a transition from the automaton. * - * \details The transition is in a form A times \epsilon -> B, where A, B \in Q + * \details The transition is in a form A \times \epsilon -> B, where A, B \in Q * * \param current the source state (A) * \param next the target state (B) diff --git a/alib2data/src/automaton/FSM/ExtendedNFA.h b/alib2data/src/automaton/FSM/ExtendedNFA.h index faee7aff088b8246f26bd1ca5d583987e093e58a..22ec221e50518ed988ac9c994c89fc6a3df0afe6 100644 --- a/alib2data/src/automaton/FSM/ExtendedNFA.h +++ b/alib2data/src/automaton/FSM/ExtendedNFA.h @@ -334,7 +334,7 @@ public: /** * \brief Add a transition to the automaton. * - * \details The transition is in a form A times a -> B, where A, B \in Q and a \in RegExpsOver(T) + * \details The transition is in a form A \times a -> B, where A, B \in Q and a \in RegExpsOver(T) * * \param current the source state (A) * \param input the regexp (a) @@ -349,7 +349,7 @@ public: /** * \brief Add a transitions to the automaton. * - * \details The transition is in a form A times a -> P(Q), where A \in Q, a \in RegExpsOver(T), P(Q) is a powerset of states. + * \details The transition is in a form A \times a -> P(Q), where A \in Q, a \in RegExpsOver(T), P(Q) is a powerset of states. * * \param current the source state (A) * \param input the regexp (a) @@ -362,7 +362,7 @@ public: /** * \brief Removes a transition from the automaton. * - * \details The transition is in a form A times a -> B, where A, B \in Q and a \in RegExpsOver(T) + * \details The transition is in a form A \times a -> B, where A, B \in Q and a \in RegExpsOver(T) * * \param current the source state (A) * \param input the regexp (a) diff --git a/alib2data/src/automaton/FSM/MultiInitialStateNFA.h b/alib2data/src/automaton/FSM/MultiInitialStateNFA.h index 3719306e883aea47c303fa9a06a03ce341549e70..430afa95f96f8b5da2596d783109b7cf9b798fac 100644 --- a/alib2data/src/automaton/FSM/MultiInitialStateNFA.h +++ b/alib2data/src/automaton/FSM/MultiInitialStateNFA.h @@ -323,7 +323,7 @@ public: /** * \brief Add a transition to the automaton. * - * \details The transition is in a form A times a -> B, where A, B \in Q and a \in T + * \details The transition is in a form A \times a -> B, where A, B \in Q and a \in T * * \param current the source state (A) * \param input the input symbol (a) @@ -338,7 +338,7 @@ public: /** * \brief Add a transitions to the automaton. * - * \details The transition is in a form A times a -> P(Q), where A \in Q, a \in T, P(Q) is a powerset of states. + * \details The transition is in a form A \times a -> P(Q), where A \in Q, a \in T, P(Q) is a powerset of states. * * \param current the source state (A) * \param input the input symbol (a) @@ -351,7 +351,7 @@ public: /** * \brief Removes a transition from the automaton. * - * \details The transition is in a form A times a -> B, where A, B \in Q and a \in T + * \details The transition is in a form A \times a -> B, where A, B \in Q and a \in T * * \param current the source state (A) * \param input the input symbol (a) diff --git a/alib2data/src/automaton/FSM/NFA.h b/alib2data/src/automaton/FSM/NFA.h index 1a2ac1ac415ce343d935edb36f1563662add2d3a..5a7e18fe728b29a54f58d451e04ffae72ff16764 100644 --- a/alib2data/src/automaton/FSM/NFA.h +++ b/alib2data/src/automaton/FSM/NFA.h @@ -294,7 +294,7 @@ public: /** * \brief Add a transition to the automaton. * - * \details The transition is in a form A times a -> B, where A, B \in Q and a \in T + * \details The transition is in a form A \times a -> B, where A, B \in Q and a \in T * * \param current the source state (A) * \param input the input symbol (a) @@ -309,7 +309,7 @@ public: /** * \brief Add a transitions to the automaton. * - * \details The transition is in a form A times a -> P(Q), where A \in Q, a \in T, P(Q) is a powerset of states. + * \details The transition is in a form A \times a -> P(Q), where A \in Q, a \in T, P(Q) is a powerset of states. * * \param current the source state (A) * \param input the input symbol (a) @@ -322,7 +322,7 @@ public: /** * \brief Removes a transition from the automaton. * - * \details The transition is in a form A times a -> B, where A, B \in Q and a \in T + * \details The transition is in a form A \times a -> B, where A, B \in Q and a \in T * * \param current the source state (A) * \param input the input symbol (a) diff --git a/alib2data/src/automaton/PDA/DPDA.h b/alib2data/src/automaton/PDA/DPDA.h index f71340af57b2b5a03e0624a43f759c98b08b2c47..6d6d340f869a6d48e377c151f7d07f8467d31eaa 100644 --- a/alib2data/src/automaton/PDA/DPDA.h +++ b/alib2data/src/automaton/PDA/DPDA.h @@ -66,7 +66,7 @@ class InitialState; * G (PushdownStoreAlphabet) = finite set of pushdown store symbol - having this empty makes the automaton equivalent to DFA * I (InitialState) = initial state, * Z (InitialPushdownStoreSymbol) = initial pushdown store symbol - * \delta = transition function of the form A \times a \times \alpha -> B \times \beta, where A, B \in Q, a \in T \cup { \eps }, and \alpha, beta \in G*, + * \delta = transition function of the form A \times a \times \alpha -> B \times \beta, where A, B \in Q, a \in T \cup { \eps }, and \alpha, \beta \in G*, * F (FinalStates) = set of final states * * The transition functions must meet following criteria. Othervise adding conflicting transition will cause exception. @@ -74,7 +74,7 @@ class InitialState; * if $\delta (q, a, \alpha) \neq \emptyset$, $\delta (q, a, \beta) \neq \emptyset$ and $\alpha \neq \beta$, then $\alpha$ is not suffix of $\beta$ and $\beta$ is not suffix of $\alpha$ (formally $\gamma \alpha \neq \beta and \alpha \neq \gamma \beta$). * if $\delta(q, a, \alpha) \neq \emptyset$, $\delta (q, \varepsilon, \beta) \neq \emptyset$, then $\alpha$ is not suffix of $\beta$ and $\beta$ is not suffix of $\alpha$ (fornally $\gamma \alpha \neq \beta and \alpha \neq \gamma \beta$). * - * \tparam SymbolType used for the terminal alphabet + * \tparam InputSymbolType used for the terminal alphabet * \tparam EpsilonSymbolType used for the epsilon in the automaton * \tparam PushdownSymbolType used for the pushdown store alphabet * \tparam StateType used to the states, and the initial state of the automaton. @@ -83,7 +83,7 @@ template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolTy class DPDA final : public AutomatonBase, public core::Components < DPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, ext::set < InputSymbolType >, component::Set, InputAlphabet, ext::set < PushdownStoreSymbolType >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolType, component::Value, InitialSymbol, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > { protected: /** - * Transition function as mapping from a state times an input symbol or epsilon times string of pushdown store symbols on the left hand side to a state time string of pushdown store symbols. + * Transition function as mapping from a state times an input symbol or epsilon times string of pushdown store symbols on the left hand side to a state times string of pushdown store symbols. */ ext::map < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::pair < StateType, ext::vector < PushdownStoreSymbolType > > > transitions; @@ -393,7 +393,7 @@ public: /** * \brief Adds a transition to the automaton. * - * \details The transition is in a form A times a times \alpha -> B times \beta, where A, B \in Q, a \in T \cup { \eps }, and \alpha, \beta \in G* + * \details The transition is in a form A \times a \times \alpha -> B \times \beta, where A, B \in Q, a \in T \cup { \eps }, and \alpha, \beta \in G* * * \param from the source state (A) * \param input the input symbol or epsilon (a) @@ -410,7 +410,7 @@ public: /** * \brief Adds a transition to the automaton. * - * \details The transition is in a form A times a times \alpha -> B times \beta, where A, B \in Q, a \in T, and \alpha, \beta \in G* + * \details The transition is in a form A \times a \times \alpha -> B \times \beta, where A, B \in Q, a \in T, and \alpha, \beta \in G* * * \param from the source state (A) * \param input the input symbol (a) @@ -427,7 +427,7 @@ public: /** * \brief Adds a transition to the automaton. * - * \details The transition is in a form A times \eps times \alpha -> B times \beta, where A, B \in Q and \alpha, \beta \in G* + * \details The transition is in a form A \times \eps \times \alpha -> B \times \beta, where A, B \in Q, and \alpha, \beta \in G* * * \param from the source state (A) * \param pop symbols to be poped from pushdown store on the transition use (\alpha) @@ -443,7 +443,7 @@ public: /** * \brief Removes a transition from the automaton. * - * \details The transition is in a form A times a times \alpha -> B times \beta, where A, B \in Q, a \in T \cup { \eps }, and \alpha, \beta \in G* + * \details The transition is in a form A \times a \times \alpha -> B \times \beta, where A, B \in Q, a \in T \cup { \eps }, and \alpha, \beta \in G* * * \param from the source state (A) * \param input the input symbol or epsilon (a) @@ -460,7 +460,7 @@ public: /** * \brief Removes a transition from the automaton. * - * \details The transition is in a form A times a times \alpha -> B times \beta, where A, B \in Q, a \in T, and \alpha, \beta \in G* + * \details The transition is in a form A \times a \times \alpha -> B \times \beta, where A, B \in Q, a \in T, and \alpha, \beta \in G* * * \param from the source state (A) * \param input the input symbol (a) @@ -477,7 +477,7 @@ public: /** * \brief Removes a transition from the automaton. * - * \details The transition is in a form A times \eps times \alpha -> B times \beta, where A, B \in Q and \alpha, \beta \in G* + * \details The transition is in a form A \times \eps \times \alpha -> B \times \beta, where A, B \in Q and \alpha, \beta \in G* * * \param from the source state (A) * \param pop symbols poped from pushdown store on the transition use (\alpha) @@ -949,7 +949,7 @@ public: /** * Helper class specifying constraints for the automaton's internal pushdown store alphabet component. * - * \tparam SymbolType used for the terminal alphabet of the automaton. + * \tparam InputSymbolType used for the terminal alphabet of the automaton. * \tparam EpsilonSymbolType used for the epsilon in the automaton * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. * \tparam StateType used for the terminal alphabet of the automaton. @@ -980,7 +980,7 @@ public: } /** - * Returns true as all symbols are possibly available to be elements of the input alphabet. + * Returns true as all symbols are possibly available to be elements of the pushdown store alphabet. * * \param automaton the tested automaton * \param state the tested state @@ -992,7 +992,7 @@ public: } /** - * All symbols are valid as input symbols. + * All symbols are valid as pushdown store symbols. * * \param automaton the tested automaton * \param state the tested state @@ -1004,7 +1004,7 @@ public: /** * Helper class specifying constraints for the automaton's internal pushdown store initial element. * - * \tparam SymbolType used for the terminal alphabet of the automaton. + * \tparam InputSymbolType used for the terminal alphabet of the automaton. * \tparam EpsilonSymbolType used for the epsilon in the automaton * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. * \tparam StateType used for the terminal alphabet of the automaton. @@ -1037,7 +1037,7 @@ public: /** * Helper class specifying constraints for the automaton's internal states component. * - * \tparam SymbolType used for the terminal alphabet of the automaton. + * \tparam InputSymbolType used for the terminal alphabet of the automaton. * \tparam EpsilonSymbolType used for the epsilon in the automaton * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. * \tparam StateType used for the terminal alphabet of the automaton. @@ -1092,7 +1092,7 @@ public: /** * Helper class specifying constraints for the automaton's internal final states component. * - * \tparam SymbolType used for the terminal alphabet of the automaton. + * \tparam InputSymbolType used for the terminal alphabet of the automaton. * \tparam EpsilonSymbolType used for the epsilon in the automaton * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. * \tparam StateType used for the terminal alphabet of the automaton. @@ -1137,7 +1137,7 @@ public: /** * Helper class specifying constraints for the automaton's internal initial state element. * - * \tparam SymbolType used for the terminal alphabet of the automaton. + * \tparam InputSymbolType used for the terminal alphabet of the automaton. * \tparam EpsilonSymbolType used for the epsilon in the automaton * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. * \tparam StateType used for the terminal alphabet of the automaton. diff --git a/alib2data/src/automaton/PDA/InputDrivenDPDA.h b/alib2data/src/automaton/PDA/InputDrivenDPDA.h index 0b9040bd77fef2fb486e0914842f700fe14921e0..7d35d56785e5aad917316b42a5e65dc39ea88418 100644 --- a/alib2data/src/automaton/PDA/InputDrivenDPDA.h +++ b/alib2data/src/automaton/PDA/InputDrivenDPDA.h @@ -73,7 +73,7 @@ class InitialState; * Note that target state of a transition is required. * This class is used to store minimal, total, ... variants of deterministic finite automata. * - * \tparam SymbolType used for the terminal alphabet + * \tparam InputSymbolType used for the terminal alphabet * \tparam PushdownSymbolType used for the pushdown store alphabet * \tparam StateType used to the states, and the initial state of the automaton. */ @@ -447,7 +447,7 @@ public: /** * \brief Adds a transition to the automaton. * - * \details The transition is in a form A times a -> B, where A, B \in Q and a \in T + * \details The transition is in a form A \times a -> B, where A, B \in Q and a \in T * * \param current the source state (A) * \param input the input symbol (a) @@ -462,7 +462,7 @@ public: /** * \brief Removes a transition from the automaton. * - * \details The transition is in a form A times a -> B, where A, B \in Q and a \in T + * \details The transition is in a form A \times a -> B, where A, B \in Q and a \in T * * \param current the source state (A) * \param input the input symbol (a) @@ -906,7 +906,7 @@ public: /** * Helper class specifying constraints for the automaton's internal pushdown store alphabet component. * - * \tparam SymbolType used for the terminal alphabet of the automaton. + * \tparam InputSymbolType used for the terminal alphabet of the automaton. * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. * \tparam StateType used for the terminal alphabet of the automaton. */ @@ -936,7 +936,7 @@ public: } /** - * Returns true as all symbols are possibly available to be elements of the input alphabet. + * Returns true as all symbols are possibly available to be elements of the pushdown store alphabet. * * \param automaton the tested automaton * \param state the tested state @@ -948,7 +948,7 @@ public: } /** - * All symbols are valid as input symbols. + * All symbols are valid as pushdown store symbols. * * \param automaton the tested automaton * \param state the tested state @@ -960,7 +960,7 @@ public: /** * Helper class specifying constraints for the automaton's internal pushdown store initial element. * - * \tparam SymbolType used for the terminal alphabet of the automaton. + * \tparam InputSymbolType used for the terminal alphabet of the automaton. * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. * \tparam StateType used for the terminal alphabet of the automaton. */ @@ -992,7 +992,7 @@ public: /** * Helper class specifying constraints for the automaton's internal states component. * - * \tparam SymbolType used for the terminal alphabet of the automaton. + * \tparam InputSymbolType used for the terminal alphabet of the automaton. * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. * \tparam StateType used for the terminal alphabet of the automaton. */ @@ -1046,7 +1046,7 @@ public: /** * Helper class specifying constraints for the automaton's internal final states component. * - * \tparam SymbolType used for the terminal alphabet of the automaton. + * \tparam InputSymbolType used for the terminal alphabet of the automaton. * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. * \tparam StateType used for the terminal alphabet of the automaton. */ @@ -1090,7 +1090,7 @@ public: /** * Helper class specifying constraints for the automaton's internal initial state element. * - * \tparam SymbolType used for the terminal alphabet of the automaton. + * \tparam InputSymbolType used for the terminal alphabet of the automaton. * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. * \tparam StateType used for the terminal alphabet of the automaton. */ diff --git a/alib2data/src/automaton/PDA/InputDrivenNPDA.h b/alib2data/src/automaton/PDA/InputDrivenNPDA.h index 3bd6665066f82f8f67534cdc87089c1ed0572be7..266fb6f54d78c5ded9824a19812703a0187b5cac 100644 --- a/alib2data/src/automaton/PDA/InputDrivenNPDA.h +++ b/alib2data/src/automaton/PDA/InputDrivenNPDA.h @@ -1,5 +1,21 @@ /* - * INPUT_DRIVEN_NPDA.h + * InputDrivenNPDA.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: Mar 25, 2013 * Author: Jan Travnicek @@ -57,7 +73,7 @@ class InitialState; * Note that target state of a transition is required. * This class is used to store minimal, total, ... variants of deterministic finite automata. * - * \tparam SymbolType used for the terminal alphabet + * \tparam InputSymbolType used for the terminal alphabet * \tparam PushdownSymbolType used for the pushdown store alphabet * \tparam StateType used to the states, and the initial state of the automaton. */ @@ -431,7 +447,7 @@ public: /** * \brief Adds a transition to the automaton. * - * \details The transition is in a form A times a -> B, where A, B \in Q and a \in T + * \details The transition is in a form A \times a -> B, where A, B \in Q and a \in T * * \param current the source state (A) * \param input the input symbol (a) @@ -446,7 +462,7 @@ public: /** * \brief Adds transitions to the automaton. * - * \details The transition is in a form A times a -> B | C | ... , where A, B, C, ... \in Q and a \in T + * \details The transition is in a form A \times a -> B | C | ... , where A, B, C, ... \in Q and a \in T * * \param current the source state (A) * \param input the input symbol (a) @@ -931,7 +947,7 @@ public: /** * Helper class specifying constraints for the automaton's internal pushdown store alphabet component. * - * \tparam SymbolType used for the terminal alphabet of the automaton. + * \tparam InputSymbolType used for the terminal alphabet of the automaton. * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. * \tparam StateType used for the terminal alphabet of the automaton. */ @@ -961,7 +977,7 @@ public: } /** - * Returns true as all symbols are possibly available to be elements of the input alphabet. + * Returns true as all symbols are possibly available to be elements of the pushdown store alphabet. * * \param automaton the tested automaton * \param state the tested state @@ -973,7 +989,7 @@ public: } /** - * All symbols are valid as input symbols. + * All symbols are valid as pushdown store symbols. * * \param automaton the tested automaton * \param state the tested state @@ -985,7 +1001,7 @@ public: /** * Helper class specifying constraints for the automaton's internal pushdown store initial element. * - * \tparam SymbolType used for the terminal alphabet of the automaton. + * \tparam InputSymbolType used for the terminal alphabet of the automaton. * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. * \tparam StateType used for the terminal alphabet of the automaton. */ @@ -1017,7 +1033,7 @@ public: /** * Helper class specifying constraints for the automaton's internal states component. * - * \tparam SymbolType used for the terminal alphabet of the automaton. + * \tparam InputSymbolType used for the terminal alphabet of the automaton. * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. * \tparam StateType used for the terminal alphabet of the automaton. */ @@ -1071,7 +1087,7 @@ public: /** * Helper class specifying constraints for the automaton's internal final states component. * - * \tparam SymbolType used for the terminal alphabet of the automaton. + * \tparam InputSymbolType used for the terminal alphabet of the automaton. * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. * \tparam StateType used for the terminal alphabet of the automaton. */ @@ -1115,7 +1131,7 @@ public: /** * Helper class specifying constraints for the automaton's internal initial state element. * - * \tparam SymbolType used for the terminal alphabet of the automaton. + * \tparam InputSymbolType used for the terminal alphabet of the automaton. * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. * \tparam StateType used for the terminal alphabet of the automaton. */ diff --git a/alib2data/src/automaton/PDA/NPDA.h b/alib2data/src/automaton/PDA/NPDA.h index 9ef1a1f48fed22cf8d4c75430e7fd73182f09219..f851f67f4150b4753a4b232d740f33b33c62bd8e 100644 --- a/alib2data/src/automaton/PDA/NPDA.h +++ b/alib2data/src/automaton/PDA/NPDA.h @@ -65,19 +65,18 @@ class InitialState; * G (PushdownStoreAlphabet) = finite set of pushdown store symbol - having this empty makes the automaton equivalent to DFA * I (InitialState) = initial state, * Z (InitialPushdownStoreSymbol) = initial pushdown store symbol - * \delta = transition function of the form A \times a \times \alpha -> B \times \beta, where A, B \in Q, a \in T \cup { \eps }, and \alpha, beta \in G*, + * \delta = transition function of the form A \times a \times \alpha -> B \times \beta, where A, B \in Q, a \in T \cup { \eps }, and \alpha, \beta \in G*, * F (FinalStates) = set of final states * - * \tparam SymbolType used for the terminal alphabet + * \tparam InputSymbolType used for the terminal alphabet * \tparam EpsilonSymbolType used for the epsilon in the automaton * \tparam PushdownSymbolType used for the pushdown store alphabet * \tparam StateType used to the states, and the initial state of the automaton. */ template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > class NPDA final : public AutomatonBase, public core::Components < NPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, ext::set < InputSymbolType >, component::Set, InputAlphabet, ext::set < PushdownStoreSymbolType >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolType, component::Value, InitialSymbol, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > { -protected: /** - * Transition function as mapping from a state times an input symbol or epsilon times string of pushdown store symbols on the left hand side to a state time string of pushdown store symbols. + * Transition function as mapping from a state times an input symbol or epsilon times string of pushdown store symbols on the left hand side to a state times string of pushdown store symbols. */ ext::map < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::set < ext::pair < StateType, ext::vector < PushdownStoreSymbolType > > > > transitions; @@ -387,7 +386,7 @@ public: /** * \brief Adds a transition to the automaton. * - * \details The transition is in a form A times a times \alpha -> B times \beta, where A, B \in Q, a \in T \cup { \eps }, and \alpha, \beta \in G* + * \details The transition is in a form A \times a \times \alpha -> B \times \beta, where A, B \in Q, a \in T \cup { \eps }, and \alpha, \beta \in G* * * \param from the source state (A) * \param input the input symbol or epsilon (a) @@ -404,7 +403,7 @@ public: /** * \brief Adds a transition to the automaton. * - * \details The transition is in a form A times a times \alpha -> B times \beta, where A, B \in Q, a \in T, and \alpha, \beta \in G* + * \details The transition is in a form A \times a \times \alpha -> B \times \beta, where A, B \in Q, a \in T, and \alpha, \beta \in G* * * \param from the source state (A) * \param input the input symbol (a) @@ -421,7 +420,7 @@ public: /** * \brief Adds a transition to the automaton. * - * \details The transition is in a form A times \eps times \alpha -> B times \beta, where A, B \in Q and \alpha, \beta \in G* + * \details The transition is in a form A \times \eps \times \alpha -> B \times \beta, where A, B \in Q and \alpha, \beta \in G* * * \param from the source state (A) * \param pop symbols to be poped from pushdown store on the transition use (\alpha) @@ -437,7 +436,7 @@ public: /** * \brief Adds transitions to the automaton. * - * \details The transitions are in a form A times a times \alpha -> B times \beta | C \gamma | ..., where A, B, C \in Q, a \in T \cup { \eps }, and \alpha, \beta, \gamma \in G* + * \details The transitions are in a form A \times a \times \alpha -> B \times \beta | C \times \gamma | ..., where A, B, C \in Q, a \in T \cup { \eps }, and \alpha, \beta, \gamma \in G* * * \param from the source state (A) * \param input the input symbol or epsilon (a) @@ -451,7 +450,7 @@ public: /** * \brief Adds transitions to the automaton. * - * \details The transitions are in a form A times a times \alpha -> B times \beta | C \gamma | ..., where A, B, C \in Q, a \in T, and \alpha, \beta, \gamma \in G* + * \details The transitions are in a form A \times a \times \alpha -> B \times \beta | C \gamma | ..., where A, B, C \in Q, a \in T, and \alpha, \beta, \gamma \in G* * * \param from the source state (A) * \param input the input symbol (a) @@ -465,7 +464,7 @@ public: /** * \brief Adds transitions to the automaton. * - * \details The transitions are in a form A times \eps times \alpha -> B times \beta | C \gamma | ..., where A, B, C \in Q and \alpha, \beta, \gamma \in G* + * \details The transitions are in a form A \times \eps \times \alpha -> B \times \beta | C \gamma | ..., where A, B, C \in Q and \alpha, \beta, \gamma \in G* * * \param from the source state (A) * \param pop symbols to be poped from pushdown store on the transition use (\alpha) @@ -478,7 +477,7 @@ public: /** * \brief Removes a transition from the automaton. * - * \details The transition is in a form A times a times \alpha -> B times \beta, where A, B \in Q, a \in T \cup { \eps }, and \alpha, \beta \in G* + * \details The transition is in a form A \times a \times \alpha -> B \times \beta, where A, B \in Q, a \in T \cup { \eps }, and \alpha, \beta \in G* * * \param from the source state (A) * \param input the input symbol or epsilon (a) @@ -495,7 +494,7 @@ public: /** * \brief Removes a transition from the automaton. * - * \details The transition is in a form A times a times \alpha -> B times \beta, where A, B \in Q, a \in T, and \alpha, \beta \in G* + * \details The transition is in a form A \times a \times \alpha -> B \times \beta, where A, B \in Q, a \in T, and \alpha, \beta \in G* * * \param from the source state (A) * \param input the input symbol (a) @@ -512,7 +511,7 @@ public: /** * \brief Removes a transition from the automaton. * - * \details The transition is in a form A times \eps times \alpha -> B times \beta, where A, B \in Q and \alpha, \beta \in G* + * \details The transition is in a form A \times \eps \times \alpha -> B \times \beta, where A, B \in Q and \alpha, \beta \in G* * * \param from the source state (A) * \param pop symbols poped from pushdown store on the transition use (\alpha) @@ -908,7 +907,7 @@ public: /** * Helper class specifying constraints for the automaton's internal pushdown store alphabet component. * - * \tparam SymbolType used for the terminal alphabet of the automaton. + * \tparam InputSymbolType used for the terminal alphabet of the automaton. * \tparam EpsilonSymbolType used for the epsilon in the automaton * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. * \tparam StateType used for the terminal alphabet of the automaton. @@ -942,7 +941,7 @@ public: } /** - * Returns true as all symbols are possibly available to be elements of the input alphabet. + * Returns true as all symbols are possibly available to be elements of the pushdown store alphabet. * * \param automaton the tested automaton * \param state the tested state @@ -954,7 +953,7 @@ public: } /** - * All symbols are valid as input symbols. + * All symbols are valid as pushdown store symbols. * * \param automaton the tested automaton * \param state the tested state @@ -966,7 +965,7 @@ public: /** * Helper class specifying constraints for the automaton's internal pushdown store initial element. * - * \tparam SymbolType used for the terminal alphabet of the automaton. + * \tparam InputSymbolType used for the terminal alphabet of the automaton. * \tparam EpsilonSymbolType used for the epsilon in the automaton * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. * \tparam StateType used for the terminal alphabet of the automaton. @@ -999,7 +998,7 @@ public: /** * Helper class specifying constraints for the automaton's internal states component. * - * \tparam SymbolType used for the terminal alphabet of the automaton. + * \tparam InputSymbolType used for the terminal alphabet of the automaton. * \tparam EpsilonSymbolType used for the epsilon in the automaton * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. * \tparam StateType used for the terminal alphabet of the automaton. @@ -1058,7 +1057,7 @@ public: /** * Helper class specifying constraints for the automaton's internal final states component. * - * \tparam SymbolType used for the terminal alphabet of the automaton. + * \tparam InputSymbolType used for the terminal alphabet of the automaton. * \tparam EpsilonSymbolType used for the epsilon in the automaton * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. * \tparam StateType used for the terminal alphabet of the automaton. @@ -1103,7 +1102,7 @@ public: /** * Helper class specifying constraints for the automaton's internal initial state element. * - * \tparam SymbolType used for the terminal alphabet of the automaton. + * \tparam InputSymbolType used for the terminal alphabet of the automaton. * \tparam EpsilonSymbolType used for the epsilon in the automaton * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. * \tparam StateType used for the terminal alphabet of the automaton. diff --git a/alib2data/src/automaton/PDA/NPDTA.h b/alib2data/src/automaton/PDA/NPDTA.h index 07625827ced8ba4da6499a7afe6f2f23c6818f77..5bf43f8b70f84e3c181e16062220fb4918eee421 100644 --- a/alib2data/src/automaton/PDA/NPDTA.h +++ b/alib2data/src/automaton/PDA/NPDTA.h @@ -1,6 +1,22 @@ /* * NPDTA.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: 10. 5. 2016 * Author: Jakub Doupal */ @@ -40,227 +56,647 @@ class FinalStates; class InitialState; /** - * Push Down Translation Automaton + * Nondeterministic Pushdown Translation Automaton. Translates context free languages. + * + * \details + * Definition + * A = (Q, T, D, G, I, Z, \delta, F), + * Q (States) = nonempty finite set of states, + * T (TerminalAlphabet) = finite set of terminal symbols - having this empty won't let automaton do much though, + * T (OutputAlphabet) = finite set of output symbols - having this empty won't let automaton do translation at all, + * G (PushdownStoreAlphabet) = finite set of pushdown store symbol - having this empty makes the automaton equivalent to DFA + * I (InitialState) = initial state, + * Z (InitialPushdownStoreSymbol) = initial pushdown store symbol + * \delta = transition function of the form A \times a \times \alpha -> B \times \beta \times \gamma, where A, B \in Q, a \in T \cup { \eps }, \alpha, \beta \in G*, and \gamma \in D*, + * F (FinalStates) = set of final states + * + * \tparam InputSymbolType used for the terminal alphabet + * \tparam OutputSymbolType used for the output alphabet + * \tparam EpsilonSymbolType used for the epsilon in the automaton + * \tparam PushdownSymbolType used for the pushdown store alphabet + * \tparam StateType used to the states, and the initial state of the automaton. */ template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > class NPDTA final : public AutomatonBase, public core::Components < NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, ext::set < InputSymbolType >, component::Set, InputAlphabet, ext::set < OutputSymbolType >, component::Set, OutputAlphabet, ext::set < PushdownStoreSymbolType >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolType, component::Value, InitialSymbol, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > { -protected: + /** + * Transition function as mapping from a state times an input symbol or epsilon times string of pushdown store symbols on the left hand side to a state times string of pushdown store symbols times string of output symbols. + */ ext::map < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > > transitions; public: + /** + * \brief Creates a new instance of the automaton with a concrete set of states, input alphabet, pushdown store alphabet, initial state, initial pushdown symbol and a set of final states. + * + * \param states the initial set of states of the automaton + * \param inputAlphabet the initial input alphabet + * \param outputAlphabet the initial output alphabet + * \param pushdownStoreAlphabet the initial set of symbols used in the pushdown store by the automaton + * \param initialState the initial state of the automaton + * \param initialPushdownSymbol the initial pushdown symbol of the automaton + * \param finalStates the initial set of final states of the automaton + */ explicit NPDTA ( ext::set < StateType > states, ext::set < InputSymbolType > inputAlphabet, ext::set < OutputSymbolType > outputAlphabet, ext::set < PushdownStoreSymbolType > pushdownStoreSymbol, StateType initialState, PushdownStoreSymbolType initialPushdownSymbol, ext::set < StateType > finalStates ); + + /** + * \brief Creates a new instance of the automaton with a concrete initial state and initial pushdown store symbol. + * + * \param initialState the initial state of the automaton + * \param initialPushdownSymbol the initial pushdown symbol of the automaton + */ explicit NPDTA ( StateType initialState, PushdownStoreSymbolType initialPushdownSymbol ); - virtual AutomatonBase * clone ( ) const; + /** + * @copydoc automaton::AutomatonBase::clone() + */ + virtual AutomatonBase * clone ( ) const override; - virtual AutomatonBase * plunder ( ) &&; + /** + * @copydoc automaton::AutomatonBase::plunder() + */ + virtual AutomatonBase * plunder ( ) && override; + /** + * Getter of the initial state. + * + * \returns the initial state of the automaton + */ const StateType & getInitialState ( ) const & { - return this->template accessComponent < InitialState > ( ).get ( ); + return this-> template accessComponent < InitialState > ( ).get ( ); } + /** + * Getter of the initial state. + * + * \returns the initial state of the automaton + */ StateType && getInitialState ( ) && { - return std::move ( this->template accessComponent < InitialState > ( ).get ( ) ); + return std::move ( this-> template accessComponent < InitialState > ( ).get ( ) ); } + /** + * Setter of the initial state. + * + * \param state new initial state of the automaton + * + * \returns true if the initial state was indeed changed + */ bool setInitialState ( StateType state ) { - return this->template accessComponent < InitialState > ( ).set ( std::move ( state ) ); + return this-> template accessComponent < InitialState > ( ).set ( std::move ( state ) ); } + /** + * Getter of states. + * + * \returns the states of the automaton + */ const ext::set < StateType > & getStates ( ) const & { - return this->template accessComponent < States > ( ).get ( ); + return this-> template accessComponent < States > ( ).get ( ); } + /** + * Getter of states. + * + * \returns the states of the automaton + */ ext::set < StateType > && getStates ( ) && { - return std::move ( this->template accessComponent < States > ( ).get ( ) ); + return std::move ( this-> template accessComponent < States > ( ).get ( ) ); } + /** + * Adder of a state. + * + * \param state the new state to be added to a set of states + * + * \returns true if the state was indeed added + */ bool addState ( StateType state ) { - return this->template accessComponent < States > ( ).add ( std::move ( state ) ); + return this-> template accessComponent < States > ( ).add ( std::move ( state ) ); } + /** + * Setter of states. + * + * \param states completely new set of states + */ void setStates ( ext::set < StateType > states ) { - this->template accessComponent < States > ( ).set ( std::move ( states ) ); + this-> template accessComponent < States > ( ).set ( std::move ( states ) ); } + /** + * Remover of a state. + * + * \param state a state to be removed from a set of states + * + * \returns true if the state was indeed removed + */ void removeState ( const StateType & state ) { - this->template accessComponent < States > ( ).remove ( state ); + this-> template accessComponent < States > ( ).remove ( state ); } + /** + * Getter of final states. + * + * \returns the final states of the automaton + */ const ext::set < StateType > & getFinalStates ( ) const & { - return this->template accessComponent < FinalStates > ( ).get ( ); + return this-> template accessComponent < FinalStates > ( ).get ( ); } + /** + * Getter of final states. + * + * \returns the final states of the automaton + */ ext::set < StateType > && getFinalStates ( ) && { - return std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ); + return std::move ( this-> template accessComponent < FinalStates > ( ).get ( ) ); } + /** + * Adder of a final state. + * + * \param state the new state to be added to a set of final states + * + * \returns true if the state was indeed added + */ bool addFinalState ( StateType state ) { - return this->template accessComponent < FinalStates > ( ).add ( std::move ( state ) ); + return this-> template accessComponent < FinalStates > ( ).add ( std::move ( state ) ); } + /** + * Setter of final states. + * + * \param states completely new set of final states + */ void setFinalStates ( ext::set < StateType > states ) { - this->template accessComponent < FinalStates > ( ).set ( std::move ( states ) ); + this-> template accessComponent < FinalStates > ( ).set ( std::move ( states ) ); } + /** + * Remover of a final state. + * + * \param state a state to be removed from a set of final states + * + * \returns true if the state was indeed removed + */ void removeFinalState ( const StateType & state ) { - this->template accessComponent < FinalStates > ( ).remove ( state ); + this-> template accessComponent < FinalStates > ( ).remove ( state ); } + /** + * Getter of the pushdown store alphabet. + * + * \returns the pushdown store alphabet of the automaton + */ const ext::set < PushdownStoreSymbolType > & getPushdownStoreAlphabet ( ) const & { return this->template accessComponent < PushdownStoreAlphabet > ( ).get ( ); } + /** + * Getter of the pushdown store alphabet. + * + * \returns the pushdown store alphabet of the automaton + */ ext::set < PushdownStoreSymbolType > && getPushdownStoreAlphabet ( ) && { return std::move ( this->template accessComponent < PushdownStoreAlphabet > ( ).get ( ) ); } + /** + * Adder of a pushdown store symbol. + * + * \param symbol the new symbol to be added to a pushdown store alphabet + * + * \returns true if the symbol was indeed added + */ bool addPushdownStoreSymbol ( PushdownStoreSymbolType symbol ) { return this->template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbol ) ); } + /** + * Adder of pushdown store symbols. + * + * \param symbols new symbols to be added to a pushdown store alphabet + */ void addPushdownStoreSymbols ( ext::set < PushdownStoreSymbolType > symbols ) { this->template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbols ) ); } + /** + * Setter of a pushdown store alphabet. + * + * \param symbols completely new pushdown store alphabet + */ void setPushdownStoreAlphabet ( ext::set < PushdownStoreSymbolType > symbols ) { this->template accessComponent < PushdownStoreAlphabet > ( ).set ( std::move ( symbols ) ); } + /** + * Remover of an pushdown store symbol. + * + * \param symbol a symbol to be removed from a pushdown store alphabet + * + * \returns true if the symbol was indeed removed + */ void removePushdownStoreSymbol ( const PushdownStoreSymbolType & symbol ) { this->template accessComponent < PushdownStoreAlphabet > ( ).remove ( symbol ); } + /** + * Getter of the initial pushdown store symbol. + * + * \returns the initial pushdown store symbol of the automaton + */ const PushdownStoreSymbolType & getInitialSymbol ( ) const & { return this->template accessComponent < InitialSymbol > ( ).get ( ); } + /** + * Getter of the initial pushdown store symbol. + * + * \returns the initial pushdown store symbol of the automaton + */ PushdownStoreSymbolType && getInitialSymbol ( ) && { return std::move ( this->template accessComponent < InitialSymbol > ( ).get ( ) ); } + /** + * Setter of the initial pushdown store symbol. + * + * \param symbol new initial pushdown store symbol of the automaton + * + * \returns true if the initial pushdown store symbol was indeed changed + */ bool setInitialSymbol ( PushdownStoreSymbolType symbol ) { return this->template accessComponent < InitialSymbol > ( ).set ( std::move ( symbol ) ); } + /** + * Getter of the input alphabet. + * + * \returns the input alphabet of the automaton + */ const ext::set < InputSymbolType > & getInputAlphabet ( ) const & { - return this->template accessComponent < InputAlphabet > ( ).get ( ); + return this-> template accessComponent < InputAlphabet > ( ).get ( ); } + /** + * Getter of the input alphabet. + * + * \returns the input alphabet of the automaton + */ ext::set < InputSymbolType > && getInputAlphabet ( ) && { - return std::move ( this->template accessComponent < InputAlphabet > ( ).get ( ) ); + return std::move ( this-> template accessComponent < InputAlphabet > ( ).get ( ) ); } + /** + * Adder of a input symbol. + * + * \param symbol the new symbol to be added to an input alphabet + * + * \returns true if the symbol was indeed added + */ bool addInputSymbol ( InputSymbolType symbol ) { - return this->template accessComponent < InputAlphabet > ( ).add ( std::move ( symbol ) ); + return this-> template accessComponent < InputAlphabet > ( ).add ( std::move ( symbol ) ); } + /** + * Adder to an input symbols. + * + * \param symbols new symbols to be added to an input alphabet + */ void addInputSymbols ( ext::set < InputSymbolType > symbols ) { - this->template accessComponent < InputAlphabet > ( ).add ( std::move ( symbols ) ); + this-> template accessComponent < InputAlphabet > ( ).add ( std::move ( symbols ) ); } + /** + * Setter of input alphabet. + * + * \param symbols completely new input alphabet + */ void setInputAlphabet ( ext::set < InputSymbolType > symbols ) { - this->template accessComponent < InputAlphabet > ( ).set ( std::move ( symbols ) ); + this-> template accessComponent < InputAlphabet > ( ).set ( std::move ( symbols ) ); } + /** + * Remover of an input symbol. + * + * \param symbol a symbol to be removed from an input alphabet + * + * \returns true if the symbol was indeed removed + */ void removeInputSymbol ( const InputSymbolType & symbol ) { - this->template accessComponent < InputAlphabet > ( ).remove ( symbol ); + this-> template accessComponent < InputAlphabet > ( ).remove ( symbol ); } + /** + * Getter of the input alphabet. + * + * \returns the input alphabet of the automaton + */ const ext::set < OutputSymbolType > & getOutputAlphabet ( ) const & { return this->template accessComponent < OutputAlphabet > ( ).get ( ); } + /** + * Getter of the input alphabet. + * + * \returns the input alphabet of the automaton + */ ext::set < OutputSymbolType > && getOutputAlphabet ( ) && { return std::move ( this->template accessComponent < OutputAlphabet > ( ).get ( ) ); } + /** + * Adder to an output symbol. + * + * \param symbol the new symbol to be added to an output alphabet + * + * \returns true if the symbol was indeed added + */ bool addOutputSymbol ( OutputSymbolType symbol ) { return this->template accessComponent < OutputAlphabet > ( ).add ( std::move ( symbol ) ); } + /** + * Adder to an output symbols. + * + * \param symbols new symbols to be added to an output alphabet + */ void addOutputSymbols ( ext::set < OutputSymbolType > symbols ) { this->template accessComponent < OutputAlphabet > ( ).add ( std::move ( symbols ) ); } + /** + * Setter of an output alphabet. + * + * \param symbols completely new output alphabet + */ void setOutputAlphabet ( ext::set < OutputSymbolType > symbols ) { this->template accessComponent < OutputAlphabet > ( ).set ( std::move ( symbols ) ); } + /** + * Remover of an output symbol. + * + * \param symbol a symbol to be removed from an output alphabet + * + * \returns true if the symbol was indeed removed + */ void removeOutputSymbol ( const OutputSymbolType & symbol ) { this->template accessComponent < OutputAlphabet > ( ).remove ( symbol ); } /** - * Adds transition to the NPDTA. - * @param transition transition to add - * @throws AutomatonException when some part of the transition is not present - * in the NPDTA (state, input symbol, stack symbol, output symbol) or when transition already exists + * \brief Adds a transition to the automaton. + * + * \details The transition is in a form A \times a \times \alpha -> B \times \beta \times \gamma, where A, B \in Q, a \in T \cup { \eps }, \alpha, \beta \in G*, and \gamma in D* + * + * \param from the source state (A) + * \param input the input symbol or epsilon (a) + * \param pop symbols to be poped from pushdown store on the transition use (\alpha) + * \param to the target state (B) + * \param push symbols to be pushed to the pushdown store on the transition use (\beta) + * \param output resulting symbols of the transition when used (\gamma) + * + * \throws AutomatonException when transition contains state or symbol not present in the automaton components + * + * \returns true if the transition was indeed added */ bool addTransition ( StateType from, ext::variant < EpsilonType, InputSymbolType > input, ext::vector < PushdownStoreSymbolType > pop, StateType to, ext::vector < PushdownStoreSymbolType > push, ext::vector < OutputSymbolType > output ); + /** + * \brief Adds a transition to the automaton. + * + * \details The transition is in a form A \times a \times \alpha -> B \times \beta \times \gamma, where A, B \in Q, a \in T, \alpha, \beta \in G*, and \gamma in D* + * + * \param from the source state (A) + * \param input the input symbol (a) + * \param pop symbols to be poped from pushdown store on the transition use (\alpha) + * \param to the target state (B) + * \param push symbols to be pushed to the pushdown store on the transition use (\beta) + * \param output resulting symbols of the transition when used (\gamma) + * + * \throws AutomatonException when transition contains state or symbol not present in the automaton components + * + * \returns true if the transition was indeed added + */ bool addTransition ( StateType from, InputSymbolType input, ext::vector < PushdownStoreSymbolType > pop, StateType to, ext::vector < PushdownStoreSymbolType > push, ext::vector < OutputSymbolType > output ); + /** + * \brief Adds a transition to the automaton. + * + * \details The transition is in a form A \times \eps \times \alpha -> B \times \beta \times \gamma, where A, B \in Q, \alpha, \beta \in G*, and \gamma in D* + * + * \param from the source state (A) + * \param pop symbols to be poped from pushdown store on the transition use (\alpha) + * \param to the target state (B) + * \param push symbols to be pushed to the pushdown store on the transition use (\beta) + * \param output resulting symbols of the transition when used (\gamma) + * + * \throws AutomatonException when transition contains state or symbol not present in the automaton components + * + * \returns true if the transition was indeed added + */ bool addTransition ( StateType from, ext::vector < PushdownStoreSymbolType > pop, StateType to, ext::vector < PushdownStoreSymbolType > push, ext::vector < OutputSymbolType > output ); /** - * Adds transition to the NPDTA. - * @param transition transition to add - * @throws AutomatonException when some part of the transition is not present - * in the NPDTA (state, input symbol, stack symbol, output symbol) or when transition already exists + * \brief Adds transitions to the automaton. + * + * \details The transitions are in a form A \times a \times \alpha -> B_1 \times \beta_1 \times \gamma_1 | B_2 \times \beta_2 \times \gamma_2 | ..., where A, B_1, B_2 \in Q, a \in T \cup { \eps }, \alpha, \beta_1, \beta_2, \in G*, and \gamma_1, \gamma_2 in D* + * + * \param from the source state (A) + * \param input the input symbol or epsilon (a) + * \param pop symbols to be poped from pushdown store on the transition use (\alpha) + * \param targets the set of target state (B_1, B_2 ...), symbols to be pushed to the pushdown store on the transition use (\beta_1, \beta_2, ...), and resulting symbols of the transition when used (\gamma_1, \gamma_2, ...) + * + * \throws AutomatonException when transition contains state or symbol not present in the automaton components */ void addTransitions ( StateType from, ext::variant < EpsilonType, InputSymbolType > input, ext::vector < PushdownStoreSymbolType > pop, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > targets ); + /** + * \brief Adds transitions to the automaton. + * + * \details The transitions are in a form A \times a \times \alpha -> B_1 \times \beta_1 \times \gamma_1 | B_2 \times \beta_2 \times \gamma_2 | ..., where A, B_1, B_2 \in Q, a \in T, \alpha, \beta_1, \beta_2, \in G*, and \gamma_1, \gamma_2 in D* + * + * \param from the source state (A) + * \param input the input symbol (a) + * \param pop symbols to be poped from pushdown store on the transition use (\alpha) + * \param targets the set of target state (B_1, B_2 ...), symbols to be pushed to the pushdown store on the transition use (\beta_1, \beta_2, ...), and resulting symbols of the transition when used (\gamma_1, \gamma_2, ...) + * + * \throws AutomatonException when transition contains state or symbol not present in the automaton components + */ void addTransitions ( StateType from, InputSymbolType input, ext::vector < PushdownStoreSymbolType > pop, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > targets ); + /** + * \brief Adds transitions to the automaton. + * + * \details The transitions are in a form A \times \eps \times \alpha -> B_1 \times \beta_1 \times \gamma_1 | B_2 \times \beta_2 \times \gamma_2 | ..., where A, B_1, B_2 \in Q, \alpha, \beta_1, \beta_2, \in G*, and \gamma_1, \gamma_2 in D* + * + * \param from the source state (A) + * \param pop symbols to be poped from pushdown store on the transition use (\alpha) + * \param targets the set of target state (B_1, B_2 ...), symbols to be pushed to the pushdown store on the transition use (\beta_1, \beta_2, ...), and resulting symbols of the transition when used (\gamma_1, \gamma_2, ...) + * + * \throws AutomatonException when transition contains state or symbol not present in the automaton components + */ void addTransitions ( StateType from, ext::vector < PushdownStoreSymbolType > pop, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > targets ); /** - * Removes the transition from the NPDTA. - * @param transition transition to remove - * @throws AutomatonException when transition is not present in the NPDTA + * \brief Removes a transition from the automaton. + * + * \details The transition is in a form A \times a \times \alpha -> B \times \beta \times \gamma, where A, B \in Q, a \in T \cup { \eps }, \alpha, \beta \in G*, and \gamma \in D* + * + * \param from the source state (A) + * \param input the input symbol or epsilon (a) + * \param pop symbols poped from pushdown store on the transition use (\alpha) + * \param to the target state (B) + * \param push symbols pushed to the pushdown store on the transition use (\beta) + * \param output resulting symbols of the transition when used (\gamma) + * + * \throws AutomatonException when removed transition left hand side was found but the right hand side did not match. + * + * \returns true if the transition was indeed removed */ bool removeTransition ( const StateType & from, const ext::variant < EpsilonType, InputSymbolType > & input, const ext::vector < PushdownStoreSymbolType > & pop, const StateType & to, const ext::vector < PushdownStoreSymbolType > & push, const ext::vector < OutputSymbolType > & output ); + /** + * \brief Removes a transition from the automaton. + * + * \details The transition is in a form A \times a \times \alpha -> B \times \beta \times \gamma, where A, B \in Q, a \in T, \alpha, \beta \in G*, and \gamma \in D* + * + * \param from the source state (A) + * \param input the input symbol (a) + * \param pop symbols poped from pushdown store on the transition use (\alpha) + * \param to the target state (B) + * \param push symbols pushed to the pushdown store on the transition use (\beta) + * \param output resulting symbols of the transition when used (\gamma) + * + * \throws AutomatonException when removed transition left hand side was found but the right hand side did not match. + * + * \returns true if the transition was indeed removed + */ bool removeTransition ( const StateType & from, const InputSymbolType & input, const ext::vector < PushdownStoreSymbolType > & pop, const StateType & to, const ext::vector < PushdownStoreSymbolType > & push, const ext::vector < OutputSymbolType > & output ); + /** + * \brief Removes a transition from the automaton. + * + * \details The transition is in a form A \times \eps \times \alpha -> B \times \beta \times \gamma, where A, B \in Q, a \in T, \alpha, \beta \in G*, and \gamma \in D* + * + * \param from the source state (A) + * \param pop symbols poped from pushdown store on the transition use (\alpha) + * \param to the target state (B) + * \param push symbols pushed to the pushdown store on the transition use (\beta) + * \param output resulting symbols of the transition when used (\gamma) + * + * \throws AutomatonException when removed transition left hand side was found but the right hand side did not match. + * + * \returns true if the transition was indeed removed + */ bool removeTransition ( const StateType & from, const ext::vector < PushdownStoreSymbolType > & pop, const StateType & to, const ext::vector < PushdownStoreSymbolType > & push, const ext::vector < OutputSymbolType > & output ); /** - * @return NPDTA transitions + * Get the transition function of the automaton in its natural form. + * + * \returns transition function of the automaton */ const ext::map < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > > & getTransitions ( ) const &; + /** + * Get the transition function of the automaton in its natural form. + * + * \returns transition function of the automaton + */ ext::map < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::set < ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > > && getTransitions ( ) &&; + /** + * Get a subset of the transition function of the automaton, with the source state fixed in the transitions natural representation. + * + * \param from filter the transition function based on this state as a source state + * + * \returns a subset of the transition function of the automaton with the source state fixed + */ ext::map < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector < PushdownStoreSymbolType > >, ext::tuple < StateType, ext::vector < PushdownStoreSymbolType >, ext::vector < OutputSymbolType > > > getTransitionsFromState ( const StateType & from ) const; - virtual int compare ( const ObjectBase & other ) const { + /** + * @copydoc alib::CommonBase<ObjectBase>::compare ( const ObjectBase & ) + */ + virtual int compare ( const ObjectBase & other ) const override { if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other ); return ext::type_index ( typeid ( * this ) ) - ext::type_index ( typeid ( other ) ); } - virtual int compare ( const NPDTA & other ) const; + /** + * The actual compare method + * + * \param other the other instance + * + * \returns the actual relation between two by type same automata instances + */ + int compare ( const NPDTA & other ) const; - virtual void operator >>( std::ostream & os ) const; + /** + * @copydoc alib::CommonBase<ObjectBase>::operator >> ( std::ostream & ) + */ + virtual void operator >>( std::ostream & os ) const override; - virtual explicit operator std::string ( ) const; + /** + * @copydoc alib::CommonBase<ObjectBase>::operator std::string ( ) + */ + virtual explicit operator std::string ( ) const override; + /** + * \brief The XML tag name of class. + * + * \details Intentionaly a static member function to be safe in the initialisation before the main function starts. + * + * \returns string representing the XML tag name of the class + */ static const std::string & getXmlTagName() { static std::string xmlTagName = "NPDTA"; return xmlTagName; } + /** + * Parsing from a sequence of xml tokens helper. + * + * \params input the iterator to sequence of xml tokens to parse from + * + * \returns the new instance of the automaton + */ static NPDTA parse ( ext::deque < sax::Token >::iterator & input ); + + /** + * Helper for parsing of individual transitions of the automaton from a sequence of xml tokens. + * + * \params input the iterator to sequence of xml tokens to parse from + * \params automaton the automaton to add the rule to + */ static void parseTransition ( ext::deque < sax::Token >::iterator & input, NPDTA & automaton ); + /** + * Composing to a sequence of xml tokens helper. + * + * \param out the sink for new xml tokens representing the automaton + * \param automaton the automaton to compose + */ static void compose ( ext::deque < sax::Token > & out, const NPDTA & automaton ); + + /** + * Helper for composing transitions of the automaton to a sequence of xml tokens. + * + * \param out the sink for xml tokens representing the rules of the automaton + * \param automaton the automaton to compose + */ static void composeTransitions ( ext::deque < sax::Token > & out, const NPDTA & automaton ); - virtual object::ObjectBase * inc ( ) &&; + /** + * @copydoc alib::GrammarBase::inc() + */ + virtual object::ObjectBase * inc ( ) && override; + /** + * Type of normalized automaton. + */ typedef NPDTA < > normalized_type; }; @@ -537,9 +973,26 @@ object::ObjectBase* NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, Push namespace core { +/** + * Helper class specifying constraints for the automaton's internal input alphabet component. + * + * \tparam InputSymbolType used for the terminal alphabet of the automaton. + * \tparam OutputSymbolType used for the output alphabet of the automaton. + * \tparam EpsilonSymbolType used for the epsilon in the automaton + * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. + * \tparam StateType used for the terminal alphabet of the automaton. + */ template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > class SetConstraint< automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, InputSymbolType, automaton::InputAlphabet > { public: + /** + * Returns true if the symbol is still used in some transition of the automaton. + * + * \param automaton the tested automaton + * \param symbol the tested symbol + * + * \returns true if the symbol is used, false othervise + */ static bool used ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const InputSymbolType & symbol ) { for ( const std::pair<const ext::tuple<StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector<PushdownStoreSymbolType> >, ext::set<ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > > > >& transition : automaton.getTransitions()) if (std::get<1>(transition.first).template is < InputSymbolType >() && symbol == std::get<1>(transition.first).template get < InputSymbolType >()) @@ -548,17 +1001,48 @@ public: return false; } + /** + * Returns true as all symbols are possibly available to be elements of the input alphabet. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true + */ static bool available ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const InputSymbolType & ) { return true; } + /** + * All symbols are valid as input symbols. + * + * \param automaton the tested automaton + * \param state the tested state + */ static void valid ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const InputSymbolType & ) { } }; +/** + * Helper class specifying constraints for the automaton's internal pushdown store alphabet component. + * + * \tparam InputSymbolType used for the terminal alphabet of the automaton. + * \tparam OutputSymbolType used for the output alphabet of the automaton. + * \tparam EpsilonSymbolType used for the epsilon in the automaton + * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. + * \tparam StateType used for the terminal alphabet of the automaton. + */ template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > class SetConstraint< automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, OutputSymbolType, automaton::OutputAlphabet > { public: + /** + * Returns true if the symbol is still used in some transition of the automaton. + * + * \param automaton the tested automaton + * \param symbol the tested symbol + * + * \returns true if the symbol is used, false othervise + */ static bool used ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const OutputSymbolType & symbol ) { for ( const std::pair<const ext::tuple<StateType, ext::variant < EpsilonType, InputSymbolType >, ext::vector<PushdownStoreSymbolType> >, ext::set<ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > > > >& transition : automaton.getTransitions()) for(const ext::tuple<StateType, ext::vector<PushdownStoreSymbolType>, ext::vector < OutputSymbolType > >& target : transition.second) @@ -568,17 +1052,48 @@ public: return false; } + /** + * Returns true as all symbols are possibly available to be elements of the output alphabet. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true + */ static bool available ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const OutputSymbolType & ) { return true; } + /** + * All symbols are valid as output symbols. + * + * \param automaton the tested automaton + * \param state the tested state + */ static void valid ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const OutputSymbolType & ) { } }; +/** + * Helper class specifying constraints for the automaton's internal pushdown store alphabet component. + * + * \tparam InputSymbolType used for the terminal alphabet of the automaton. + * \tparam OutputSymbolType used for the output alphabet of the automaton. + * \tparam EpsilonSymbolType used for the epsilon in the automaton + * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. + * \tparam StateType used for the terminal alphabet of the automaton. + */ template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > class SetConstraint< automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::PushdownStoreAlphabet > { public: + /** + * Returns true if the symbol is still used in some transition of the automaton. + * + * \param automaton the tested automaton + * \param symbol the tested symbol + * + * \returns true if the symbol is used, false othervise + */ static bool used ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const PushdownStoreSymbolType & symbol ) { if(automaton.getInitialSymbol() == symbol) return true; @@ -596,28 +1111,82 @@ public: return false; } + /** + * Returns true as all symbols are possibly available to be elements of the pushdown store alphabet. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true + */ static bool available ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType & ) { return true; } + /** + * All symbols are valid as pushdown store symbols. + * + * \param automaton the tested automaton + * \param state the tested state + */ static void valid ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType & ) { } }; +/** + * Helper class specifying constraints for the automaton's internal pushdown store initial element. + * + * \tparam InputSymbolType used for the terminal alphabet of the automaton. + * \tparam OutputSymbolType used for the output alphabet of the automaton. + * \tparam EpsilonSymbolType used for the epsilon in the automaton + * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. + * \tparam StateType used for the terminal alphabet of the automaton. + */ template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > class ElementConstraint< automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::InitialSymbol > { public: + /** + * Determines whether the initial pushdown store symbol is available in the automaton's pushdown store alphabet. + * + * \param automaton the tested automaton + * \param symbol the tested symbol + * + * \returns true if the pushdown store symbol is already in the pushdown store alphabet of the automaton + */ static bool available ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const PushdownStoreSymbolType & symbol ) { return automaton.template accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); } + /** + * All pushdown store symbols are valid as an initial pusdown store symbol of the automaton. + * + * \param automaton the tested automaton + * \param symbol the tested symbol + */ static void valid ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType & ) { } }; +/** + * Helper class specifying constraints for the automaton's internal states component. + * + * \tparam InputSymbolType used for the terminal alphabet of the automaton. + * \tparam OutputSymbolType used for the output alphabet of the automaton. + * \tparam EpsilonSymbolType used for the epsilon in the automaton + * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. + * \tparam StateType used for the terminal alphabet of the automaton. + */ template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > class SetConstraint< automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, StateType, automaton::States > { public: + /** + * Returns true if the state is still used in some transition of the automaton. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true if the state is used, false othervise + */ static bool used ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const StateType & state ) { if ( automaton.getInitialState ( ) == state ) return true; @@ -637,36 +1206,104 @@ public: return false; } + /** + * Returns true as all states are possibly available to be elements of the states. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true + */ static bool available ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const StateType & ) { return true; } + /** + * All states are valid as a state of the automaton. + * + * \param automaton the tested automaton + * \param state the tested state + */ static void valid ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const StateType & ) { } }; +/** + * Helper class specifying constraints for the automaton's internal final states component. + * + * \tparam InputSymbolType used for the terminal alphabet of the automaton. + * \tparam OutputSymbolType used for the output alphabet of the automaton. + * \tparam EpsilonSymbolType used for the epsilon in the automaton + * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. + * \tparam StateType used for the terminal alphabet of the automaton. + */ template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > class SetConstraint< automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, StateType, automaton::FinalStates > { public: + /** + * Returns true if the state is still used in some transition of the automaton. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true if the state is used, false othervise + */ static bool used ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const StateType & ) { return false; } + /** + * Determines whether the state is available in the automaton's states set. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true if the state is already in the set of states of the automaton + */ static bool available ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const StateType & state ) { return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); } + /** + * All states are valid as a final state of the automaton. + * + * \param automaton the tested automaton + * \param state the tested state + */ static void valid ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const StateType & ) { } }; +/** + * Helper class specifying constraints for the automaton's internal initial state element. + * + * \tparam InputSymbolType used for the terminal alphabet of the automaton. + * \tparam OutputSymbolType used for the output alphabet of the automaton. + * \tparam EpsilonSymbolType used for the epsilon in the automaton + * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. + * \tparam StateType used for the terminal alphabet of the automaton. + */ template < class InputSymbolType, class OutputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > class ElementConstraint< automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, StateType, automaton::InitialState > { public: + /** + * Determines whether the state is available in the automaton's states set. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true if the state is already in the set of states of the automaton + */ static bool available ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const StateType & state ) { return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); } + /** + * All states are valid as an initial state of the automaton. + * + * \param automaton the tested automaton + * \param state the tested state + */ static void valid ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const StateType & ) { } }; diff --git a/alib2data/src/automaton/PDA/SinglePopDPDA.h b/alib2data/src/automaton/PDA/SinglePopDPDA.h index f1cc4cb9e0d517f2e5ae2be573f971ea151c7196..4b4806e25fac682ff1dfc32555bcf115c2814737 100644 --- a/alib2data/src/automaton/PDA/SinglePopDPDA.h +++ b/alib2data/src/automaton/PDA/SinglePopDPDA.h @@ -1,6 +1,22 @@ /* * SinglePopDPDA.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: Apr 10, 2013 * Author: Jan Travnicek */ @@ -40,193 +56,536 @@ class FinalStates; class InitialState; /** - * Push Down Automaton + * \brief + * Deterministic pushdown automaton requiring a symbol pop from pushdown store on each transition use. Accepts subset of context free languages. + + * \details + * Definition + * A = (Q, T, G, I, Z, \delta, F), + * Q (States) = nonempty finite set of states, + * T (TerminalAlphabet) = finite set of terminal symbols - having this empty won't let automaton do much though, + * G (PushdownStoreAlphabet) = finite set of pushdown store symbol - having this empty makes the automaton equivalent to DFA + * I (InitialState) = initial state, + * Z (InitialPushdownStoreSymbol) = initial pushdown store symbol + * \delta = transition function of the form A \times a \times g -> B \times \beta, where A, B \in Q, a \in T \cup { \eps }, g \in G, and \beta \in G*, + * F (FinalStates) = set of final states + * + * The transition functions must meet following criteria. Othervise adding conflicting transition will cause exception. + * $|\delta (q, a, g)| \leq 1$, $\forall q, a, \gamma, q \in Q, a \in (T \cup \{\varepsilon\}), g \in G.$ + * if $\delta(q, a, g) \neq \emptyset$, $\delta (q, \varepsilon, h) \neq \emptyset$, then $g \neq h$). * - * $|\delta (q, a, \gamma)| \leq 1$, $\forall q, a, \gamma, q \in Q, a \in (T \cup \{\varepsilon\}), \gamma \in G^*.$ - * if $\delta (q, a, r) \neq \emptyset$, $\delta (q, a, s) \neq \emptyset$ then $r \neq s$. - * if $\delta(q, a, r) \neq \emptyset$, $\delta (q, \varepsilon, s) \neq \emptyset$, then $r \neq s$. + * \tparam InputSymbolType used for the terminal alphabet + * \tparam EpsilonSymbolType used for the epsilon in the automaton + * \tparam PushdownSymbolType used for the pushdown store alphabet + * \tparam StateType used to the states, and the initial state of the automaton. */ template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > class SinglePopDPDA final : public AutomatonBase, public core::Components < SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, ext::set < InputSymbolType >, component::Set, InputAlphabet, ext::set < PushdownStoreSymbolType >, component::Set, PushdownStoreAlphabet, PushdownStoreSymbolType, component::Value, InitialSymbol, ext::set < StateType >, component::Set, std::tuple < States, FinalStates >, StateType, component::Value, InitialState > { protected: + /** + * Transition function as mapping from a state times an input symbol or epsilon times pushdown store symbol on the left hand side to a state times string of pushdown store symbols. + */ ext::map < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, PushdownStoreSymbolType >, ext::pair < StateType, ext::vector < PushdownStoreSymbolType > > > transitions; public: + /** + * \brief Creates a new instance of the automaton with a concrete set of states, input alphabet, pushdown store alphabet, initial state, initial pushdown symbol and a set of final states. + * + * \param states the initial set of states of the automaton + * \param inputAlphabet the initial input alphabet + * \param pushdownStoreAlphabet the initial set of symbols used in the pushdown store by the automaton + * \param initialState the initial state of the automaton + * \param initialPushdownSymbol the initial pushdown symbol of the automaton + * \param finalStates the initial set of final states of the automaton + */ explicit SinglePopDPDA ( ext::set < StateType > states, ext::set < InputSymbolType > inputAlphabet, ext::set < PushdownStoreSymbolType > pushdownStoreSymbol, StateType initialState, PushdownStoreSymbolType initialPushdownSymbol, ext::set < StateType > finalStates ); + + /** + * \brief Creates a new instance of the automaton with a concrete initial state and initial pushdown store symbol. + * + * \param initialState the initial state of the automaton + * \param initialPushdownSymbol the initial pushdown symbol of the automaton + */ explicit SinglePopDPDA ( StateType initialState, PushdownStoreSymbolType initialPushdownSymbol ); - virtual AutomatonBase * clone ( ) const; + /** + * @copydoc automaton::AutomatonBase::clone() + */ + virtual AutomatonBase * clone ( ) const override; - virtual AutomatonBase * plunder ( ) &&; + /** + * @copydoc automaton::AutomatonBase::plunder() + */ + virtual AutomatonBase * plunder ( ) && override; + /** + * Getter of the initial state. + * + * \returns the initial state of the automaton + */ const StateType & getInitialState ( ) const & { - return this->template accessComponent < InitialState > ( ).get ( ); + return this-> template accessComponent < InitialState > ( ).get ( ); } + /** + * Getter of the initial state. + * + * \returns the initial state of the automaton + */ StateType && getInitialState ( ) && { - return std::move ( this->template accessComponent < InitialState > ( ).get ( ) ); + return std::move ( this-> template accessComponent < InitialState > ( ).get ( ) ); } + /** + * Setter of the initial state. + * + * \param state new initial state of the automaton + * + * \returns true if the initial state was indeed changed + */ bool setInitialState ( StateType state ) { - return this->template accessComponent < InitialState > ( ).set ( std::move ( state ) ); + return this-> template accessComponent < InitialState > ( ).set ( std::move ( state ) ); } + /** + * Getter of states. + * + * \returns the states of the automaton + */ const ext::set < StateType > & getStates ( ) const & { - return this->template accessComponent < States > ( ).get ( ); + return this-> template accessComponent < States > ( ).get ( ); } + /** + * Getter of states. + * + * \returns the states of the automaton + */ ext::set < StateType > && getStates ( ) && { - return std::move ( this->template accessComponent < States > ( ).get ( ) ); + return std::move ( this-> template accessComponent < States > ( ).get ( ) ); } + /** + * Adder of a state. + * + * \param state the new state to be added to a set of states + * + * \returns true if the state was indeed added + */ bool addState ( StateType state ) { - return this->template accessComponent < States > ( ).add ( std::move ( state ) ); + return this-> template accessComponent < States > ( ).add ( std::move ( state ) ); } + /** + * Setter of states. + * + * \param states completely new set of states + */ void setStates ( ext::set < StateType > states ) { - this->template accessComponent < States > ( ).set ( std::move ( states ) ); + this-> template accessComponent < States > ( ).set ( std::move ( states ) ); } + /** + * Remover of a state. + * + * \param state a state to be removed from a set of states + * + * \returns true if the state was indeed removed + */ void removeState ( const StateType & state ) { - this->template accessComponent < States > ( ).remove ( state ); + this-> template accessComponent < States > ( ).remove ( state ); } + /** + * Getter of final states. + * + * \returns the final states of the automaton + */ const ext::set < StateType > & getFinalStates ( ) const & { - return this->template accessComponent < FinalStates > ( ).get ( ); + return this-> template accessComponent < FinalStates > ( ).get ( ); } + /** + * Getter of final states. + * + * \returns the final states of the automaton + */ ext::set < StateType > && getFinalStates ( ) && { - return std::move ( this->template accessComponent < FinalStates > ( ).get ( ) ); + return std::move ( this-> template accessComponent < FinalStates > ( ).get ( ) ); } + /** + * Adder of a final state. + * + * \param state the new state to be added to a set of final states + * + * \returns true if the state was indeed added + */ bool addFinalState ( StateType state ) { - return this->template accessComponent < FinalStates > ( ).add ( std::move ( state ) ); + return this-> template accessComponent < FinalStates > ( ).add ( std::move ( state ) ); } + /** + * Setter of final states. + * + * \param states completely new set of final states + */ void setFinalStates ( ext::set < StateType > states ) { - this->template accessComponent < FinalStates > ( ).set ( std::move ( states ) ); + this-> template accessComponent < FinalStates > ( ).set ( std::move ( states ) ); } + /** + * Remover of a final state. + * + * \param state a state to be removed from a set of final states + * + * \returns true if the state was indeed removed + */ void removeFinalState ( const StateType & state ) { - this->template accessComponent < FinalStates > ( ).remove ( state ); + this-> template accessComponent < FinalStates > ( ).remove ( state ); } + /** + * Getter of the pushdown store alphabet. + * + * \returns the pushdown store alphabet of the automaton + */ const ext::set < PushdownStoreSymbolType > & getPushdownStoreAlphabet ( ) const & { return this->template accessComponent < PushdownStoreAlphabet > ( ).get ( ); } + /** + * Getter of the pushdown store alphabet. + * + * \returns the pushdown store alphabet of the automaton + */ ext::set < PushdownStoreSymbolType > && getPushdownStoreAlphabet ( ) && { return std::move ( this->template accessComponent < PushdownStoreAlphabet > ( ).get ( ) ); } + /** + * Adder of a pushdown store symbol. + * + * \param symbol the new symbol to be added to a pushdown store alphabet + * + * \returns true if the symbol was indeed added + */ bool addPushdownStoreSymbol ( PushdownStoreSymbolType symbol ) { return this->template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbol ) ); } + /** + * Adder of pushdown store symbols. + * + * \param symbols new symbols to be added to a pushdown store alphabet + */ void addPushdownStoreSymbols ( ext::set < PushdownStoreSymbolType > symbols ) { this->template accessComponent < PushdownStoreAlphabet > ( ).add ( std::move ( symbols ) ); } + /** + * Setter of a pushdown store alphabet. + * + * \param symbols completely new pushdown store alphabet + */ void setPushdownStoreAlphabet ( ext::set < PushdownStoreSymbolType > symbols ) { this->template accessComponent < PushdownStoreAlphabet > ( ).set ( std::move ( symbols ) ); } + /** + * Remover of an pushdown store symbol. + * + * \param symbol a symbol to be removed from a pushdown store alphabet + * + * \returns true if the symbol was indeed removed + */ void removePushdownStoreSymbol ( const PushdownStoreSymbolType & symbol ) { this->template accessComponent < PushdownStoreAlphabet > ( ).remove ( symbol ); } + /** + * Getter of the initial pushdown store symbol. + * + * \returns the initial pushdown store symbol of the automaton + */ const PushdownStoreSymbolType & getInitialSymbol ( ) const & { return this->template accessComponent < InitialSymbol > ( ).get ( ); } + /** + * Getter of the initial pushdown store symbol. + * + * \returns the initial pushdown store symbol of the automaton + */ PushdownStoreSymbolType && getInitialSymbol ( ) && { return std::move ( this->template accessComponent < InitialSymbol > ( ).get ( ) ); } + /** + * Setter of the initial pushdown store symbol. + * + * \param symbol new initial pushdown store symbol of the automaton + * + * \returns true if the initial pushdown store symbol was indeed changed + */ bool setInitialSymbol ( PushdownStoreSymbolType symbol ) { return this->template accessComponent < InitialSymbol > ( ).set ( std::move ( symbol ) ); } + /** + * Getter of the input alphabet. + * + * \returns the input alphabet of the automaton + */ const ext::set < InputSymbolType > & getInputAlphabet ( ) const & { - return this->template accessComponent < InputAlphabet > ( ).get ( ); + return this-> template accessComponent < InputAlphabet > ( ).get ( ); } + /** + * Getter of the input alphabet. + * + * \returns the input alphabet of the automaton + */ ext::set < InputSymbolType > && getInputAlphabet ( ) && { - return std::move ( this->template accessComponent < InputAlphabet > ( ).get ( ) ); + return std::move ( this-> template accessComponent < InputAlphabet > ( ).get ( ) ); } + /** + * Adder of a input symbol. + * + * \param symbol the new symbol to be added to an input alphabet + * + * \returns true if the symbol was indeed added + */ bool addInputSymbol ( InputSymbolType symbol ) { - return this->template accessComponent < InputAlphabet > ( ).add ( std::move ( symbol ) ); + return this-> template accessComponent < InputAlphabet > ( ).add ( std::move ( symbol ) ); } + /** + * Adder of input symbols. + * + * \param symbols new symbols to be added to an input alphabet + */ void addInputSymbols ( ext::set < InputSymbolType > symbols ) { - this->template accessComponent < InputAlphabet > ( ).add ( std::move ( symbols ) ); + this-> template accessComponent < InputAlphabet > ( ).add ( std::move ( symbols ) ); } + /** + * Setter of input alphabet. + * + * \param symbols completely new input alphabet + */ void setInputAlphabet ( ext::set < InputSymbolType > symbols ) { - this->template accessComponent < InputAlphabet > ( ).set ( std::move ( symbols ) ); + this-> template accessComponent < InputAlphabet > ( ).set ( std::move ( symbols ) ); } + /** + * Remover of an input symbol. + * + * \param symbol a symbol to be removed from an input alphabet + * + * \returns true if the symbol was indeed removed + */ void removeInputSymbol ( const InputSymbolType & symbol ) { - this->template accessComponent < InputAlphabet > ( ).remove ( symbol ); + this-> template accessComponent < InputAlphabet > ( ).remove ( symbol ); } /** - * Adds transition to the SinglePopDPDA. - * @param transition transition to add - * @throws AutomatonException when some part of the transition is not present - * in the SinglePopDPDA (state, input symbol, stack symbol) or when transition already exists + * \brief Adds a transition to the automaton. + * + * \details The transition is in a form A \times a \times g -> B \times \beta, where A, B \in Q, a \in T \cup { \eps }, g \in G, and \beta \in G* + * + * \param from the source state (A) + * \param input the input symbol or epsilon (a) + * \param pop symbol to be poped from pushdown store on the transition use (g) + * \param to the target state (B) + * \param push symbols to be pushed to the pushdown store on the transition use (\beta) + * + * \throws AutomatonException when transition contains state or symbol not present in the automaton components or when the transition would cause nondeterminism + * + * \returns true if the transition was indeed added */ bool addTransition ( StateType from, ext::variant < EpsilonType, InputSymbolType > input, PushdownStoreSymbolType pop, StateType to, ext::vector < PushdownStoreSymbolType > push ); + /** + * \brief Adds a transition to the automaton. + * + * \details The transition is in a form A \times a \times g -> B \times \beta, where A, B \in Q, a \in T, g \in G, and \beta \in G* + * + * \param from the source state (A) + * \param input the input symbol (a) + * \param pop symbol to be poped from pushdown store on the transition use (g) + * \param to the target state (B) + * \param push symbols to be pushed to the pushdown store on the transition use (\beta) + * + * \throws AutomatonException when transition contains state or symbol not present in the automaton components or when the transition would cause nondeterminism + * + * \returns true if the transition was indeed added + */ bool addTransition ( StateType from, InputSymbolType input, PushdownStoreSymbolType pop, StateType to, ext::vector < PushdownStoreSymbolType > push ); + /** + * \brief Adds a transition to the automaton. + * + * \details The transition is in a form A \times \eps \times g -> B \times \beta, where A, B \in Q, g \in G, and \beta \in G* + * + * \param from the source state (A) + * \param pop symbols to be poped from pushdown store on the transition use (g) + * \param to the target state (B) + * \param push symbols to be pushed to the pushdown store on the transition use (\beta) + * + * \throws AutomatonException when transition contains state or symbol not present in the automaton components or when the transition would cause nondeterminism + * + * \returns true if the transition was indeed added + */ bool addTransition ( StateType from, PushdownStoreSymbolType pop, StateType to, ext::vector < PushdownStoreSymbolType > push ); /** - * Removes the transition from the SinglePopDPDA. - * @param transition transition to remove - * @throws AutomatonException when transition is not present in the SinglePopDPDA + * \brief Removes a transition from the automaton. + * + * \details The transition is in a form A \times a \times g -> B \times \beta, where A, B \in Q, a \in T \cup { \eps }, g \in G, and \beta \in G* + * + * \param from the source state (A) + * \param input the input symbol or epsilon (a) + * \param pop symbols poped from pushdown store on the transition use (g) + * \param to the target state (B) + * \param push symbols pushed to the pushdown store on the transition use (\beta) + * + * \throws AutomatonException when removed transition left hand side was found but the right hand side did not match. + * + * \returns true if the transition was indeed removed */ bool removeTransition ( const StateType & from, const ext::variant < EpsilonType, InputSymbolType > & input, const PushdownStoreSymbolType & pop, const StateType & to, const ext::vector < PushdownStoreSymbolType > & push ); + /** + * \brief Removes a transition from the automaton. + * + * \details The transition is in a form A \times a \times g -> B \times \beta, where A, B \in Q, a \in T, g \in G, and \beta \in G* + * + * \param from the source state (A) + * \param input the input symbol (a) + * \param pop symbols poped from pushdown store on the transition use (g) + * \param to the target state (B) + * \param push symbols pushed to the pushdown store on the transition use (\beta) + * + * \throws AutomatonException when removed transition left hand side was found but the right hand side did not match. + * + * \returns true if the transition was indeed removed + */ bool removeTransition ( const StateType & from, const InputSymbolType & input, const PushdownStoreSymbolType & pop, const StateType & to, const ext::vector < PushdownStoreSymbolType > & push ); + /** + * \brief Removes a transition from the automaton. + * + * \details The transition is in a form A \times \eps \times g -> B \times \beta, where A, B \in Q, g \ in G, and \beta \in G* + * + * \param from the source state (A) + * \param pop symbols poped from pushdown store on the transition use (g) + * \param to the target state (B) + * \param push symbols pushed to the pushdown store on the transition use (\beta) + * + * \throws AutomatonException when removed transition left hand side was found but the right hand side did not match. + * + * \returns true if the transition was indeed removed + */ bool removeTransition ( const StateType & from, const PushdownStoreSymbolType & pop, const StateType & to, const ext::vector < PushdownStoreSymbolType > & push ); /** - * @return SinglePopDPDA transitions + * Get the transition function of the automaton in its natural form. + * + * \returns transition function of the automaton */ const ext::map < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, PushdownStoreSymbolType >, ext::pair < StateType, ext::vector < PushdownStoreSymbolType > > > & getTransitions ( ) const &; + /** + * Get the transition function of the automaton in its natural form. + * + * \returns transition function of the automaton + */ ext::map < ext::tuple < StateType, ext::variant < EpsilonType, InputSymbolType >, PushdownStoreSymbolType >, ext::pair < StateType, ext::vector < PushdownStoreSymbolType > > > && getTransitions ( ) &&; - virtual int compare ( const ObjectBase & other ) const { + /** + * @copydoc alib::CommonBase<ObjectBase>::compare ( const ObjectBase & ) + */ + virtual int compare ( const ObjectBase & other ) const override { if ( ext::type_index ( typeid ( * this ) ) == ext::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other ); return ext::type_index ( typeid ( * this ) ) - ext::type_index ( typeid ( other ) ); } - virtual int compare ( const SinglePopDPDA & other ) const; + /** + * The actual compare method + * + * \param other the other instance + * + * \returns the actual relation between two by type same automata instances + */ + int compare ( const SinglePopDPDA & other ) const; - virtual void operator >>( std::ostream & os ) const; + /** + * @copydoc alib::CommonBase<ObjectBase>::operator >> ( std::ostream & ) + */ + virtual void operator >>( std::ostream & os ) const override; - virtual explicit operator std::string ( ) const; + /** + * @copydoc alib::CommonBase<ObjectBase>::operator std::string ( ) + */ + virtual explicit operator std::string ( ) const override; + /** + * \brief The XML tag name of class. + * + * \details Intentionaly a static member function to be safe in the initialisation before the main function starts. + * + * \returns string representing the XML tag name of the class + */ static const std::string & getXmlTagName() { static std::string xmlTagName = "SinglePopDPDA"; return xmlTagName; } + /** + * Parsing from a sequence of xml tokens helper. + * + * \params input the iterator to sequence of xml tokens to parse from + * + * \returns the new instance of the automaton + */ static SinglePopDPDA parse ( ext::deque < sax::Token >::iterator & input ); + + /** + * Helper for parsing of individual transitions of the automaton from a sequence of xml tokens. + * + * \params input the iterator to sequence of xml tokens to parse from + * \params automaton the automaton to add the rule to + */ static void parseTransition ( ext::deque < sax::Token >::iterator & input, SinglePopDPDA & automaton ); + /** + * Composing to a sequence of xml tokens helper. + * + * \param out the sink for new xml tokens representing the automaton + * \param automaton the automaton to compose + */ static void compose ( ext::deque < sax::Token > & out, const SinglePopDPDA & automaton ); + + /** + * Helper for composing transitions of the automaton to a sequence of xml tokens. + * + * \param out the sink for xml tokens representing the rules of the automaton + * \param automaton the automaton to compose + */ static void composeTransitions ( ext::deque < sax::Token > & out, const SinglePopDPDA & automaton ); - virtual object::ObjectBase * inc ( ) &&; + /** + * @copydoc alib::GrammarBase::inc() + */ + virtual object::ObjectBase * inc ( ) && override; + /** + * Type of normalized automaton. + */ typedef SinglePopDPDA < > normalized_type; }; @@ -460,9 +819,25 @@ object::ObjectBase* SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreS namespace core { +/** + * Helper class specifying constraints for the automaton's internal input alphabet component. + * + * \tparam InputSymbolType used for the terminal alphabet of the automaton. + * \tparam EpsilonSymbolType used for the epsilon in the automaton + * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. + * \tparam StateType used for the terminal alphabet of the automaton. + */ template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > class SetConstraint< automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, InputSymbolType, automaton::InputAlphabet > { public: + /** + * Returns true if the symbol is still used in some transition of the automaton. + * + * \param automaton the tested automaton + * \param symbol the tested symbol + * + * \returns true if the symbol is used, false othervise + */ static bool used ( const automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const InputSymbolType & symbol ) { for ( const std::pair<const ext::tuple<StateType, ext::variant < EpsilonType, InputSymbolType >, PushdownStoreSymbolType>, ext::pair<StateType, ext::vector<PushdownStoreSymbolType> > >& transition : automaton.getTransitions()) if (std::get<1>(transition.first).template is < InputSymbolType >() && symbol == std::get<1>(transition.first).template get < InputSymbolType >()) @@ -471,17 +846,47 @@ public: return false; } + /** + * Returns true as all symbols are possibly available to be elements of the input alphabet. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true + */ static bool available ( const automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const InputSymbolType & ) { return true; } + /** + * All symbols are valid as input symbols. + * + * \param automaton the tested automaton + * \param state the tested state + */ static void valid ( const automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const InputSymbolType & ) { } }; +/** + * Helper class specifying constraints for the automaton's internal pushdown store alphabet component. + * + * \tparam InputSymbolType used for the terminal alphabet of the automaton. + * \tparam EpsilonSymbolType used for the epsilon in the automaton + * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. + * \tparam StateType used for the terminal alphabet of the automaton. + */ template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > class SetConstraint< automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::PushdownStoreAlphabet > { public: + /** + * Returns true if the symbol is still used in some transition of the automaton. + * + * \param automaton the tested automaton + * \param symbol the tested symbol + * + * \returns true if the symbol is used, false othervise + */ static bool used ( const automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const PushdownStoreSymbolType & symbol ) { for ( const std::pair<const ext::tuple<StateType, ext::variant < EpsilonType, InputSymbolType >, PushdownStoreSymbolType>, ext::pair<StateType, ext::vector<PushdownStoreSymbolType> > >& transition : automaton.getTransitions()) if (symbol == std::get<2>(transition.first) || std::find(transition.second.second.begin(), transition.second.second.end(), symbol) != transition.second.second.end()) @@ -493,28 +898,80 @@ public: return false; } + /** + * Returns true as all symbols are possibly available to be elements of the pushdown store alphabet. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true + */ static bool available ( const automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType & ) { return true; } + /** + * All symbols are valid as pushdown store symbols. + * + * \param automaton the tested automaton + * \param state the tested state + */ static void valid ( const automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType & ) { } }; +/** + * Helper class specifying constraints for the automaton's internal pushdown store initial element. + * + * \tparam InputSymbolType used for the terminal alphabet of the automaton. + * \tparam EpsilonSymbolType used for the epsilon in the automaton + * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. + * \tparam StateType used for the terminal alphabet of the automaton. + */ template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > class ElementConstraint< automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, PushdownStoreSymbolType, automaton::InitialSymbol > { public: + /** + * Determines whether the initial pushdown store symbol is available in the automaton's pushdown store alphabet. + * + * \param automaton the tested automaton + * \param symbol the tested symbol + * + * \returns true if the pushdown store symbol is already in the pushdown store alphabet of the automaton + */ static bool available ( const automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const PushdownStoreSymbolType & symbol ) { return automaton.template accessComponent < automaton::PushdownStoreAlphabet > ( ).get ( ).count ( symbol ); } + /** + * All pushdown store symbols are valid as an initial pusdown store symbol of the automaton. + * + * \param automaton the tested automaton + * \param symbol the tested symbol + */ static void valid ( const automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const PushdownStoreSymbolType & ) { } }; +/** + * Helper class specifying constraints for the automaton's internal states component. + * + * \tparam InputSymbolType used for the terminal alphabet of the automaton. + * \tparam EpsilonSymbolType used for the epsilon in the automaton + * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. + * \tparam StateType used for the terminal alphabet of the automaton. + */ template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > class SetConstraint< automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, StateType, automaton::States > { public: + /** + * Returns true if the state is still used in some transition of the automaton. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true if the state is used, false othervise + */ static bool used ( const automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const StateType & state ) { if ( automaton.getInitialState ( ) == state ) return true; @@ -529,36 +986,102 @@ public: return false; } + /** + * Returns true as all states are possibly available to be elements of the states. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true + */ static bool available ( const automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const StateType & ) { return true; } + /** + * All states are valid as a state of the automaton. + * + * \param automaton the tested automaton + * \param state the tested state + */ static void valid ( const automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const StateType & ) { } }; +/** + * Helper class specifying constraints for the automaton's internal final states component. + * + * \tparam InputSymbolType used for the terminal alphabet of the automaton. + * \tparam EpsilonSymbolType used for the epsilon in the automaton + * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. + * \tparam StateType used for the terminal alphabet of the automaton. + */ template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > class SetConstraint< automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, StateType, automaton::FinalStates > { public: + /** + * Returns true if the state is still used in some transition of the automaton. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true if the state is used, false othervise + */ static bool used ( const automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const StateType & ) { return false; } + /** + * Determines whether the state is available in the automaton's states set. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true if the state is already in the set of states of the automaton + */ static bool available ( const automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const StateType & state ) { return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); } + /** + * All states are valid as a final state of the automaton. + * + * \param automaton the tested automaton + * \param state the tested state + */ static void valid ( const automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const StateType & ) { } }; +/** + * Helper class specifying constraints for the automaton's internal initial state element. + * + * \tparam InputSymbolType used for the terminal alphabet of the automaton. + * \tparam EpsilonSymbolType used for the epsilon in the automaton + * \tparam PushdownSymbolType used for the pushdown store alphabet of the automaton. + * \tparam StateType used for the terminal alphabet of the automaton. + */ template < class InputSymbolType, class EpsilonType, class PushdownStoreSymbolType, class StateType > class ElementConstraint< automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType >, StateType, automaton::InitialState > { public: + /** + * Determines whether the state is available in the automaton's states set. + * + * \param automaton the tested automaton + * \param state the tested state + * + * \returns true if the state is already in the set of states of the automaton + */ static bool available ( const automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > & automaton, const StateType & state ) { return automaton.template accessComponent < automaton::States > ( ).get ( ).count ( state ); } + /** + * All states are valid as an initial state of the automaton. + * + * \param automaton the tested automaton + * \param state the tested state + */ static void valid ( const automaton::SinglePopDPDA < InputSymbolType, EpsilonType, PushdownStoreSymbolType, StateType > &, const StateType & ) { } };