Вы находитесь на странице: 1из 14

NOIDA INSTITUTE OF ENGG.

& TECHNOLOGY

COMPILER LAB
(ECS - 653)

Submitted to:

Mr. NISHANT KUMAR HIND

Submitted by:

NEETIKA GUPTA

0813310047 (CS 6 A)
PROGRAM 1

// A Program to tell whether a given String contains letters from a


to z or not.

#include<stdio.h>

#include<conio.h>

void main()

char *str;

int i,l,flag=0;

clrscr();

printf("Enter the string:");

scanf("%s",str);

l = strlen(str);

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

if(str[i]>=97&&str[i]<=122)

flag = 1;

break;

}
if (flag==1)

printf("String contains letters from a to z");

else

printf("String doesn't contain characters from a to z");

getch();

}
OUTPUT:
PROGRAM 2

// A Program to tell whether a given String contains a and b or


none of these.

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

char *str;

int i,l,flag=0;

clrscr();

printf("Enter a String:");

scanf("%s",str);

l=strlen(str);

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

if(str[i]>=96&&str[i]<=97)

flag = flag+1;

if(flag==l)

printf("String contains a and b");


else

printf("String doesn't contain a or b");

getch();

}
OUTPUT:
PROGRAM 3

// A Program to accept Strings that are in the form of (a/b)*abb.

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

char *str;

int i,l,flag=0;

clrscr();

printf("Enter the string:");

scanf("%s",str);

l=strlen(str);

if((str[l-1]==98)&&(str[l-2]==98)&&(str[l-3]==97))

flag=3;

for(i = 0;i<l-3;i++)

if (str[i] ==97 || str[i]==98)

flag = flag+1;

}
if(flag==l)

printf("String valid");

else

printf("String invalid");

getch();

}
OUTPUT:
PROGRAM 4

// A Program to recognise whether the given String is identifier,


Numeric constant or arithmetic operator.

#include<stdio.h>

#include<conio.h>

#include<string.h>

void main()

int i,l,flag=0,flag2=0;

char str[10];

clrscr();

printf("Enter a String:");

scanf("%s",str);

l=strlen(str);

if(str[0]>=65 && str[0]<=90 || str[0]>=97 && str[0]<=122)

flag=1;

for(i=1;i<l;i++)

if((str[i]>=65 && str[i]<=90) || (str[i]>=97 && str[i]<=122) ||


(str[i]>=48 && str[i]<=57))

flag=flag+1;

}
if(flag==l)

printf("String is identifier");

else if(str[0]=='+' || str[0]=='-' || str[0]=='*' || str[0]=='/')

flag=1;

if(str[1])

flag=0;

if(flag ==1)

printf("String is arithmetic operator");

else if(str[0]>=48 && str[0]<=57)

flag=1;

for(i=1;i<l;i++)

if(str[i]=='.')

flag2=flag2+1;

if(flag2<=1)

flag=flag+1;

else if(str[i]>=48 && str[i]<=57)


flag=flag+1;

if(flag==l && flag2<=1)

printf("String is a numeric constant");

if(flag!=l )

printf("String invalid");

getch();

}
OUTPUT:

Вам также может понравиться