comp.lang.ada
 help / color / mirror / Atom feed
* Pascal to Ada translator/ aflex,ayacc GNAT ports
@ 1996-11-27  0:00 Martin C. Carlisle
  1996-11-27  0:00 ` Michael Feldman
  0 siblings, 1 reply; 15+ messages in thread
From: Martin C. Carlisle @ 1996-11-27  0:00 UTC (permalink / raw)



I have just completed a preliminary version of a pascal to ada
translator (some features like "with" aren't handled) using aflex
and ayacc.  It is publicly available at:

ftp://ftp.usafa.af.mil/pub/dfcs/carlisle

Also at the same site are ports of the source of aflex and ayacc so
they will compile directly under GNAT and generate GNAT compatible
output files.

Direct comments to :  mcc@cs.usafa.af.mil

--Martin C. Carlisle
--Department of Computer Science, US Air Force Academy

DISCLAIMER: This posting does not necessarily reflect the opinions of
the US Air Force Academy, the Air Force, or the US Govt.





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

* Re: Pascal to Ada translator/ aflex,ayacc GNAT ports
  1996-11-27  0:00 Pascal to Ada translator/ aflex,ayacc GNAT ports Martin C. Carlisle
@ 1996-11-27  0:00 ` Michael Feldman
  1996-11-28  0:00   ` steved
  0 siblings, 1 reply; 15+ messages in thread
From: Michael Feldman @ 1996-11-27  0:00 UTC (permalink / raw)



In article <57htn2$jm8@cnn.Princeton.EDU>,
Martin C. Carlisle <mcc@tyrolia.cs.princeton.edu> wrote:
>I have just completed a preliminary version of a pascal to ada
>translator (some features like "with" aren't handled) using aflex
>and ayacc.  It is publicly available at:

This looks like it has a lot of real potential as a valuable tool.
What _does_ it do with a Pascal "with"? Maybe it should mark such
lines in an obvious way for hand-tweaking?

Expanding a Pascal "with" into full field-selection looks intuitively 
similar to the "use" expansion some Ada tools can do.

In any event, good luck with this! Keep up the good work!

Mike Feldman




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

* Re: Pascal to Ada translator/ aflex,ayacc GNAT ports
  1996-11-27  0:00 ` Michael Feldman
@ 1996-11-28  0:00   ` steved
  1996-11-29  0:00     ` Robert Dewar
  0 siblings, 1 reply; 15+ messages in thread
From: steved @ 1996-11-28  0:00 UTC (permalink / raw)



