WAP to perform Lexical Analysis.
Watch Video:
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<iostream.h>
void main()
{
String key[]={"int","float","char","double"};
char op[]={'+','-','*','/',','};
char exp[50],id[20];
int a,b,i,j,c;
clrscr();
cout<<"Enter expression:";
gets(exp);
a=strlen(exp);
b=strlen(key);
c=strlen(op);
for(i=0;i<b;i++)
{
for(j=0;j<a;j++)
{
if(key[i]==exp[j])
{
cout<<"key word:"<<key[i];
}
}
}
for(i=0;i<c;i++)
{
for(j=0;j<a;j++)
{
if(op[i]==exp[j])
{
cout<<"operator:"<<op[i];
}
}
}
for(i=0;i<a;i++)
{
if(exp[i]>96 & exp[i]<123)
{
cout<<"identifier:"<<exp[i];
}
}
getch();
}
Comments
Post a Comment