Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Miscellaneous ProblemsRSS Feeds

Identifer recognisition Integer Unsigned real number with optional integer part

Posted By: Bailey Evans     Category: C++ Programming     Views: 6150

Identifer recognisition
Integer
Unsigned real number with optional integer part

7 8 9
States l d .
0 start id int s1
1 id id id ---
2 int -- int s1
3 s1 -- real --
4 real -- real --

Code for Identifer recognisition Integer Unsigned real number with optional integer part in C++ Programming

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
int main()
{
    clrscr();
    int flag=0;
    char state = '0';
    char ch = NULL;
    char token[10]={NULL};
    char stt[6][4] = {    NULL,'7','8','9',
                '0','1','2','3',
                '1','1','1',NULL,
                '2',NULL,'2','3',
                '3',NULL,'4',NULL,
                '4',NULL,'4',NULL    };

    cout << "Enter Identifier, Integer or Real Number : ";
    cin >> token;
    for(int i=0; i < strlen(token); i++)
    {
        if (isalpha(token[i]))
            ch='7';
        elseif (isdigit(token[i]))
            ch = '8';
        elseif (token[i] == '.')
            ch = '9';
        for(int j=1; j<=3 && ch != stt[0][j]; j++);
        for(int k=1;k<=5 && state != stt[k][0];k++);
        state = stt[k][j];
            if(state == NULL)
            {
                cout << endl << "Invalid ....";
                flag=1;
                break;
            }
    }
    if (flag==0)
        cout<<"valide string";
    getch();
    return 0;
}
  
Share: 



Bailey Evans
Bailey Evans author of Identifer recognisition Integer Unsigned real number with optional integer part is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
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!