1. RE: C to Eu translator
- Posted by Andy Serpa <ac at onehorseshy.com> Jan 03, 2004
- 413 views
Juergen Luethje wrote: > > > Hi all! > > No, there is no typo in the subject. I actually mean a C -> Eu > translator. Does someone intend to write such a program? > > As a layman and autodidact, I believe I learnt 80-90% of what I know > about progranmming, by studying source code written by other people. > Many -- especially professional -- code is written in C. Because I > cannot understand most of that code, I can't learn from it. > > I know some very simple things that can be done in an editor: > - replace "//" with "--" > - replace "==" with "=" > - replace "++" with "+=1" > - replace "&&" with "and" > - replace "||" with "or" > - replace "~" with "not_bits(" > - replace "printf(" with "printf(1, " > - replace word "const" with "constant" > - replace word "int" with "integer" > - (replace word "void" with "procedure") > > This is not much, and a translator would be much better of course. > Is an automatic translation actually possible? > Automatically translating a lower-level language (C) into a higher-level one (Euphoria) is an incredibly nasty problem, and probably intractable in some cases. You might be able to make a "literal" translation, but the resulting Euphoria code would look very much like the C code started out and not any easier to understand. I can't imagine an automatic translator that could make elegant, Euphoric code...
2. RE: C to Eu translator
- Posted by Andy Serpa <ac at onehorseshy.com> Jan 04, 2004
- 392 views
> > How about only translating things that are safe and clear to do, > e.g. replacing all symbols such as "//", "==", "++", "&&", "||", "~", > and other stuff, thereby letting the C constructs that are not available > in Euphoria such as goto, setjump, pointers, pass-by-reference, > structures, etc. alone? > > Then only the rest of the C program must be converted manually. Do you > think that there are many C programs, where this would save a > considerable amount of time, compared to converting the whole program > manually? Or is it not worth the effort, to write such a > "semi-translator"? > Well, what is the ultimate purpose? If you're doing something like the COM library or something where it is actually useful to mimic the C-style, then ok. But you were talking about trying to learn from the code, but not understanding what it is doing. If you have to do the important (hard) parts of the translation manually, you'll have to understand exactly what the C code is doing. And once you understand that, it is much easier to just rewrite a Euphoria version from scratch (not a translation, but a re-expression of the same ideas in Euphoria) now that you know the things that need to be accomplished. You can't translate C without understanding C, bottom line. And if someone else made an auto-translator for you, the resulting Euphoria code would be no easier to understand than the original code...
3. RE: C to Eu translator
- Posted by CoJaBo <cojabo at suscom.net> Jan 04, 2004
- 402 views
One problem with a C to EU translator is that each compiler uses slightly differant code, so complete automatic translation is near impossible. Also, Euphoria doesnt support some C code (pointers), so that part of code would need to be redone anyway. It would probably be better to simply rewrite ito from scrach as said below. Andy Serpa wrote: > > > > How about only translating things that are safe and clear to do, > > e.g. replacing all symbols such as "//", "==", "++", "&&", "||", "~", > > and other stuff, thereby letting the C constructs that are not available > > in Euphoria such as goto, setjump, pointers, pass-by-reference, > > structures, etc. alone? > > > > Then only the rest of the C program must be converted manually. Do you > > think that there are many C programs, where this would save a > > considerable amount of time, compared to converting the whole program > > manually? Or is it not worth the effort, to write such a > > "semi-translator"? > > > > Well, what is the ultimate purpose? If you're doing something like the > COM library or something where it is actually useful to mimic the > C-style, then ok. > > But you were talking about trying to learn from the code, but not > understanding what it is doing. If you have to do the important (hard) > parts of the translation manually, you'll have to understand exactly > what the C code is doing. And once you understand that, it is much > easier to just rewrite a Euphoria version from scratch (not a > translation, but a re-expression of the same ideas in Euphoria) now that > > you know the things that need to be accomplished. > > You can't translate C without understanding C, bottom line. And if > someone else made an auto-translator for you, the resulting Euphoria > code would be no easier to understand than the original code... >
4. RE: C to Eu translator
- Posted by Jerry Story <jstory at edmc.net> Jan 06, 2004
- 400 views
If the purpose of translating C to Euphoria is to understand the C source code, then maybe that purpose would be better accomplished by translating from C to English. http://www-2.cs.cmu.edu/~dst/DeCSS/Baccash/ Jerry Story