Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
35 views2 pages

DFA Construction for CS Students

The document describes a C program to construct a DFA for the regular expression (a+aa*b)*. The program includes a transition table, reads in a string, and uses the table to determine if the string is accepted by the DFA.

Uploaded by

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

DFA Construction for CS Students

The document describes a C program to construct a DFA for the regular expression (a+aa*b)*. The program includes a transition table, reads in a string, and uses the table to determine if the string is accepted by the DFA.

Uploaded by

Chiku Man
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Name: Krithika Shivkumar

RegNo : 21BCE1637

LAB 2: CONSTRUCTION OF DFA


AIM: C program to construct DFA for Regular Expression (a+aa*b)*

CODE:
#include<stdio.h>
#include<conio.h>
#include<strings.h>
void main() {
int table[2][2],i,j,l,status=0,success;
char input[100];
printf("To implementing DFA of language (a+aa*b)*
Enter Input String:”);
table[0][0]=1;
table[0][1]=-1;
table[1][0]=1;
table[1][1]=0;
scanf("%s",input);
l=strlen(input);
for (i=0;i<l;i++) {
if(input[i]!='a'&&input[i]!='b') {
printf("The entered Value is wrong");
getch();
exit(0);
}
if(input[i]=='a')
status=table[status][0]; else
status=table[status][1];
if(status==-1) {
printf("String not Accepted");
break;
}
}
if(i==l)
printf("String Accepted");
getch();
}

Sample Input:
Input: Enter Input String
baabaab
Output: String not Accepted.
Output:

Run 1:
To implementing DFA of language (a+aa*b)*
Enter Input String:cbsd
The entered Value is wrong.
Run 2:
To implementing DFA of language (a+aa*b)*
Enter Input String:abbababa
String not Accepted.
Run 3:
To implementing DFA of language (a+aa*b)*

Enter Input String:babbaab


String not Accepted.

You might also like