IntelliJ Java IDE
The moose likes Beginning Java and the fly likes operands Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "operands" Watch "operands" New topic
Author

operands

Kishore
Greenhorn

Joined: Aug 26, 2002
Posts: 10
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
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?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Kishore
Greenhorn

Joined: Aug 26, 2002
Posts: 10
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
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
What is a simple (yet somewhat thorough) example of the contents of the file that you must parse?
 
 
subject: operands
 
Threads others viewed
++ Sign - Order of Operation
passing arrays
chars using the + operator
++ -- Operators
Operators
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture