0% found this document useful (0 votes)
50 views

Noida Institute of Engg. & Technology: Compiler Lab (ECS - 653)

The document contains 4 programs written in C language. Each program checks a different condition for a given input string: 1) Checks if the string contains letters from a to z. 2) Checks if the string contains letters a and b or none of them. 3) Checks if the string is in the form of (a/b)*abb. 4) Identifies if the string is an identifier, numeric constant or arithmetic operator. For each program, it takes input, applies conditions using loops and conditional statements, and prints the output.

Uploaded by

Shomya Jaiswal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Noida Institute of Engg. & Technology: Compiler Lab (ECS - 653)

The document contains 4 programs written in C language. Each program checks a different condition for a given input string: 1) Checks if the string contains letters from a to z. 2) Checks if the string contains letters a and b or none of them. 3) Checks if the string is in the form of (a/b)*abb. 4) Identifies if the string is an identifier, numeric constant or arithmetic operator. For each program, it takes input, applies conditions using loops and conditional statements, and prints the output.

Uploaded by

Shomya Jaiswal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 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:

You might also like