File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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

parsing a c program through java program

parni raghuvanshi

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

Joined: Aug 07, 2007
Posts: 2832
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

Joined: Apr 06, 2010
Posts: 4543

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).
I agree. Here's the link:
subject: parsing a c program through java program
It's not a secret anymore!