0% found this document useful (0 votes)
11 views2 pages

Manual 5

The document describes an experiment to create a C program that can validate operators. The program takes in an operator as input, uses a switch statement to check what operator was entered, and outputs the corresponding word for that operator. If the input is not a recognized operator, it outputs "Not an operator". The program is run by going to debug and pressing CTRL + F9. Sample input of "*" is given, with output of "Multiplication".

Uploaded by

dineshgawanden
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Manual 5

The document describes an experiment to create a C program that can validate operators. The program takes in an operator as input, uses a switch statement to check what operator was entered, and outputs the corresponding word for that operator. If the input is not a recognized operator, it outputs "Not an operator". The program is run by going to debug and pressing CTRL + F9. Sample input of "*" is given, with output of "Multiplication".

Uploaded by

dineshgawanden
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

EXPERIMENT-5

5.1 OBJECTIVE:

*Write a C program to simulate lexical analyzer for validating operators.

5.2 RESOURCE:

Turbo C++

5.3 PROGRAM LOGIC :


Read the given input.
If the given input matches with any operator symbol.
Then display in terms of words of the particular symbol.
Else print not a operator.
5.4 PROCEDURE:

Go to debug -> run or press CTRL + F9 to run the program.

5.5 PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
char s[5];
clrscr();
printf("\n Enter any operator:");
gets(s);
switch(s[0])
{
case'>': if(s[1]=='=')
printf("\n Greater than or equal");
else
printf("\n Greater than");
break;
case'<': if(s[1]=='=')
printf("\n Less than or equal");
else
printf("\nLess than");
break;
case'=': if(s[1]=='=')
printf("\nEqual to");
else
printf("\nAssignment");
break;
case'!': if(s[1]=='=')
printf("\nNot Equal");
else
printf("\n Bit Not");
break;
case'&': if(s[1]=='&')
printf("\nLogical AND");
else
printf("\n Bitwise AND");
break;
case'|': if(s[1]=='|')
printf("\nLogical OR");

9
else
printf("\nBitwise OR");
break;
case'+': printf("\n Addition");
break;
case'-': printf("\nSubstraction");
break;
case'*': printf("\nMultiplication");
break;
case'/': printf("\nDivision");
break;
case'%': printf("Modulus");
break;
default: printf("\n Not a operator");
}
getch();
}

5.6 INPUT & OUTPUT:

Input

Enter any operator: *

Output

Multiplication

10

You might also like