Try a search on Google with c2pas. One of the results leads to this http://www.programmersheav
I have not tested the mentioned utility, but you could give it a try!
Main Topics
Browse All TopicsI am looking for a good converter which translate "K&R C source code" to Pascal code
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Try a search on Google with c2pas. One of the results leads to this http://www.programmersheav
I have not tested the mentioned utility, but you could give it a try!
I saw one of these about 15 years back in a Borland magazine. You might look at Borland's support database.
It's about 8 hours of work to write and deobug the parser if you're already familiar with parsers, and another 8 hours of work to take the parsed tree and write it back out in C instead of Pascal and debug that.
Simple string substitution will handle most of it ...
Pascal C
begin {
end }
:= =
= ==
void procedure
int integer
double real
record struct
(* /*
{ /*
} */
*) */
and so on
What cannot be handled by simple string substitution is:
* pointer dereferencing (always an issue in C programming)
* "for" loop constructs
* places where C syntax call for different order than Pascal sequence.
The latter two pieces are trivial in the sense that the compiler will let you know about them. The former is a pain in the <insert descripter here>.
I would probably start by writing a set of general translator classes without implementations, then write the Pascal reader to build a parsed tree, and a C writer to print the parsed tree with C constructs. At this point it becomes trivial to reverse the process and write a two way translator.
If I were point starved, I might sit down and do this for the 500 points suggested by DeerBear because it sounds fun. I'd certainly be willing to help you build one by answering question sand offering a bit of advice just because it does sound fun, although you would have to do all of the work. I'm not starved for points, so increasing the point count won't get much more from me than advice on this one.
Initially, these are the classes you need. All are descended from TObject.
TTranslator
TCodeReader
TParsedTree
TCodeWriter
Once these general LANGUAGE INDEPENDENT classes are defined, you need to descend a TPascalCodeReader and a TCCodeWriter. The TParsedTree will be language independent so it does not need descendents.
The TTranslator should be and independent wrapper that has a TCodeReader, TParsedTree, and TCodeWriter component, so it should also need no descendents.
The TParsedTree is actually the most complex piece, although it is primarily a data object. It implements the recursive structure that is defines a "module" in the abstract sense in any programming language.
I would recommend downloading dUnit at thispoint in time from sourceforge, since you will need to get the parsed tree working before you can really get started on the specific code parsers or code writers.
kacor,
Please keep in mind that nobody is under accusation.
I replied simply because it was stated that I only provided a small correction and nothing else.
This was simply not true, and wanting correction.
As for the points, I think nobody of us is really concerned about earning them.
Speaking for me, my motivation is helping out other people and if I can get some points, the better :-)
I just replied because I felt DeNavigator message to be inaccurate to say the least.
Cheers,
Andrew
Business Accounts
Answer for Membership
by: DeerBearPosted on 2003-10-31 at 17:56:20ID: 9661699
Hi,
LOL!
That's definitely not a 20 points task :-)
Even 500 are a bit too low :-)
The best thing I can do for you is to try and introduce you to some
nasty tips&tricks to help you translating code.
This is a very small primer on the topic.
Let's see some procedure declarations:
void MyRoutine( Parameters );
This is a procedure. "Void" in C means it's "empty" thus no value.
void *MyRoutine( Parameters );
This is a function. "Void *" in C means "Pointer to empty", thus an
untyped pointer.
Generally speaking, when you see an * near an identifier, that is a
pointer.
char * = PChar = lpsz
The former is a very common equation to make. The last form is
especially used in Windows APIs.
char []
This is an array, but beware: arrays in C are the same as pointers,
thus you can treat a pointer as an array and viceversa.
Keep this in mind when translating code.
typedef
( void * )( int Function )
This is nasty. This is a function pointer, much like:
Type
TFunc = function : Integer;
Well, these are the usual pitfalls.
HTH,
Andrew