comp.lang.ada
 help / color / mirror / Atom feed
* C++ to Ada translator?
@ 2002-09-18 13:58 Ivan Paniagua
  2002-09-18 19:12 ` Hyman Rosen
  2002-09-18 19:50 ` Ira Baxter
  0 siblings, 2 replies; 16+ messages in thread
From: Ivan Paniagua @ 2002-09-18 13:58 UTC (permalink / raw)


I'm looking for a C++ to Ada translator.

Can anybody help me?

Thanks a lot.
Iv�n



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: C++ to Ada translator?
  2002-09-18 13:58 C++ to Ada translator? Ivan Paniagua
@ 2002-09-18 19:12 ` Hyman Rosen
  2002-09-18 20:14   ` Robert A Duff
  2002-09-19 14:29   ` Wes Groleau
  2002-09-18 19:50 ` Ira Baxter
  1 sibling, 2 replies; 16+ messages in thread
From: Hyman Rosen @ 2002-09-18 19:12 UTC (permalink / raw)


Ivan Paniagua wrote:
> I'm looking for a C++ to Ada translator.

This is essentially impossible to do in a way that would preserve
the character of the C++ code. That is, if you wanted to further
edit the translated code, or even just read it, you would find it
cryptic and difficult. (I speak here of C++ in its full generality.
Limited subsets of C++ which avoid its best features will translate
more readily.)

Edison Design Group sells a compiler which translates C++ into C,
so that might be a starting point. The same caveats apply.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: C++ to Ada translator?
  2002-09-18 13:58 C++ to Ada translator? Ivan Paniagua
  2002-09-18 19:12 ` Hyman Rosen
@ 2002-09-18 19:50 ` Ira Baxter
  2002-09-18 20:18   ` Hyman Rosen
  1 sibling, 1 reply; 16+ messages in thread
From: Ira Baxter @ 2002-09-18 19:50 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2181 bytes --]

We build custom translation tools as special cases of out
genearlized compiler technology used for analysis and enhancement
of large scale software systems.
See http://www.semdesigns.com/Products/Services/LegacyMigration.html.
We have Ada and C++ modules for our tools,
although we have not paired these before.

Another poster suggested that the "nature of the C++ code"
would be lost.   From a purist black and white point of view,
probably true.  From a practical point of view,
perhaps not.   C++ classes have decent analogs
in Ada95, and so the basic translation seems feasible.

Lots of icky details invariably show up.
I'd guess type casts in C++ would be gruesome
when converted to Ada, and pointer arithmetic
truly ugly.   Translating macros to something
sensible is hard, but there's less macro
stuff in C++ code than in C programs.
 Nasty assumptions about the nature
of "strings" (zero terminated in C++)
will also show up, probably as a String package
coded in Ada to simulate Ada semantics, etc.
The resulting code would be ... somewhat readable.
(We've had pretty reasonable results
with other langauge translations, such as JOVIAL to C,
where the basic language concepts are
quite similar.  We do better than you
might expect, copying comments, etc).

I'm sure this will start a flame fest over readability.
I'm not going to get into that, because the
result depends on what a translator
actually does.   The issue of the OP,
if he really needs translation, may be the driving
factor.   And I suspect the Ada community
would much rather see C++ programs
moving to Ada than the other way round,
even if the answer isn't ideal :-}

And these translators, even with our foundation tools
and available front-end language modules,
still aren't easy or cheap to produce.
Just a hell of a lot more practical,
if you insist on needing a translation,
that lots of other approaches.

--
Ira Baxter, Ph.D. CTO Semantic Designs
www.semdesigns.com  512-250-1018

"Ivan Paniagua" <paniaguaivan@hotmail.com> wrote in message
news:c560b18f.0209180558.58d495cc@posting.google.com...
> I'm looking for a C++ to Ada translator.
>
> Can anybody help me?
>
> Thanks a lot.
> Iv�n





^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: C++ to Ada translator?
  2002-09-18 19:12 ` Hyman Rosen
