Professional Documents
Culture Documents
Practical File OF Compiler Design
Practical File OF Compiler Design
Practical File OF Compiler Design
SUBMITTED
08/CSE/07
INDEX
s. no
1. 2.
Title
Design Automata to accept the String ending with 011 Design an Automata to accept the String having exactly one 0 over alphabet {0,1}
date
t. sign
3.
Design Automata to accept the String which does not contain 000 Design Automata to accept the String which starts with 01 or end with 01
4.
5.
6.
Design Automata to accept the String which has equal no. of 0s &1s
7.
Design Automata to accept the String which has even no. of 0s &1s Design Automata to reverse of the String
8.
9.
Program -- 1 Design Automata to accept the String ending with 011 #include<stdio.h> #include<conio.h> void main() { int i,n,a[1]; clrscr(); printf(Enter The Value of n : ); scanf(%d,&n); printf(Enter String); for(i=1;i<=n;i++) { scanf(%d,&a[i]); } If((a[n-2]==0)&&(a[n-1]==1)&&(a[n]==1)) { Printf(String Accepted); } else { printf(String Not Accepted); } getch(); }
Output of 1st program Enter The Value of n : 4 Enter the String 0 0 1 1 String Accepted Enter the String 0 1 1 1 String Not Accepted
Program -- 2 Design an Automata to accept the String having exactly one 0 over alphabet {0,1}
#include<stdio.h> #include<conio.h> void main() { int i, len,count=0; int a[20]; clrscr(); printf("Enter the length of the string : "); scanf("%d",&len); printf("Enter the string : \n"); for(i=0;i<len;i++) scanf("%d",&a[i]); { for(i=0;i<len;i++) if(a[i]==0) count=count+1; } if (count==1) printf("String Accepted"); else printf("Not Accepted"); getch(); }
Enter the length of the string : 5 Enter the string 0 1 1 1 1 String Accepted
Enter the length of the string : 4 Enter the string 1 0 0 1 String not Accepted
Program -- 3
Design Automata to accept the String which does not contain 000
#include<stdio.h> #include<conio.h> void main() { clrscr(); int a[10],i,n,count=0; printf("Enter the value of n : "); scanf("%d",&n); printf("Enter the array : \n"); for(i=1;i<=n;i++) scanf("%d",&a[i]); for(i=1;i<=n;i++) { if((a[i]==0)&&(a[i+1]==0)&&(a[i+2]==0)) count++; } if(count>0) printf("String is not accepted"); else printf("String is accepted"); getch(); }
Program -- 4 Design Automata to accept the String which starts with 01 or end with 01 #include<stdio.h> #include<conio.h> void main() { clrscr(); int a[1],i,n; printf("Enter the value of n : "); scanf("%d",&n); printf("Enter the array : \n"); for(i=1;i<=n;i++) scanf("%d",&a[i]); if(((a[0]==0)&&(a[1]==1))||((a[n-1]==0)&&(a[n]==1))) printf("String is accepted"); else printf("String is not accepted"); getch(); }
Program -- 5 Design Automata to accept the String 101 #include<stdio.h> #include<conio.h> void main() { clrscr(); int a[1],i,n; printf("Enter the value of n : "); scanf("%d",&n); if(n==3) { printf("Enter the string : \n"); for(i=1;i<=n;i++) scanf("%d",&a[i]); if((a[1]==1)&&(a[n-1]==0)&&(a[n]==1)) printf("String is accepted"); else printf("String is not accepted"); } else printf(The value of n must be 3); getch(); }
Program -- 6
Design Automata to accept the String which has equal no. of 0s &1s
#include<stdio.h> #include<conio.h> void main() { int a[3],i,n,c1=0,c2=0; clrscr(); printf("Enter the value of n: "); scanf("%d",&n); printf("Enter the string:\n"); for(i=1;i<=n;i++) scanf("%d",&a[i]); for(i=1;i<=n;i++) { if(a[i]==0) c1++; else if(a[i]==1) c2++; } if(c1==c2) printf("String is accepted"); else printf("String is not accepted"); getch(); }
Program -- 7
Design Automata to accept the String which has even no. of 0s &1s
#include<stdio.h> #include<conio.h> void main() { int a[3],i,n,c1=0,c2=0; clrscr(); { printf("Enter the value of n: "); scanf("%d",&n); printf("Enter the string:\n"); for(i=1;i<=n;i++) scanf("%d",&a[i]); for(i=1;i<=n;i++) { if(a[i]==0) c1++; else if(a[i]==1) c2++; } if((c1%2==0)&&(c2%2==0)) printf("String is accepted"); else printf("String is not accepted"); } getch(); }
Program 8 Design Automata to reverse of the String #include<stdio.h> #include<conio.h> void main() { int a[3],i,n; clrscr(); { printf("Enter the value of n: "); scanf("%d",&n); printf("Enter the string:\n"); for(i=1;i<=n;i++) scanf("%d",&a[i]); printf("\nThe reverse of the string:"); for(i=n;i>=1;i--) { printf("\n%d",a[i]); } } getch(); }
Program -- 9 Design Automata to the String has multiple three of 0s #include<stdio.h> #include<conio.h> void main() { int a[3],i,n,c=0; clrscr(); { printf("Enter the value of n: "); scanf("%d",&n); printf("\nEnter the string:\n"); for(i=1;i<=n;i++) scanf("%d",&a[i]); for(i=1;i<=n;i++) { if(a[i]==0) c++; } if(c%3==0) printf("String is accepted"); else printf("String is not accepted"); } getch(); }