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?
How am passing the expression for analysis as below:
1 2 3 4 5 6 7 8 9 10 11 12 13 | void main() { clrscr(); char mstr[50]; printf("\n\n\tEnter String: ");// Here i want file as input gets(mstr); Lex_Ana oblex(mstr);//Here how to pass all lines to analysis oblex.Find_Lex(); oblex.Rem_Dup(); oblex.Sep_Val(); oblex.Display(); getch(); } |
i tried like below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | void main() { clrscr(); ifstream indata; char file_name[40], *mainStr,*ch; printf("\n\n\tEnter File name: "); gets(file_name); indata.open(file_name); if(indata==NULL) { perror("Error while opening the file.\n"); exit(EXIT_FAILURE); } else { while(!indata.eof()) { getline(indata,ch); strcat(mainStr,ch); } Lex_Ana oblex(mainStr); oblex.Find_Lex(); oblex.Rem_Dup(); oblex.Sep_Val(); oblex.Display(); indata.close(); } getch(); } |
this is not working..
Compiler: Turbo c++
Any help would be appreciated..
Please login to post questions.
This is the one stop educational site for all Electronic and Computer students. If you want to learn something new then we are here to help. We work on Microcontroller projects, Basic Electronics, Digital electronics, Computer projects and also in basic c/c++ programs.
#Home #Sitemap #Resources #Terms of Use
Copyright©2012 electrofriends.com All Rights Reserved
Contact:info@electrofriends.com