Converting dfa / regular expression to C Program step wise explanation | deterministic finite automata
Given : Regular Expression ((0 +1)* 01)
Step 1
Langugage L = {01,001,101,1101,000101, 001101 }
Minimum strings = { 01,001,101}
Few examples of invalid strings ={ 000,11100,01010}
Step 2
Draw Dfa of given regular expression
or draw Nfa of given regular expression and convert it to Dfa
Dfa of (( 0+1)*01)
dead states = null
initial state = State 1
Final State = state 3
Step 3
construct transition table of Dfa
Step 4
C program implementation
#include <stdio.h>
#include <string.h>
#include<conio.h>
int main()
{
char s[20];
int l, State, c;
char Temp;
printf("\n enter string to check: \n");
gets(s);
l=strlen(s); //length of the string
printf("String length is %d \n", l);
c=0;
printf("count is %d \n", c);
State=1; // initial state
printf("State is %d \n", State);
while(c<l)
{
Temp=s[c];
switch(State)
{
case 1:
if(Temp=='0')
State=2;
if(Temp=='1')
State=1;
break;
case 2:
if(Temp=='0')
State=2;
if(Temp=='1')
State=3;
break;
case 3:
if(Temp=='0')
State=2;
if(Temp=='1')
State=1;
break;
}
c++;
}
if(State==3)
printf("Valid string \n");
else
printf("InValid string \n");
getch();
return 0;
}
Step 5
output
Want any Specific tutorial, Do comment in the comment section below.