In Michael Feldman writes:
>In article <57htn2$jm8@cnn.Princeton.EDU>,
>Martin C. Carlisle <mcc@tyrolia.cs.princeton.edu> wrote:
>>I have just completed a preliminary version of a pascal to ada
>>translator (some features like "with" aren't handled) using aflex
>>and ayacc.  It is publicly available at:
>
>This looks like it has a lot of real potential as a valuable tool.
>What _does_ it do with a Pascal "with"? Maybe it should mark such
>lines in an obvious way for hand-tweaking?
>
>Expanding a Pascal "with" into full field-selection looks intuitively 
>similar to the "use" expansion some Ada tools can do.
>
My $0.02 worth:

In working with a Pascal to Ada translator from Wiljan Derks.  I believe I have
learned a few things about what makes a for a good translation.  One of which
is to make the translated code look very much like the original code.

Wiljan originally had the code explicitly qualify all references to fields that
were brought into scope using the "with".  I found the generated code to be
hard to read, so I modified the generation to generate the following translation:

with complex.expression[ witharrayindex ] do
  begin
    field1 := value;
  end;

.. maps to ...

declare
  w_0 : aRecordType renames complex.expression[ witharrayindex ];
begin
  w_0.field1 := value;
end;

Which makes the translated code look very much like the original IMHO.

>
>In any event, good luck with this! Keep up the good work!
>
>Mike Feldman





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

* Re: Pascal to Ada translator/ aflex,ayacc GNAT ports
  1996-11-28  0:00   ` steved
@ 1996-11-29  0:00     ` Robert Dewar
  1996-11-29  0:00       ` wiljan
  1996-11-29  0:00       ` Larry Kilgallen
  0 siblings, 2 replies; 15+ messages in thread
From: Robert Dewar @ 1996-11-29  0:00 UTC (permalink / raw)



In discussing Pascal to Ada translation:

.. maps to ...

declare
  w_0 : aRecordType renames complex.expression[ witharrayindex ];
begin
  w_0.field1 := value;
end;



Yes, this is the obvious appropraite translation in this case, however, I
would say that the general goal of making the translated code look as much
like the original Pascal as possible is quite wrong, and illustrates what
is wrong with these translators. If you want Pascal-in-Ada what's the point,
you might as well write in Pascal. The only point in translating from Pascal
to Ada is to take advantage of the greater expressive power (e.g. generics)
available in Ada.





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

* Re: Pascal to Ada translator/ aflex,ayacc GNAT ports
  1996-11-29  0:00     ` Robert Dewar
  1996-11-29  0:00       ` wiljan
@ 1996-11-29  0:00       ` Larry Kilgallen
  1 sibling, 0 replies; 15+ messages in thread
From: Larry Kilgallen @ 1996-11-29  0:00 UTC (permalink / raw)



In article <dewar.849267826@merv>, dewar@merv.cs.nyu.edu (Robert Dewar) writes:
> In discussing Pascal to Ada translation:
> 
> .. maps to ...
> 
> declare
>   w_0 : aRecordType renames complex.expression[ witharrayindex ];
> begin
>   w_0.field1 := value;
> end;
> 
> Yes, this is the obvious appropraite translation in this case, however, I
> would say that the general goal of making the translated code look as much
> like the original Pascal as possible is quite wrong, and illustrates what
> is wrong with these translators. If you want Pascal-in-Ada what's the point,
> you might as well write in Pascal. The only point in translating from Pascal
> to Ada is to take advantage of the greater expressive power (e.g. generics)
> available in Ada.

Although people should always have warnings about using Language A 
as a vehicle for writing in the style of Language B, making an
informed decision in light of that warning should be sufficient.

It could be, for instance, that this is an excellent time to switch to
Ada (political climate, etc.) but a lousy time to rewrite large chunks
of code.  A mechanical translator is not going to write "good Ada",
so the priorities should be:

	1) Having it write code no less correct than the Pascal

	2) Having it write code which humans can change to be "good Ada"

I think the second purpose is well served by something which follows
the style of the Pascal, presuming those who will make subsequent
changes are accustomed to maintaining the Pascal version and thus
will feel "at home".

To keep people from following on and using Ada to write Pascal, the
translator could insert elements such as:

	-- The following emulation of a Pascal WITH statement
	-- was produced by a mechanical translator as a temporary
	-- expedient until a more robust approach can be implemented
	-- by  our skilled programming staff.

with the exact text to be generated controlled by the project manager
in accordance with local sensibilities.

Larry Kilgallen




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

* Re: Pascal to Ada translator/ aflex,ayacc GNAT ports
  1996-11-29  0:00     ` Robert Dewar
@ 1996-11-29  0:00       ` wiljan
  1996-11-29  0:00         ` Robert Dewar
  1996-11-29  0:00       ` Larry Kilgallen
  1 sibling, 1 reply; 15+ messages in thread
From: wiljan @ 1996-11-29  0:00 UTC (permalink / raw)



Robert Dewar <dewar@merv.cs.nyu.edu> wrote in article
<dewar.849267826@merv>...
> Yes, this is the obvious appropraite translation in this case, however, I
> would say that the general goal of making the translated code look as
much
> like the original Pascal as possible is quite wrong, and illustrates what
> is wrong with these translators. If you want Pascal-in-Ada what's the
point,
> you might as well write in Pascal. The only point in translating from
Pascal
> to Ada is to take advantage of the greater expressive power (e.g.
generics)
> available in Ada.
I do not agree that this is the obvious translation.
It depends on how the code is original written. In many cases you can
of cause give an abvious translation to Ada but it depends from case to
case.
I think that such a translation process is of same difficulty for a
computer as
translating natural languages.
The goal for my pascal to Ada translator was:
     * Have the Ada code close the original Pascal code.
     * Do not add to many constructs that gets you lost in the generated
code.
     * Try to generate directly compilable Ada code, thus generate
       working Ada code from working pascal code.
I things these goals where very well reached. That means for MY code.
Anyway the translator certainly gave me a BIG advantage over rewriting all
the
code. In relative short time I had my code working again in Ada.
AND what is very important to me: WITH the same bugs -> no Bugs where
added.
Note that my translator is different from the program mentioned in the
original post. It is a real compiler that first reads all the pascal
modules.
It then analyses them and rearanges things to get reasonable Ada.

For those interested the translator was written for EPASCAL, a pascal+++
dialect from digital used in the VAXELN toolkit.

I know Steve has been very busy with it. I think he also found it a
valuable tool.
Any remarks Steve ??

Wiljan





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

* Re: Pascal to Ada translator/ aflex,ayacc GNAT ports
  1996-11-29  0:00       ` wiljan
@ 1996-11-29  0:00         ` Robert Dewar
  1996-11-30  0:00           ` wiljan
  1996-12-02  0:00           ` Laurent Gasser
  0 siblings, 2 replies; 15+ messages in thread
From: Robert Dewar @ 1996-11-29  0:00 UTC (permalink / raw)



Wiljan says

"I do not agree that this is the obvious translation.
It depends on how the code is original written. In many cases you can
of cause give an abvious translation to Ada but it depends from case to
case."


I am confused, you seem to be talking in generalities (which are in fact
reasonable), but you don't seem to talk to this specific case. Can you
show an example where you think it is inappropriate to translate the
Pascal "with" into an Ada renaming?

Seems to me that the Pascal WITH is *exactly* analogous to the Ada renaming,
with a little less to write, but with less flexibility.





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

* Re: Pascal to Ada translator/ aflex,ayacc GNAT ports
  1996-11-30  0:00           ` wiljan
@ 1996-11-30  0:00             ` Robert Dewar
  1996-12-01  0:00               ` wiljan
  0 siblings, 1 reply; 15+ messages in thread
From: Robert Dewar @ 1996-11-30  0:00 UTC (permalink / raw)



Wiljan says

"I think that when one has:
    type rec=record a,b:integer end;
    var x:rec;
    ....
    with x do a:=3;
is best translated to
    x.a:=3;
With a rename it whould look like:
    x1:rec renames x;
    x1.a:=3;
Note that when translating to an Ada renaming one must add extra names
which also does not attribute to clear code."


Yes that is certainly reasonable. Of course a translator that is this clever
in terms of making aesthetic judgments about best translations is an
unlikely beast. Sure, this one case could be handled, but to be this 
accurate in producing "best translations" throughout -- that's hard.

Note that in this case, the renames translation is indeed clunky, but
then the original Pascal is also clunky, I certainly never saw any
Pascal where someone would use a with for a single statement.

Obviously the appropriate Pascal in this case is:

   x.a := 3;

Just how much effort do you expect an automatic translator to spend in
taking junk badly written Pascal and turning it into nice Ada?





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

* Re: Pascal to Ada translator/ aflex,ayacc GNAT ports
  1996-11-29  0:00         ` Robert Dewar
@ 1996-11-30  0:00           ` wiljan
  1996-11-30  0:00             ` Robert Dewar
  1996-12-02  0:00           ` Laurent Gasser
  1 sibling, 1 reply; 15+ messages in thread
From: wiljan @ 1996-11-30  0:00 UTC (permalink / raw)



Robert Dewar <dewar@merv.cs.nyu.edu> wrote in article
<dewar.849318953@merv>...
> I am confused, you seem to be talking in generalities (which are in fact
> reasonable), but you don't seem to talk to this specific case. Can you
> show an example where you think it is inappropriate to translate the
> Pascal "with" into an Ada renaming?
I think that when one has:
    type rec=record a,b:integer end;
    var x:rec;
    ....
    with x do a:=3;
is best translated to
    x.a:=3;
With a rename it whould look like:
    x1:rec renames x;
    x1.a:=3;
Note that when translating to an Ada renaming one must add extra names
which also does not attribute to clear code.

Wiljan





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

* Re: Pascal to Ada translator/ aflex,ayacc GNAT ports
  1996-11-30  0:00             ` Robert Dewar
@ 1996-12-01  0:00               ` wiljan
  1996-12-01  0:00                 ` Michael Feldman
  1996-12-01  0:00                 ` Robert Dewar
  0 siblings, 2 replies; 15+ messages in thread
From: wiljan @ 1996-12-01  0:00 UTC (permalink / raw)





Robert Dewar <dewar@merv.cs.nyu.edu> wrote in article
<dewar.849367775@merv>...
> Just how much effort do you expect an automatic translator to spend in
> taking junk badly written Pascal and turning it into nice Ada?
I do not think it is even possible to build such a program in general.
If one could, you can probably prove that one can also translate
badly written C program into good Ada programs.

My point is that every translator has certain trade offs. That was also
the case with my pascal to Ada translator.
For me there had be a point at which stop working on the translator.
I had the trade off between:
    * putting more work in the translator making it work better
    * Starting with the output of the translator.
My intermediate goal was the translator, but my final goal was to
have my EPASCAL code running in Ada on Windows NT.

Wiljan




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

* Re: Pascal to Ada translator/ aflex,ayacc GNAT ports
  1996-12-01  0:00               ` wiljan
  1996-12-01  0:00                 ` Michael Feldman
@ 1996-12-01  0:00                 ` Robert Dewar
  1 sibling, 0 replies; 15+ messages in thread
From: Robert Dewar @ 1996-12-01  0:00 UTC (permalink / raw)



wiljan said

"My point is that every translator has certain trade offs. That was also
the case with my pascal to Ada translator."

Sure, that's perfectly reasonable, but in that context, always using the
renaming as the translation of with seems the right choice.





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

* Re: Pascal to Ada translator/ aflex,ayacc GNAT ports
  1996-12-01  0:00               ` wiljan
@ 1996-12-01  0:00                 ` Michael Feldman
  1996-12-01  0:00                 ` Robert Dewar
  1 sibling, 0 replies; 15+ messages in thread
From: Michael Feldman @ 1996-12-01  0:00 UTC (permalink / raw)



In article <01bbdf5d$da19d820$33208b82@wd>,
wiljan <W.Derks@nl.cis.philips.com> wrote:

>My intermediate goal was the translator, but my final goal was to
>have my EPASCAL code running in Ada on Windows NT.
>
>Wiljan

I agree with Wiljan here - a partial translation - to be completed
and cleaned up by hand - is better than none at all. I've done a lot
of ad-hoc partial translations of Pascal and Modula-2 code, mostly using
very simple stuff written in SNOBOL. This code has all been significantly
improved by hand, but the job was _much_ easier than hand-coding from
scratch.

As in so many other things, I think moderation is a virtue here.

Mike Feldman




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

* Re: Pascal to Ada translator/ aflex,ayacc GNAT ports
  1996-11-29  0:00         ` Robert Dewar
  1996-11-30  0:00           ` wiljan
@ 1996-12-02  0:00           ` Laurent Gasser
  1996-12-02  0:00             ` Jacques Rouillard
  1996-12-02  0:00             ` Larry Kilgallen
  1 sibling, 2 replies; 15+ messages in thread
From: Laurent Gasser @ 1996-12-02  0:00 UTC (permalink / raw)



In article <dewar.849318953@merv>, dewar@merv.cs.nyu.edu (Robert Dewar) writes:
> Wiljan says
> 
> "I do not agree that this is the obvious translation.
> It depends on how the code is original written. In many cases you can
> of cause give an abvious translation to Ada but it depends from case to
> case."
> 
> 
> I am confused, you seem to be talking in generalities (which are in fact
> reasonable), but you don't seem to talk to this specific case. Can you
> show an example where you think it is inappropriate to translate the
> Pascal "with" into an Ada renaming?
> 
> Seems to me that the Pascal WITH is *exactly* analogous to the Ada renaming,
> with a little less to write, but with less flexibility.
> 


In the MacOs, you often have structures like a Rect which are

Rect = record
  top, bottom, right, left: integer;
end;

You are typically using WITH when you are calculating with them.  The intent
is to make the source easier to read, and only that.  (Well, compiler might
write more efficent code as well.)

my_rect : Rect;

with my_rect do begin  { may have a scope of many lines }
  top    := top - top_margin;
  right  := left + (3*(bottom - top)) div 4;
  bottom := bottom - bot_margin;
end;

In this case, the proposed solution would not help much.  It would be 
preferable to work as in C: no local block, and all the fields are written
in full.  An extra local variable cannot do any better.

my_rect.top    := my_rect.top - top_margin;
my_rect.right  := my_rect.left + (3*(my_rect.bottom - my_rect.top)) div 4;
my_rect.bottom := my_rect.bottom - bot_margin;

This is the case every time the structured type is directly the type
of the variable at work.  No array of, pointer to, or field in a record 
of the structured type.  The Ada renaming is quite effective when the
structured type is deeply nested in the variable call.

-- 
Laurent Gasser (lga@sma.ch)
Computers do not solve problems, they execute solutions.






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

* Re: Pascal to Ada translator/ aflex,ayacc GNAT ports
  1996-12-02  0:00           ` Laurent Gasser
@ 1996-12-02  0:00             ` Jacques Rouillard
  1996-12-02  0:00             ` Larry Kilgallen
  1 sibling, 0 replies; 15+ messages in thread
From: Jacques Rouillard @ 1996-12-02  0:00 UTC (permalink / raw)



In article <57uki4INNkae@maz4.sma.ch>, lga@sma.ch wrote:

> In article <dewar.849318953@merv>, dewar@merv.cs.nyu.edu (Robert Dewar)
writes:
> > Wiljan says

> > Seems to me that the Pascal WITH is *exactly* analogous to the Ada renaming,
> > with a little less to write, but with less flexibility.
> > 
> 
> 
> In the MacOs, you often have structures like a Rect which are
> 
> Rect = record
>   top, bottom, right, left: integer;
> end;
> 
> You are typically using WITH when you are calculating with them.  The intent
> is to make the source easier to read, and only that.  (Well, compiler might
> write more efficent code as well.)
> 
> my_rect : Rect;
> 
> with my_rect do begin  { may have a scope of many lines }
>   top    := top - top_margin;
>   right  := left + (3*(bottom - top)) div 4;
>   bottom := bottom - bot_margin;
> end;
> 
> In this case, the proposed solution would not help much.  It would be 
> preferable to work as in C: no local block, and all the fields are written
> in full.  An extra local variable cannot do any better.
> 
> my_rect.top    := my_rect.top - top_margin;
> my_rect.right  := my_rect.left + (3*(my_rect.bottom - my_rect.top)) div 4;
> my_rect.bottom := my_rect.bottom - bot_margin;
> 
> This is the case every time the structured type is directly the type
> of the variable at work.  No array of, pointer to, or field in a record 
> of the structured type.  The Ada renaming is quite effective when the
> structured type is deeply nested in the variable call.

Problem: the withed thing can be returned by a fonction, that may have
side effects.

 function my_rect : Rect;
 ....
 
 with my_rect do begin         (*called only once*)
   top    := top - top_margin;
   right  := left + (3*(bottom - top)) div 4;
   bottom := bottom - bot_margin;
 end;
  

 my_rect.top    := my_rect.top - top_margin;
 my_rect.right  := my_rect.left + (3*(my_rect.bottom - my_rect.top)) div 4;
 my_rect.bottom := my_rect.bottom - bot_margin;

(*called 3 times*)

The best approximation remains the 'renames'.

--
Jacques Rouillard t33(0)491054342 f33(0)491700659 e rouillard@acm.org
USA http://vhdl.org/~rouillard   EU http://ismea.imt-mrs.fr/~rouillar
---------------------- Va savoir, Charles --------------------------
Ne reponds pas au fou selon    |Reponds au fou selon sa demence
 sa demence, que tu ne l'egales| de peur qu'il ne soit sage
 toi aussi [Prov 26:4]         | a ses yeux [Prov 26:5]
--------------------------------------------------------------------




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

* Re: Pascal to Ada translator/ aflex,ayacc GNAT ports
  1996-12-02  0:00           ` Laurent Gasser
  1996-12-02  0:00             ` Jacques Rouillard
@ 1996-12-02  0:00             ` Larry Kilgallen
  1 sibling, 0 replies; 15+ messages in thread
From: Larry Kilgallen @ 1996-12-02  0:00 UTC (permalink / raw)



In article <57uki4INNkae@maz4.sma.ch>, lga@sma.ch (Laurent Gasser) writes:

> In the MacOs, you often have structures like a Rect which are
> 
> Rect = record
>   top, bottom, right, left: integer;
> end;
> 
> You are typically using WITH when you are calculating with them.  The intent
> is to make the source easier to read, and only that.  (Well, compiler might
> write more efficent code as well.)
> 
> my_rect : Rect;
> 
> with my_rect do begin  { may have a scope of many lines }
>   top    := top - top_margin;
>   right  := left + (3*(bottom - top)) div 4;
>   bottom := bottom - bot_margin;
> end;
> 
> In this case, the proposed solution would not help much.  It would be 
> preferable to work as in C: no local block, and all the fields are written
> in full.  An extra local variable cannot do any better.
> 
> my_rect.top    := my_rect.top - top_margin;
> my_rect.right  := my_rect.left + (3*(my_rect.bottom - my_rect.top)) div 4;
> my_rect.bottom := my_rect.bottom - bot_margin;
> 
> This is the case every time the structured type is directly the type
> of the variable at work.  No array of, pointer to, or field in a record 
> of the structured type.  The Ada renaming is quite effective when the
> structured type is deeply nested in the variable call.

Note that Macintosh Pascal compilers have often been constructed
so as not to help the user regarding interaction between "with"
statements and memory-moving toolbox calls.  Thus if the "with"
statement base calculation dereferences an unlocked handle
(pointer to a pointer to data) no toolbox calls which might
relocate heap should be made within the scope of that "with".

Pascal code which ignores that problem might be hit only after
translation to Ada, and for those trying to port code rather
than point fingers (yes, it was bad Macintosh Pascal) a translator
would be more valuable if it unrolled the problem "with" clauses
(even if the best it could do was to unroll _all_ "with" clauses).

Or can one rename something based on an aliased pointer ?

Larry Kilgallen




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

end of thread, other threads:[~1996-12-02  0:00 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-11-27  0:00 Pascal to Ada translator/ aflex,ayacc GNAT ports Martin C. Carlisle
1996-11-27  0:00 ` Michael Feldman
1996-11-28  0:00   ` steved
1996-11-29  0:00     ` Robert Dewar
1996-11-29  0:00       ` wiljan
1996-11-29  0:00         ` Robert Dewar
1996-11-30  0:00           ` wiljan
1996-11-30  0:00             ` Robert Dewar
1996-12-01  0:00               ` wiljan
1996-12-01  0:00                 ` Michael Feldman
1996-12-01  0:00                 ` Robert Dewar
1996-12-02  0:00           ` Laurent Gasser
1996-12-02  0:00             ` Jacques Rouillard
1996-12-02  0:00             ` Larry Kilgallen
1996-11-29  0:00       ` Larry Kilgallen

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