Hi Kevan,

Yes, your "type Data ..." is the way to go. You can later declare arrays of type QData using

   foo : Qdata (1..37);
   bah : Qdata (6..100);

You can do simple loops like

   for i in foo'first .. fool'last loop
      foo (i) := i;
   end loop;

or even

   for i in bah'range loop
      bah (i) := i*i;
   end loop;

You can also use this method to handle GPC's conformant arrays formal parameters. So the Pascal code

procedure mary (var abc : Array[a..b] of Integer);
...
mary (foo);
mary (bah);

would become

procedure mary (abc : in out Qdata) is
...
mary (foo);
mary (bah);

The attributes 'first, 'last and 'range are Ada's way of giving you access to the properties (well attributes) of your arrays.

If you're using gnat you'll also find that it comes with a pretty printer. It only works on correct Ada code so it's usually the lats thing I do after a conversion using pa2ada. Try

gnatpp fred.adb

(see gnatpp --help for a list of options)

Cheers,
Leo

ps. The correct usage is Ada not ADA (the folks on comp.lang.ada will have a pink fit if you use ADA, they'll point out that it could be the Australian Dental Association). Ada is a name not an acronym.


On 5 January 2017 at 07:15, Kevan Hashemi <hashemi@brandeis.edu> wrote:
Dear Leo

I'm not sure how committed people on this list are to staying with Pascal but if you are prepared to jump ship to Ada then I can tell
you from my own experience it is well worth the effort.

This is an interesting proposal.

I just installed GCC 4.7.0 with ADA included on my MacOS 10.7 laptop (still with 10.7 so I can use existing GPC binaries). The ADA compiler works right away, which is awesome.

I downloaded p2ada binaries and translate the following program:

program p; begin writeln('hello world from Pascal.'); end.

The ADA output compiles immeditaely in the ADA compiler, and runs correctly. I note that the ADA code contains 38 lines, but I'm guessing that much of the extra occurs only once per translation. I now try to translate the following program:

program p;

type
  graph_type(num_points:integer)=array [0..num_points-1] of real;
  graph_ptr=^graph_type;

var
  xg:graph_ptr;
  i:integer;
       
begin
  new(xg,100);
  for i:=0 to 99 do xg^[i]:=i;
end.

In p2ada I get: "Syntax Error at line 4"

It looks like p2ada does not translate dynamic schema types. I would have to convert them all manualy. But does ADA itself support dynamic schema types? It supports a format like this:

type QData is array(Positive range <>) of Quarndex;

I guess that's an array of any integer size. If anyone can confirm that it's possible to translate dynamic schema types into ADA, then this translation looks like a good long-term solution.

Yours, Kevan

--
Kevan Hashemi, Electrical Engineer
Physics Department, Brandeis University
http://alignment.hep.brandeis.edu/