It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming C and C++ Forum

help for c++ code for recognizing a valid c++ identifier?

help for c++ code for recognizing a valid c++ identifier?

Postby deerlittle7 on Sat Jan 24, 2009 12:06 pm

What is the c++ code for recognizing a valid c++ identifier? there are some conditions to be followed:
1. it should start with a letter or an underscore
2. no two succeeding underscore.
3.the length of the identifier is from 1 to 8 characters only.
4. a single underscore inputted as an identifier is invalid.

here are the codes that i coded that are very much familiar with the problem. all i need is to combine them as one code that solves the problem above.:

/*THIS IS A SIMPLE CODE TO RECOGNIZE AN IDENTIFIER*/
#include <stdio.h>
#include <ctype.h>
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <math.h>
using namespace std;

void error();
/*THIS IS A SIMPLE CODE TO RECOGNIZE AN IDENTIFIER*/
char in;
void
error()
{

in=getchar();

if(isalpha(in))
in=getchar();
else
{error();}


while(isalpha(in)||isdigit(in))
in=getchar();

}
int
main ()
{


error();

{
getch();
}
}

;;;;;;;;;;;;;;
/*THIS IS A SIMPLE CODE that RECOGNIZE a REAL NUMBER*/
#include <ctype.h>
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <math.h>
using namespace std;
void error();
/*THIS IS A SIMPLE CODE that RECOGNIZE a REAL NUMBER*/
char in;
void
error()
{
in=getchar();
if(in=='+'||in=='-')
in=getchar();
while (isdigit(in))
in=getchar();
if(in=='.')
in=getchar();
else
error();
if(isdigit(in))
in=getchar();
else
error();
while(isdigit(in))
in=getchar();
cout<<"ok\n";
}
int
main ()
{


error();

{
getch();
}
}
;;;;;;;;;;;;;;;
/*THIS IS A SIMPLE CODE That implements a RECOGNIZER for AN IDENTIFIER*/
#include <ctype.h>
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <math.h>
using namespace std;


/*THIS IS A SIMPLE CODE That implements a RECOGNIZER for AN IDENTIFIER*/
void error();
int main()
{
int state;
char in;

state=1;
in=getchar();
while(isalpha(in)||isdigit(in))
{
switch(state)
{
case 1:if(isalpha(in))
state=2;
else
error();
break;
case 2:state=2;
break;
}
in=getchar();
}
return(state==2);
{
getch();
}
}
void
error()
{
getch();
}
deerlittle7
 
Posts: 1
Joined: Sat Jan 24, 2009 12:04 pm

Who is online

Users browsing this forum: No registered users and 0 guests