C program to FIND OUT WHETHER A GIVEN STRING IS A IDENTIFIER OR NOT

#include<stdio.h>
#include<conio.h>

int isiden(char*); int second(char*); int third();

void main()
{
char *str;
int i = -1;

clrscr();
printf("\n\n\t\tEnter the desired String: ");
do
{
++i;
str[i] = getch();
if(str[i]!=10 && str[i]!=13)
printf("%c",str[i]);
if(str[i] == '\b')
{
--i;
printf(" \b");
}
}while(str[i] != 10 && str[i] != 13);

if(isident(str))
printf("\n\n\t\tThe given strig is an identifier");

else

getch();
}

printf("\n\n\t\tThe given string is not an identifier");


//To Check whether the given string is identifier or not
//This function acts like first stage of dfa int isident(char *str)
{
if((str[0]>='a' && str[0]<='z') || (str[0]>='A' && str[0]<='Z'))
{
return(second(str+1));
}

else

}

return 0;


//This function acts as second stage of dfa int second(char *str)
{
if((str[0]>='0' && str[0]<='9') || (str[0]>='a' && str[0]<='z') || (str[0]>='A' && str[0]<='Z'))
{
return(second(str+1));         //Implementing the loop from second stage to second stage
}

else

{
if(str[0] == 10 || str[0] == 13)
{
return(third(str));
}
else

 }
}

{
return 0;
}

1 comments:

Anonymous said...

Hi there,
I'm looking for a C code which takes a C file as a input and generate a table of different identifiers and their value.
e.g int num = 12;
char ch = "D";
output:
------------------
| Ident | Values|
------------------
| num | 12 |
| ch | D |
------------------

Post a Comment