Contents | Prev | Next

13.2 Allow relaxed declarations

Standard Pascal requires that all declarations and definitions of the same kind must be made together in a single group, and that the groups must appear in a specific order. The groups are listed below in the order that they must appear in a Standard Pascal program.:

When the relaxed declarations extension is enabled, there can be more than one of each kind of decaration/definition group, and groups can appear in any order except that for local declarations the sub-block declaration group must be last.

So if the relaxed declarations extension is enabled then the following program is valid:

   program summing(output);
   const
      first = 1;
      last = 100;
   type
      num = first..last;
   var
      i : num;
   type
      atype = array[first..last] of integer;
   var
      a : atype;
      sum : integer;
   begin
      sum := 0;
      for i := first to last do
         begin
            sum := sum + i;
            a[i] := sum
         end;
      for i := last downto first do
         writeln(i, a[i]);
   end.

even though it has two type definition groups

   type num = first..last;

and

   type atype = array[first..last] of integer;

and two variable declaration groups

   var i : num;

and

   var a : atype; sum : integer;

In Standard Pascal (i.e. if the relaxed declarations extension is not enabled), you would have to combine these groups so you would have the following:

   program summing(output);
   const
      first = 1;
      last = 100;
   type
      num = first..last;
      atype = array[first..last] of integer;
   var
      i : num;
      a : atype;
      sum : integer;
   begin
      sum := 0;
      for i := first to last do
     begin
        sum := sum + i;
        a[i] := sum
     end;
      for i := last downto first do
     writeln(i, a[i]);
   end.

Contents | Prev | Next