@ 2002-09-18 20:14   ` Robert A Duff
  2002-09-18 20:28     ` Hyman Rosen
  2002-09-19 14:29   ` Wes Groleau
  1 sibling, 1 reply; 16+ messages in thread
From: Robert A Duff @ 2002-09-18 20:14 UTC (permalink / raw)


Hyman Rosen <hyrosen@mail.com> writes:

> Ivan Paniagua wrote:
> > I'm looking for a C++ to Ada translator.
> 
> This is essentially impossible to do in a way that would preserve
> the character of the C++ code.

I don't think "preserve the character of the C++" is the goal.
The goal ought to be to produce "good" Ada code, where "good"
is measured with respect to what a good human Ada programmer
would write.  I agree that this is a difficult goal to achieve,
but probably not impossible.  Consider:

    int mumble; /* The value of mumble is always between 1 and 10. */

I would be surprised if a translation tool would generate the
corresponding Ada, which might be:

    type Mumble_Count is range 1..10;
    Mumble: Mumble_Count;

The tranlator would have to understand the comment (!), and would have
to guess whether it means "between 1 and 10 inclusive" versus exclusive,
a job that's hard even for a human.  Or maybe a fancy (inter-module)
flow analysis could determine the right bounds in many cases.  But how
would the tool know when to create new integer types?  And how would it
generate sensible names for them?  I can imagine some heuristics, but it
doesn't sound easy.

On the other hand, it is probably feasible (not trivial!) to do a
translation that doesn't *damage* readability too much with respect to
the original C++.

>... That is, if you wanted to further
> edit the translated code, or even just read it, you would find it
> cryptic and difficult. (I speak here of C++ in its full generality.
> Limited subsets of C++ which avoid its best features will translate
> more readily.)

- Bob



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: C++ to Ada translator?
  2002-09-18 19:50 ` Ira Baxter
@ 2002-09-18 20:18   ` Hyman Rosen
  2002-09-18 20:33     ` Robert A Duff
  2002-09-19 13:40     ` Ira Baxter
  0 siblings, 2 replies; 16+ messages in thread
From: Hyman Rosen @ 2002-09-18 20:18 UTC (permalink / raw)


Ira Baxter wrote:
> Lots of icky details invariably show up.

I meant templates and multiple inheritance when I talked
about losing the C++ nature in the translated code.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: C++ to Ada translator?
  2002-09-18 20:14   ` Robert A Duff
@ 2002-09-18 20:28     ` Hyman Rosen
  0 siblings, 0 replies; 16+ messages in thread
From: Hyman Rosen @ 2002-09-18 20:28 UTC (permalink / raw)


Robert A Duff wrote:
> I don't think "preserve the character of the C++" is the goal.
> The goal ought to be to produce "good" Ada code, where "good"
> is measured with respect to what a good human Ada programmer
> would write.

The problem is dealing with the popular constructs of one language
which are unavailable in the other. I already mentioned that I
think templates and multiple inheritance would be difficult to
translate appropriately into Ada. Going the other way, Ada code
frequently makes use of arrays whose declared size is computed
at runtime, including returning such arrays from functions. That
would be difficult to translate to C++ in a nature-preserving way.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: C++ to Ada translator?
  2002-09-18 20:18   ` Hyman Rosen
@ 2002-09-18 20:33     ` Robert A Duff
  2002-09-19 13:37       ` Hyman Rosen
  2002-09-19 13:40     ` Ira Baxter
  1 sibling, 1 reply; 16+ messages in thread
From: Robert A Duff @ 2002-09-18 20:33 UTC (permalink / raw)


Hyman Rosen <hyrosen@mail.com> writes:

> Ira Baxter wrote:
> > Lots of icky details invariably show up.
> 
> I meant templates and multiple inheritance when I talked
> about losing the C++ nature in the translated code.

Yes, these are rather difficult problems.

But I think the way to judge these things is to think about what a good
human programmer would write in Ada, in a case where a good C++
programmer chose to use, say, multiple inheritance.  It seems unfair to
expect *more* from a tool than one could expect from a human programmer.

The fact that multiple inheritance translates into something less
readable in Ada is not the fault of the translator -- it's caused by the
fact that Ada doesn't have multiple inheritance.  (This of course
presumes that you believe multiple inheritance makes for readable code,
at least in *some* cases.  Some would dispute that, but it's irrelevant
to my main point.)

- Bob



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: C++ to Ada translator?
  2002-09-18 20:33     ` Robert A Duff
