Just a small logical question Can operands can be calculated by subtracting operators from words in a file. Just help me out. Thanking you, K K
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
posted
0
Just a small not-quite-sure-what-you-mean response Um, maybe. What do you mean exactly though? Do you have a file of operators and operands and want to somehow obtain a count of the operands?
No Sir. Basically i am supposed to calculate the count of operators and operands in a 'c' file. I could calculate the operators, but i need a small logic to calculate the operands. Please help me out. Thanking you, Sincerely,
Andrew Fischer
Greenhorn
Joined: Nov 18, 2002
Posts: 21
posted
0
Sounds like fun! If I understand your question, this isn't an easy assignment. You might want to find a good book on compiler design. Here are some hints. Use a StringTokenizer or a StreamTokenizer as part of your parser. You might want several of them to help parse out comments, statments and operators. Consider implementing a state machine to keep track of where you are.
For this to work correctly on real 'C' input files you've got to test against all sorts of legal C code. /* don't count comments i = j + 3 */ i = j++ + ++ i; //multiple line code i = VeryLongFunctionName() + j * k; if (a?b:c) a += (a==4)?b:c; [ November 25, 2002: Message edited by: Andrew Fischer ]
Andrew Fischer<br />SCJP
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
posted
0
What is a simple (yet somewhat thorough) example of the contents of the file that you must parse?