About

Kannur University btech CSE study materials, question papers, syllabus . . .

Saturday, June 8, 2013

S6 CSE COMPILER LAB : DFA TO ACCEPT IDENTIFIERS IN C LANGUAGE

/*  DFA TO ACCEPT IDENTIFIERS IN C LANGUAGE  */

        
#include<stdio.h>
#include<string.h>
void main()
{
        char id[20],s,p,q,r;
        int l,i;
        s=p;
        printf("Enter the input:");
        gets(id);
        if((s==p)&&(((65<=id[0])&&(id[0]<=90))||((97<=id[0])&&(id[0]<=122))||(id[0]==95)))
              s=q;
        else
              s=r;
        l=strlen(id);
        for(i=1;i<l;i++)
        {
            if((s==q)&&(((65<=id[i])&&(id[i]<=90))||((97<=id[i])&&(id[i]<=122))||(id[i]==95)||((48<=id[i])&&(id[i]<=58))))
                    s=q;
            else
                    s=r;
        }
        if(s==q)
             printf("Input is a Valid identifier\n");
        else
            printf("Input is Not an identifier\n");
}



OUTPUT


Enter the input:abc
Input is a Valid identifier

Enter the input:2abc
Input is Not an identifier

Enter the input:abc2
Input is a Valid identifier

Enter the input:123
Input is Not an identifier

Enter the input:ab_c
Input is a Valid identifier


0 comments:

Post a Comment