@ 2002-09-19 13:37       ` Hyman Rosen
  0 siblings, 0 replies; 16+ messages in thread
From: Hyman Rosen @ 2002-09-19 13:37 UTC (permalink / raw)


Robert A Duff wrote:
> But I think the way to judge these things is to think about what a good
> human programmer would write in Ada

It's likely that the human would have done a completely different
design, playing to the strengths of the language. That's going to
be far beyond the abilities of a translator to deal with.

> It seems unfair to expect *more* from a tool than one could expect
 > from a human programmer.

I don't expect more from the tool. That's why I said that the
translation is going to be essentially impossible.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: C++ to Ada translator?
  2002-09-18 20:18   ` Hyman Rosen
  2002-09-18 20:33     ` Robert A Duff
@ 2002-09-19 13:40     ` Ira Baxter
  2002-09-19 14:38       ` Frank J. Lhota
  1 sibling, 1 reply; 16+ messages in thread
From: Ira Baxter @ 2002-09-19 13:40 UTC (permalink / raw)



"Hyman Rosen" <hyrosen@mail.com> wrote in message
news:1032380280.239075@master.nyc.kbcfp.com...
> Ira Baxter wrote:
> > Lots of icky details invariably show up.
>
> I meant templates and multiple inheritance when I talked
> about losing the C++ nature in the translated code.

Templates if used in their full generality would be pretty hard to
translate.
Templates used simply might translate to various kinds of generics.

Multiple inheritance can be faked with delegation.  Not pretty,
but workable.

The real question for the OP is how much of the zany parts
of C++ does he use, in what kind of volume?

If there's only a little bit of the odd stuff, then the "nature"
could be preserved probably reasonably.

I'll repeat the other comment: often such translations
are politically motivated (after all, there are perfectly
good, er, usable, C++ compilers, why switch?)
If that's really the case, the output doesn't have to be
wonderful.  It only has to be not terrible.
Yes, the downstream engineers suffer.  But that
always happens when politics intervenes.

--
Ira Baxter, Ph.D. CTO Semantic Designs
www.semdesigns.com  512-250-1018





^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: C++ to Ada translator?
  2002-09-18 19:12 ` Hyman Rosen
  2002-09-18 20:14   ` Robert A Duff
@ 2002-09-19 14:29   ` Wes Groleau
  2002-09-19 23:28     ` Ira Baxter
  1 sibling, 1 reply; 16+ messages in thread
From: Wes Groleau @ 2002-09-19 14:29 UTC (permalink / raw)



> > I'm looking for a C++ to Ada translator.
> 
> This is essentially impossible to do in a way that would preserve
> the character of the C++ code. That is, if you wanted to further
> edit the translated code, or even just read it, you would find it
> cryptic and difficult. (I speak here of C++ in its full generality.

I sometimes translate Spanish to English and vice versa.
I always use one or more auto-tranlating programs first.
The output is totally unacceptable (see sig for a _mild_
example) but it gets me to the final result faster than
if I did the first pass myself.

I expect similar from a C/C++/Java to Ada translator.

-- 
Wes Groleau
The Invisible Idiot
http://freepages.computers.rootsweb.com/~wgroleau/idiot.html



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: C++ to Ada translator?
  2002-09-19 13:40     ` Ira Baxter
@ 2002-09-19 14:38       ` Frank J. Lhota
  2002-09-19 15:15         ` OT: Russian to English translator? Frank J. Lhota
  0 siblings, 1 reply; 16+ messages in thread
From: Frank J. Lhota @ 2002-09-19 14:38 UTC (permalink / raw)


