Allow relaxed declarations

When the relaxed declarations extension is enabled, declarations can occur before the reserved word program which normally marks the start of the program. When this is done, the declarations are placed in the same outermost scope as the declarations for the built-in identifiers (e.g. writeln). As you probably know, when you declare an identifier, your declaration will override any other declarations of that identifier in outer scopes. It is recommended that you include system include files before the reserved word program, so that the many declarations they contain will be placed in the outermost scope, where you can easily ignore the ones you are not interested in, because if you happen to declare the same identifier, in your program, as one of the identifiers declared in the system include file, your declaration will override the declaration in the system include file.

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.