wood burning stoves 2.0*
The moose likes Java in General and the fly likes parsing a c program through java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "parsing a c program through java program" Watch "parsing a c program through java program" New topic
Author

parsing a c program through java program

parni raghuvanshi
Greenhorn

Joined: Jun 21, 2011
Posts: 14
I have a small program written in c language,this program is written only in one line,i want this program to get read from my java program and make it in a structured way,i tried to read my file through character by character but unable to find a solution,i got this idea in my mind as when we download some c files from web,we always have a program that is written in one line only,i want this program to get convert in to structured format through java coding:This is my code where i tried to read my program.
[Added code tags - see UseCodeTags for more details]
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2332
    
  50
Please UseCodeTags when posting code.

I'm sorry but I can't understand what you are trying to do. Looking quickly at the code though I think your inner while loops should be if statements or the program will loop forever.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4425
    
    8

I've formatted it so it's a bit clearer what's going on.

Tony's right - those loops are never going to end. Once you're in the second while loop, the chances are that the third will never end because i never changes. But even if it does you're never going to break out of the outer loop - you have a while(true) and no break statement. That will only ever end if you get an exception.

Going back a step, though, what do you mean by "structured format"? What structure are you aiming for? And why are you trying to do it?

If you really want to write a C parser, be aware that's really not a simple job. It's not clear why you want to do that, but if that's what I was trying to do for some reason I'd be looking for a tool to do most of the work for me (see lexical analysers like JFlex).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: parsing a c program through java program