You are on page 1of 8

COMPILER

DESIGN
(lab file )

Submitted to:

Mrs.Sangita Rani

Developed By: VARUN SHARMA


CSE , 6th SEM

(Dronacharya College Of Engineering,Gr.Noida)

Roll no. 0823010052


/* (a)*bab(a+b)* */
#include<stdio.h>

#include<conio.h>

void main()

char s[25],symm;

int n,st=1,i;

clrscr();

printf("\n enter the string");

gets(s);

n=strlen(s);

printf("\n the size of string is: %d",n);

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)

printf("\n string accepteed");

else

printf("\n rejected");

getch();

}
/*
S -> cAd
A -> ab / a / A
*/

#include<stdio.h>

#include<conio.h>

#include<string.h>

int checkS(char[], int);

int checkA(char[]);

void main()

int length, flag = 0;

char string[10], sym;

clrscr();

gets(string);

length = strlen(string);

flag = checkS(string, length);

if (flag == 1)

printf("\n\nString accepted..");

else printf("\n\nString rejected..");

getch();
}

int checkS(char str[], int len)

int flag = 0;

if (str[0] == 'c')

flag = checkA(str);

if (flag == 1)

if (str[len - 1] == 'd')

return 1;

return 0;

int checkA(char str[])

if (str[1] == 'a' || str[2] == 'b')

return 1;

return 0;

}
/*Write a program to implement DFA that accept real numbers..*/
#include<stdio.h>

#include<conio.h>

void main()

int st=1, length, i;

char sym, num[20];

clrscr();

printf("Enter the real number : ");

gets(num);

length=strlen(num);

for (i=0;i<length;i++)

sym=num[i];

if (sym>='a' && sym<='z' || sym>='A' && sym<='Z' || num[length-1]=='.')


{

st=4;

break;

switch(st)

case 1:

st=2;

break;
case 2:

if (sym>='0' && sym<='9')

st=2;

else if (sym=='.')

st=3;

else if (sym=='-')

st=4;

break;

case 3:

if (sym=='.' || sym=='-')

st=4;

else if (sym<='0' && sym>='9')

st=3;

break;

default:

if (st==3 || st==2)

printf("\n\nString accepted..\nThe number is a real number..");

else printf("\nString rejected..\nThe number is not a real number");

getch();

}
COMPILER
DESIGN
(lab file )

Submitted to:

Mrs.Sangita Rani

Developed By: Vipin Kumar


CSE , 6th SEM

(Dronacharya College Of Engineering,Gr.Noida)

Roll no. 0823010055

You might also like