Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Computer GraphicsRSS Feeds

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

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

Based on Deterministic Finite Automation (DFA) for a REAL number with optional Integer and Fractional Part.

-> find for the given string entered is whether
i> Identifier
ii> Integer number
iii> Real number
it check all posibility and determine the validity of entered string.

DFA for Real number
-> L = Letter
-> D = Digit
-> . = Decimal Point


================================================
||--------||--------NEXT SYMBOL---------------||
|| STATE =======================================
||--------||---L-----||-----D-----||----.-----||
||============================================||
||-START--||--ID-----||---INT-----||----S1----||
||-ID-----||--ID-----||---ID------||--INVALID-||
||-INT----||-INVALID-||---INT-----||--REAL----||
||-REAL---||-INVALID-||---REAL----||--INVALID-||
||-S1-----||-INVALID-||---REAL----||--INVALID-||
================================================

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
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] com

I 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 Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!