W
Willing 2 Learn
Below is a program I did to recognize a Finite State Automata for ASCII
(J+H)*. I got that one working but im having trouble getting the NFA
program to work. I really desperately need help!
My NFA has initial states: 2 and 12
ending states 2 and 12
I need help to switch program below from FSA to recognize NFA. I was
trying to do a general program so if i have another expression it can
be easily changed thus no nested if-statements as I thought.
I was thinking of having multiple arrays but wasn't quite sure how to
include this.
in this program, i want to:
Enter 1 bit at a time
list initial states
list the first bit of input
list the next states
list the next bit of input
list the next states
repeat until my string is recognized or dead.
Rules for my machine
2 with 0 turns on 2,3,4,5,6,7,8,9,12
3 with 1 turns on 2,4,5,6,7,8,9,12
4 with 0 turns on 2,5,6,7,8,9,12
5 with 0 turns on 2,6,7,8,9,12
6 with 1 turns on 2,7,8,9,12
7 with 0 turns on 2,8,9,12
8 with 1 turns on 2,9,12
9 with 0 turns on 2,12
12 with 0 turns on 2,12,13,14,15,16,17,18,19
13 with 1 turns on 2,12,14,15,16,17,18,19
14 with 0 turns on 2,12,15,16,17,18,19
15 with 0 turns on 2,12,16,17,18,19
16 with 1 turns on 2,12,17,18,19
17 with 0 turns on 2,12,19
18 with 0 turns on 2,12,19
12 with 0 turns on 2,12,
#include <iostream.h>
//(01001010 + 01001000)*
int main()
{
int delta[10][2] = {
{0,0}, //0
{2,0}, //1
{0,3},
{4,0},
{5,0},
{0,6}, //5
{7,0},
{9,8}, //7
{1,0}, //8
{1,0} //9
};
int s, q, qi, qf; //qi= initial state qf-final state
qi = 1; qf=1;
q=qi;
cout<<endl<<q;
cin>>s;
while(s < 2)
{
q = delta[q];
cout<<endl<<q;
cin>>s;
} // end while
if(q==qf)
{
cout<<"win";
}
else
{
cout<<"lose";
}
return 0;
}
(J+H)*. I got that one working but im having trouble getting the NFA
program to work. I really desperately need help!
My NFA has initial states: 2 and 12
ending states 2 and 12
I need help to switch program below from FSA to recognize NFA. I was
trying to do a general program so if i have another expression it can
be easily changed thus no nested if-statements as I thought.
I was thinking of having multiple arrays but wasn't quite sure how to
include this.
in this program, i want to:
Enter 1 bit at a time
list initial states
list the first bit of input
list the next states
list the next bit of input
list the next states
repeat until my string is recognized or dead.
Rules for my machine
2 with 0 turns on 2,3,4,5,6,7,8,9,12
3 with 1 turns on 2,4,5,6,7,8,9,12
4 with 0 turns on 2,5,6,7,8,9,12
5 with 0 turns on 2,6,7,8,9,12
6 with 1 turns on 2,7,8,9,12
7 with 0 turns on 2,8,9,12
8 with 1 turns on 2,9,12
9 with 0 turns on 2,12
12 with 0 turns on 2,12,13,14,15,16,17,18,19
13 with 1 turns on 2,12,14,15,16,17,18,19
14 with 0 turns on 2,12,15,16,17,18,19
15 with 0 turns on 2,12,16,17,18,19
16 with 1 turns on 2,12,17,18,19
17 with 0 turns on 2,12,19
18 with 0 turns on 2,12,19
12 with 0 turns on 2,12,
#include <iostream.h>
//(01001010 + 01001000)*
int main()
{
int delta[10][2] = {
{0,0}, //0
{2,0}, //1
{0,3},
{4,0},
{5,0},
{0,6}, //5
{7,0},
{9,8}, //7
{1,0}, //8
{1,0} //9
};
int s, q, qi, qf; //qi= initial state qf-final state
qi = 1; qf=1;
q=qi;
cout<<endl<<q;
cin>>s;
while(s < 2)
{
q = delta[q]
cout<<endl<<q;
cin>>s;
} // end while
if(q==qf)
{
cout<<"win";
}
else
{
cout<<"lose";
}
return 0;
}