AN AUTOMATON (DFA)

AND

ITS DECLARATION

a DFA exemple


#include <tag.h>
#include <dfa_matrix.h>
#include <alphabet.h>

//code corresponding to the DFA example
main()
{

//spécifie the type of the DFA
typedef DFA_matrix<Range_alphabet<char,'a','g'>,default_tag> DFA_type;

//initialising the DFA, empty
DFA_type dfa;

//creating and adding the states
DFA_type::State s[11];
for(int i=1;i<=10;i++)

s[i]=dfa.new_state();

//setting the transitions
dfa.set_trans(s[1],'a',s[2]);
dfa.set_trans(s[1],'b',s[3]);
dfa.set_trans(s[2],'f',s[4]);
dfa.set_trans(s[2],'b',s[5]);
dfa.set_trans(s[3],'c',s[6]);
dfa.set_trans(s[4],'g',s[7]);
dfa.set_trans(s[4],'e',s[9]);
dfa.set_trans(s[5],'g',s[8]);
dfa.set_trans(s[6],'b',s[5]);
dfa.set_trans(s[6],'d',s[8]);
dfa.set_trans(s[6],'e',s[10]);
dfa.set_trans(s[8],'d',s[10]);
dfa.set_trans(s[10],'a',s[8]);

//declaring initial and finals states...VERY IMPORTANT...
dfa.initial(s[1]);
dfa.final(s[5])=true;
dfa.final(s[9])=true;
dfa.final(s[10])=true;

}