As one who has both developed and used automatic translation tools, let me
state from my experience that the output from automatic translation is
always pretty awful. Yes, the translates often compiles and links with few
hitches. Quite often, you can get the translated program to perform like the
original program. But the translated source code is an unmaintainable mess
that never takes advantage of the best features of the destination language,
and must jump through hoops in order to maintain the best features of its
source language.

All of the previous problems get worse as the level of the target language
gets higher. At the C++ / Ada 95 level, I would expect the translated code
to be atrocious.

The only reason for doing automatic translation is get a new version of the
program in a hurry. For any program that is to be maintained, the right
approach is to do a re-design of the program for the target language.






^ permalink raw reply	[flat|nested] 16+ messages in thread

* OT: Russian to English translator?
  2002-09-19 14:38       ` Frank J. Lhota
@ 2002-09-19 15:15         ` Frank J. Lhota
  2002-09-19 17:17           ` Wes Groleau
  0 siblings, 1 reply; 16+ messages in thread
From: Frank J. Lhota @ 2002-09-19 15:15 UTC (permalink / raw)


Back when the first automatic translation programs were developed for
natural languages (e.g. English, French, Spanish etc.), one of the tests
they tried was first doing an automatic English-to-Russian translation of a
common idiomatic phrase, then feed the output (sight unseen) into an
automatic Russian-to-English translator. The idea was to see how much
distortion results from the two translations.

When they tried this with the phrase

    "Out of sight, out of mind"

it came back

    "Blind idiot"

When they tried the English-to-Russian-to-English translation of the
Biblical passage

    "The spirit is strong, but the flesh is weak."

they got

    "The vodka is good, but the meat is rotten."





^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: OT: Russian to English translator?
  2002-09-19 15:15         ` OT: Russian to English translator? Frank J. Lhota
@ 2002-09-19 17:17           ` Wes Groleau
  0 siblings, 0 replies; 16+ messages in thread
From: Wes Groleau @ 2002-09-19 17:17 UTC (permalink / raw)



http://ourworld.compuserve.com/homepages/WJHutchins/Myths.htm
http://www.snopes.com/language/misxlate/machine.htm
http://language.home.sprynet.com/lingdex/limtran3.htm

-- 
Wes Groleau
The Invisible Idiot
http://freepages.computers.rootsweb.com/~wgroleau/idiot.html



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: C++ to Ada translator?
  2002-09-19 14:29   ` Wes Groleau
@ 2002-09-19 23:28     ` Ira Baxter
  2002-09-20 16:12       ` Wes Groleau
  0 siblings, 1 reply; 16+ messages in thread
From: Ira Baxter @ 2002-09-19 23:28 UTC (permalink / raw)


"Wes Groleau" <wesgroleau@despammed.com> wrote in message
news:3D89DF47.918EE3D1@despammed.com...
>
> > > I'm looking for a C++ to Ada translator.
> >
> > This is essentially impossible to do in a way that would preserve
> > the character of the C++ code. That is, if you wanted to further
> > edit the translated code, or even just read it, you would find it
> > cryptic and difficult. (I speak here of C++ in its full generality.
>
> I sometimes translate Spanish to English and vice versa.
> I always use one or more auto-tranlating programs first.
> The output is totally unacceptable (see sig for a _mild_
> example) but it gets me to the final result faster than
> if I did the first pass myself.
>
> I expect similar from a C/C++/Java to Ada translator.
>
> --
> Wes Groleau
> The Invisible Idiot
> http://freepages.computers.rootsweb.com/~wgroleau/idiot.html

Translating natural langauges is much harder than translating artificial
computer languages.
Natural languages contain ambiguity, inconsistency (maybe, maybe not),
incredible assumptions about context (this whole newsgroup thread),
broken sentences, mispelings, dialects, ... duh. (:-}).. no wonder they're
hard to translate.
And if you use that as a baseline, yes, I can see how you'd arrive at your
conclusion.

Artificial languages tend not to have most of this junk.  Individual
constructs
in one languge can often be simulated by a modest number of constructs
from another.    A trival "expansive" translation will then lead to code
bloat, but not "wrong answers".  We can argue about readable.

