0% found this document useful (0 votes)
33 views

Deenbandhu Chhotu Ram University of Science and Technology

This document contains a program to construct a deterministic finite automaton (DFA) that accepts any string of 0s and 1s containing the substring "01". The program initializes the current state to 'a', then uses a switch statement to transition between states 'a', 'b', and 'c' based on the next character in the input string. It prints whether the string is accepted based on whether the final state reached is 'c'.

Uploaded by

Riya Yadav
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Deenbandhu Chhotu Ram University of Science and Technology

This document contains a program to construct a deterministic finite automaton (DFA) that accepts any string of 0s and 1s containing the substring "01". The program initializes the current state to 'a', then uses a switch statement to transition between states 'a', 'b', and 'c' based on the next character in the input string. It prints whether the string is accepted based on whether the final state reached is 'c'.

Uploaded by

Riya Yadav
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

DEENBANDHU CHHOTU RAM UNIVERSITY

OF SCIENCE AND TECHNOLOGY

COMPILER DESIGN FILE

SUBMITTED TO:- SUBMITTED TO:-


AMITA MALIK RIYA YADAV
CSE 3rd Year
15001001043
Program No.-1

AIM:Program to construct a DFA that accepts any string of {0,1}


and contains 01 as a substring.

#include<stdio.h>
#define max 100
void main()
{
char str[max],f='a';
int i;
printf("enter the string to be checked: ");
scanf("%s",str);
for(i=0;str[i]!=NULL;i++)
{
switch(f)
{
case 'a': if(str[i]=='0') f='b';
else if(str[i]=='1') f='a';
break;
case 'b': if(str[i]=='0') f='b';
else if(str[i]=='1') f='c';
break;
case 'c': if(str[i]=='0') f='c';
else if(str[i]=='1') f='c';
break;

}
}
if(f=='c')
printf("String is accepted as it reaches the final state that is %c.",f);
else
printf("String is not accepted as it reaches the state %c which is not a
final state.",f);
}
OUTPUT

You might also like