previousnext
ASTL homeSTL home

Is_in

 

Prototype

template <class DFA, class InputIterator> 
bool is_in(const DFA &dfa, InputIterator start, InputIterator finish);

Description

Check if a word is in dfa language. Returns true if the word has been found and false otherwise.

Definition

Defined in language.h.

Requirements on types

Preconditions

InputIterator::value_type == DFA::Alphabet

Example

CODE
OUTPUT

#include <tag.h>
#include <dfa_matrix.h>
#include <alphabet.h>
#include <language.h>
#include <iterator>
#include <iostream.h>

//code corresponding to the DFA example, without
//the 10 to 8 transition, in order to avoid cyclicity (for language)


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]);

//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;

//writing the language on the standart output

language(dfa,ostream_iterator<DFA_type::Alphabet>(cout));
//is_in test
char toto[4]={'a','b','g','d'};
cout<<"is_in abgd ? "<<is_in(dfa,toto,toto+4)<<endl;
cout<<"is_in abg ? "<<is_in(dfa,toto,toto+3)<<endl;
}

# ./is_in
ab
abgd
afe
bcb
bcbgd
bcdd
bce
is_in abgd ? 1
is_in abg ? 0

Notes

See also

language,tag algorithm