Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

parsing a c program through java program

 
parni raghuvanshi
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2957
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic