Search:

Submit Article

# Program of Deterministic Finite Automation (DFA) for identifier, real number with optional Integer and Fractional Part

Posted By: Easy Tutor     Category: C++ Programming     Views: 11078

## Code for Program of Deterministic Finite Automation (DFA) for identifier, real number with optional Integer and Fractional Part in C++ Programming

```
#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");
elseif(isalpha(nextSymbol))
strcpy(state,"ID");
elseif(nextSymbol=='.')
strcpy(state,"S1");
else
strcpy(state,"INVALID");
}
elseif(strcmp(state,"ID")==0){
if(isdigit(nextSymbol))
strcpy(state,"ID");
elseif(isalpha(nextSymbol))
strcpy(state,"ID");
else
strcpy(state,"INVALID");
}
elseif(strcmp(state,"INT")==0){
if(isdigit(nextSymbol))
strcpy(state,"INT");
elseif(nextSymbol=='.')
strcpy(state,"REAL");
else
strcpy(state,"INVALID");
}
elseif(strcmp(state,"REAL")==0){
if(isdigit(nextSymbol))
strcpy(state,"REAL");
else
strcpy(state,"INVALID");
}
elseif(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]```
Share:

 Easy Tutor author of Program of Deterministic Finite Automation (DFA) for identifier, real number with optional Integer and Fractional Part is from United States. Easy Tutor says Hello Friends,I am Free Lance Tutor, who helped student in completing their homework. I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] comI have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada. I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.Thanks,Happy Programming :) View All Articles

 Please enter your CommentComment should be atleast 30 Characters.Please put code inside [Code] your code [/Code]. No Comment Found, Be the First to post comment!