48 template <
class AutomatonType >
49 requires isDFA < AutomatonType > || isNFA < AutomatonType >
53template <
class AutomatonType >
54requires isDFA < AutomatonType > || isNFA < AutomatonType >
56 static const unsigned NONE = 0;
57 static const unsigned FIRST = 1;
58 static const unsigned SECOND = 2;
62 for (
const auto &
q : first.getStates ( ) )
63 res.addState ( {
q, FIRST } );
64 for (
const auto &
q :
second.getStates ( ) )
65 res.addState ( {
q, SECOND } );
67 res.addInputSymbols ( first.getInputAlphabet ( ) );
68 res.addInputSymbols (
second.getInputAlphabet ( ) );
70 for (
const auto & t : first.getTransitions ( ) ) {
71 res.addTransition ( { t.first.first, FIRST }, t.first.second, { t.second, FIRST } );
73 if ( first.getFinalStates ( ).contains ( t.second ) )
74 res.addTransition ( { t.first.first, FIRST }, t.first.second, {
second.getInitialState ( ), SECOND } );
77 for (
const auto& t :
second.getTransitions ( ) )
78 res.addTransition ( { t.first.first, SECOND }, t.first.second, { t.second, SECOND } );
80 for (
const auto &
q :
second.getFinalStates ( ) )
81 res.addFinalState ( {
q, SECOND } );
83 if ( first.getFinalStates ( ).contains ( first.getInitialState ( ) ) ) {
85 res.addState ( q01q02 );
86 res.setInitialState ( q01q02 );
88 for (
const auto & t : first.getTransitionsFromState ( first.getInitialState ( ) ) ) {
89 res.addTransition ( q01q02, t.first.second, { t.second, FIRST } );
91 if ( first.getFinalStates ( ).contains ( t.second ) )
92 res.addTransition ( q01q02, t.first.second, { second.getInitialState ( ), SECOND } );
95 for (
const auto & t :
second.getTransitionsFromState (
second.getInitialState ( ) ) )
96 res.addTransition ( q01q02, t.first.second, { t.second, SECOND } );
98 if (
second.getFinalStates().contains(
second.getInitialState()))
99 res.addFinalState ( q01q02 );
Nondeterministic finite automaton. Accepts regular languages.
Definition: NFA.h:66
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
q
Definition: SingleInitialStateEpsilonTransition.h:85