LEXICAL ANALYZER - OPERATOR

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

ALGORITHM:
Step 1: Read the given input.
Step 2: If the given input matches with any operator symbol.
Step 3: Then display in terms of words of the particular symbol.
Step 4: Else print not a operator.

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");
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();
}

OUTPUT:

Enter any operator: *
Multiplication
Enter any operator: +
Addition

RESULT:
Thus the  program  for  operator of  lexical analyzer is  executed and verified.