Week 2 Program
1. Write a C program for implementation of Language recognizer for
following DFA on
symbols{a-z, 0-9} (only 36 characters):
Code:
#include<stdio.h>
#include<string.h>
int main()
int s=0;
char ch[100];
printf("enter the string:-");
scanf("%s",ch);
for(int i=0;i<strlen(ch);i++)
char c=ch[i];
if(s==0)
if(c=='i')
s=1;
else if((c>='a' && c<='h') || (c>='j' && c<='z'))
s=2;
else if(c>='0' && c<='9')
{
s=3;
else if(s==1)
if(c=='f')
s=4;
else if((c>='a' && c<='e') || (c>='g' && c<='z') || (c>='0' && c<='9'))
s=6;
else if(s==2)
if((c>='a' && c<='z') || (c>='0' && c<='9'))
s=6;
else if(s==3)
if((c>='0' && c<='9'))
s=3;
}
else if((c>='a' && c<='z'))
s=5;
else if(s==4)
if((c>='a' && c<='z') || (c>='0' && c<='9'))
s=6;
else if(s==5)
if((c>='a' && c<='z') || (c>='0' && c<='9'))
s=5;
else if(s==6)
if((c>='a' && c<='z') || (c>='0' && c<='9'))
s=6;
}
}
if(s==4)
printf("if condition");
if(s==3)
printf("Numbers");
if(s==6 || s==1 || s==2)
printf("Identifier");
if(s==5)
printf("Invalid String");