previousnext
ASTL homeSTL home

DFA ascii write

 

Prototype

template <class DFA> 
void dfa_ascii_write(const DFA& dfa, ostream& out);

Description

Write dfa to out in the following file format:

state count
initial_state
nb transitions state 1
final (0/1)
tag
letter state letter state ...
nb transitions state 2
final (0/1)
tag
letter state letter state ...
...
...
...
...

 

Definition

Defined in falgo_stream.h.

Requirements on types

Preconditions

ostream& << const DFA::Tag& must be defined.

Example

CODE
OUTPUT

#include <tag.h>
#include <dfa_matrix.h>
#include <alphabet.h>
#include <language.h>
#include <astl_tree.h>
#include <minimize.h>
#include <falgo_stream.h>

main()
{
//spécifie the type of the DFA
typedef DFA_matrix<Type_alphabet<char> > 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;

//printing
dfa_ascii_write(dfa, cout);

}

# ./dfa_as
10
1
2 0 0 0 a 2 b 3
2 0 0 0 b 5 f 4
1 0 0 0 c 6
2 0 0 0 e 9 g 7
1 1 0 0 g 8
3 0 0 0 b 5 d 8 e 1
0 0 0 0
1 0 0 0 d 10
0 1 0 0
1 1 0 0 a 8

Notes

See also

dfa_binary_write, nfa_ascii_write