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

Discussion in 'C Programming' started by abhisheknayak9, Jun 8, 2012.

  1. abhisheknayak9

    abhisheknayak9

    Joined:
    Jun 8, 2012
    Messages:
    1
    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.
    abhisheknayak9, Jun 8, 2012
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. robert.muller2@gmail.com

    lexical analysis of python

    robert.muller2@gmail.com, Mar 11, 2009, in forum: Python
    Replies:
    3
    Views:
    667
    Paul McGuire
    Mar 11, 2009
  2. Angus Rodgers
    Replies:
    3
    Views:
    1,173
  3. ssubbarayan
    Replies:
    5
    Views:
    2,296
    Dave Hansen
    Nov 3, 2009
  4. Tintin

    Lexical file handles

    Tintin, Nov 6, 2004, in forum: Perl Misc
    Replies:
    4
    Views:
    219
    Brian McCauley
    Nov 6, 2004
  5. free
    Replies:
    1
    Views:
    306
    Lasse Reichstein Nielsen
    Mar 26, 2011
Loading...

Share This Page