#include<stdio.h>
#include<process.h>
#include<string.h>
#include<conio.h>
#include<ctype.h>
int IsOperator(char);
void main()
{
clrscr();
char curstr[50],instr[50];
int count=0,counter=0,i=0,j,k,curstate;
char scantab[6][5]={ 1, 2, 3,-1,-1,
-1,-1,-1,-1,-1,
-1, 2, 2, 2,-1,
-1,-1, 3,-1, 4,
-1,-1, 5,-1,-1,
-1,-1, 5,-1,-1};
printf("Enter The String : ");
scanf("%[^\n]",instr);
// printf("%d",strlen(instr));while(instr[count]!='\0')
{
counter=0;
while(instr[count++]==' ')
{
}
count--;
while(instr[count]!=' ' && instr[count]!='\0')
{
curstr[counter++]=instr[count++];
// printf("%c",curstr[counter-1]);
}
curstr[counter]='\0';
// printf("%s",curstr);
j=0;
curstate=0;
// printf("%d",strlen(curstr));\ while(j<strlen(curstr))
{
if (IsOperator(curstr[j])>0)
k=0;
elseif (isalpha(curstr[j]))
k=1;
elseif (isdigit(curstr[j]))
k=2;
elseif(curstr[j]=='_')
k=3;
elseif(curstr[j]=='.')
k=4;
else
{
printf("Error In Input...");
getch();
exit;
}
curstate=scantab[curstate][k];
//printf("%d",curstate);
j++;
}
if (curstate==1)
printf(" op ");
elseif (curstate==2)
printf(" id ");
elseif (curstate==3)
printf(" int ");
elseif (curstate==5)
printf(" real ");
elseif(curstate==-1)
printf(" error ");
}
getch();
}
int IsOperator(char ch)
{
if (ch=='+')
return 1;
elseif (ch=='-')
return 2;
elseif (ch=='*')
return 3;
elseif (ch=='/')
return 4;
elseif (ch=='=')
return 5;
elsereturn 0;
}