Coupling "naive" translation with post-optimization can strip away
much of the generality that the "number of constructs" bring,
by taking into account constraints imposed by the local code.
With that, you can get code that is arguably readable (as
opposed to unarguably unreadable).  See the example
in the slides found at
http://www.semdesigns.com/Products/Services/LegacyMigration.html.
(This is JOVIAL to C; in fact, if one looks closely, it will
be a bit more unreadable for a C purist because the customer
asked us to retain the JOVIAL type names as macros
for defining variables, to ease the education curve
of his existing JOVIAL team.  All those macro names
are trivially replaceably by their content, e.g,  "I" by "int".

I'll agree that the translated code is not a pretty or nice
as that written by an experienced engineer.   I've seen
much worse code from some so-called "professional" engineers.

--
Ira D. Baxter, Ph.D., CTO   512-250-1018
Semantic Designs, Inc.      www.semdesigns.com






^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: C++ to Ada translator?
  2002-09-19 23:28     ` Ira Baxter
@ 2002-09-20 16:12       ` Wes Groleau
  2002-09-21 15:54         ` Ira Baxter
  0 siblings, 1 reply; 16+ messages in thread
From: Wes Groleau @ 2002-09-20 16:12 UTC (permalink / raw)




Ira Baxter wrote:
> I'll agree that the translated code is not a pretty or nice
> as that written by an experienced engineer.   I've seen
> much worse code from some so-called "professional" engineers.

My point (and I think you suported it)
was that, although the output of either
kind of translator is not acceptable for
delivery either one can provide a valuable,
time-saving head start.

-- 
Wes Groleau
http://freepages.rootsweb.com/~wgroleau



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: C++ to Ada translator?
  2002-09-20 16:12       ` Wes Groleau
@ 2002-09-21 15:54         ` Ira Baxter
  0 siblings, 0 replies; 16+ messages in thread
From: Ira Baxter @ 2002-09-21 15:54 UTC (permalink / raw)


"Wes Groleau" <wesgroleau@despammed.com> wrote in message
news:3D8B48F2.3CAD7FA5@despammed.com...
>
> Ira Baxter wrote:
> > I'll agree that the translated code is not a pretty or nice
> > as that written by an experienced engineer.   I've seen
> > much worse code from some so-called "professional" engineers.
>
> My point (and I think you suported it)
> was that, although the output of either
> kind of translator is not acceptable for
> delivery either one can provide a valuable,
> time-saving head start.

For many translators I've seen, I'll agree with this.
I think, however, this has to do with the quality of translator.
And I will immodestly say that things are
changing for the better; our JOVIAL-to-C
customer seems to be happy enough.
He has no specific plans to do a major
cleanup of the translated code.

There are often major plans to modify
translated programs after the fact.
This is driven by the need to add functionality.
For the JOVIAL case, the original
code ran on 16 bit machines, and
they had hardly enough room to turn
around.  Running in a 32 bit C
environment, now they plan to add
lots of new functionality.

--
Ira D. Baxter, Ph.D., CTO   512-250-1018
Semantic Designs, Inc.      www.semdesigns.com





^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2002-09-21 15:54 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-18 13:58 C++ to Ada translator? Ivan Paniagua
2002-09-18 19:12 ` Hyman Rosen
2002-09-18 20:14   ` Robert A Duff
2002-09-18 20:28     ` Hyman Rosen
2002-09-19 14:29   ` Wes Groleau
2002-09-19 23:28     ` Ira Baxter
2002-09-20 16:12       ` Wes Groleau
2002-09-21 15:54         ` Ira Baxter
2002-09-18 19:50 ` Ira Baxter
2002-09-18 20:18   ` Hyman Rosen
2002-09-18 20:33     ` Robert A Duff
2002-09-19 13:37       ` Hyman Rosen
2002-09-19 13:40     ` Ira Baxter
2002-09-19 14:38       ` Frank J. Lhota
2002-09-19 15:15         ` OT: Russian to English translator? Frank J. Lhota
2002-09-19 17:17           ` Wes Groleau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox