Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) 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
Saloon Keeper
Posts: 3154
75
  • 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: 4568
9
  • 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).
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!