#include <iostream.h> #include <conio.h> #include <string.h> #include <ctype.h> #include <process.h> void main() { char inputstr[50]; char nextSymbol,state[10]=\"START\"; int i; clrscr(); cout<<\"\\n*****Scanner (Lexical Analysis) *****\\n\"; cout<<\"Enter String : \"; cin.getline(inputstr,50,\'\\n\'); for(i=0;inputstr[i]!=NULL;i++) { nextSymbol = inputstr[i]; if(strcmp(state,\"INVALID\")==0) break; //initially state of inputstr is in start. if(strcmp(state,\"START\")==0){ if(isdigit(nextSymbol)) strcpy(state,\"INT\"); else if(isalpha(nextSymbol)) strcpy(state,\"ID\"); else if(nextSymbol==\'.\') strcpy(state,\"S1\"); else strcpy(state,\"INVALID\"); } else if(strcmp(state,\"ID\")==0){ if(isdigit(nextSymbol)) strcpy(state,\"ID\"); else if(isalpha(nextSymbol)) strcpy(state,\"ID\"); else strcpy(state,\"INVALID\"); } else if(strcmp(state,\"INT\")==0){ if(isdigit(nextSymbol)) strcpy(state,\"INT\"); else if(nextSymbol==\'.\') strcpy(state,\"REAL\"); else strcpy(state,\"INVALID\"); } else if(strcmp(state,\"REAL\")==0){ if(isdigit(nextSymbol)) strcpy(state,\"REAL\"); else strcpy(state,\"INVALID\"); } else if(strcmp(state,\"S1\")==0){ if(isdigit(nextSymbol)) strcpy(state,\"REAL\"); else strcpy(state,\"INVALID\"); } } if(strcmp(state,\"S1\")==0 || strcmp(state,\"INVALID\")==0) cout<<\"\\n\\nINVALID INPUT\"; else cout<<\"\\n\\nString State is : \"<<state; end: getch(); }[/Code]