0% found this document useful (0 votes)
88 views4 pages

Week 2 Program CD

This C program implements a language recognizer for a deterministic finite automaton (DFA) that recognizes symbols between a-z and 0-9. The program takes in a string as input, uses a for loop to iterate through each character, and checks the current state to determine the next state based on the character. It then prints out the type of string based on the final state.

Uploaded by

Jaswanth Suggula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views4 pages

Week 2 Program CD

This C program implements a language recognizer for a deterministic finite automaton (DFA) that recognizes symbols between a-z and 0-9. The program takes in a string as input, uses a for loop to iterate through each character, and checks the current state to determine the next state based on the character. It then prints out the type of string based on the final state.

Uploaded by

Jaswanth Suggula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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

You might also like