How to do Lexical analysis for c/c++ source file?


Joined
Jun 8, 2012
Messages
1
Reaction score
0
i have c++ code for Lexical analysis to get result of Expression/String as input and produces output as list of tokens that are: Total Identifier, Total Constants, Total Literals, Total Keywords, Total Operators, Total Delimiters, Invalid Tokens & Used Tokens.
So, i want to know same for a C/C++ file, then how to do?

Code:
void main()
    {
	clrscr();
	FILE *fp;
	char file_name[40],ch,mystring[4000];
	int size=0;
	printf("\n\n\tEnter File name: ");
	gets(file_name);
	fp=fopen(file_name,"r");
	if(fp==NULL)
	{
	 perror("Error while opening the file.\n");
	 exit(EXIT_FAILURE);
	}
	else
	{
	fseek(fp, 0, SEEK_END); // seek to end of file
	size = ftell(fp); // get current file pointer
	fseek(fp, 0, SEEK_SET);
	 while(( ch = fgetc(fp)) != EOF)
	  {
	   if(fgets(mystring , size , fp) != NULL )
	   {
	     //puts(mystring);
	     Lex_Ana oblex(mystring);//here how to pass whole characters of file??
	     oblex.Find_Lex();
	     oblex.Rem_Dup();
	     oblex.Sep_Val();
	     oblex.Display();
	   }
	 }
	}
	fclose(fp);
	getch();
    }
How to read all characters of file to string/char variable ??
Any help would be appreciated.
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top