Compiler Design: (Lab File)
Compiler Design: (Lab File)
DESIGN
(lab file )
Submitted to:
Mrs.Sangita Rani
#include<conio.h>
void main()
char s[25],symm;
int n,st=1,i;
clrscr();
gets(s);
n=strlen(s);
for(i=0;i<n;i++)
symm=s[i];
switch(st)
case 1: if(symm=='a')
else st=2;
break;
case 2: if(symm=='a')
st=3;
else
st=5;
break;
case 3: if(symm=='a')
st=5;
else
st=4;
break;
case 4: break;
default: ;
if(st==4)
else
printf("\n rejected");
getch();
}
/*
S -> cAd
A -> ab / a / A
*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
int checkA(char[]);
void main()
clrscr();
gets(string);
length = strlen(string);
if (flag == 1)
printf("\n\nString accepted..");
getch();
}
int flag = 0;
if (str[0] == 'c')
flag = checkA(str);
if (flag == 1)
if (str[len - 1] == 'd')
return 1;
return 0;
return 1;
return 0;
}
/*Write a program to implement DFA that accept real numbers..*/
#include<stdio.h>
#include<conio.h>
void main()
clrscr();
gets(num);
length=strlen(num);
for (i=0;i<length;i++)
sym=num[i];
st=4;
break;
switch(st)
case 1:
st=2;
break;
case 2:
st=2;
else if (sym=='.')
st=3;
else if (sym=='-')
st=4;
break;
case 3:
if (sym=='.' || sym=='-')
st=4;
st=3;
break;
default:
if (st==3 || st==2)
getch();
}
COMPILER
DESIGN
(lab file )
Submitted to:
Mrs.Sangita Rani