Aspect26 / TrufflePascal

Year project - Pascal interpreter written in Java using Truffle API
9 stars 3 forks source link

Subroutine as a parameter #89

Closed Aspect26 closed 7 years ago

Aspect26 commented 7 years ago

From the examples in the ISO standard it is clear that Pascal shall support subroutines as aparameters:

program t6p6p3p4 (output);
var globalone, globaltwo : integer;

procedure dummy ;
begin
writeln( ' fail4 ' )
end { of dummy 1;

procedure p (procedure f(procedure ff ; procedure gg) ; procedure g);
 var localtop : integer;
 procedure r;
  begin { r }
  if globalone = 1 then
   begin
   if (globaltwo <>
    writeln( ' fail1' )
   end
  else if globalone = 2 then
   begin
   if (globaltwo <> 2) or (localtop <> 2) then
    writeln( ' fail2 ' )
   else
    writeln( ' pass ' )
   end
  else
   writeln( ' fail3 ' );
  globalone := globalone + 1
  end { of r ~;
 begin { of p }
 globaltwo := globaltwo + 1;
 localtop := globaltwo;
 if globaltwo = 1 then
  p(f, r)
 else
  f(g, r)
 end { of p};

procedure q (procedure f ; procedure g);
 begin
 f;
 g
 end { of q};

begin { of t6p6p3p4 }
globalone := 1;
globaltwo := 0;
p(q, dummy)
end. { of t6p6p3p4 }

Do we need to support this? Currently Im not able to think about how difficult it will be to implement this feature.

Aspect26 commented 7 years ago

apparently, TurboPascal does not support this syntax. However, it suports this:

type fType = function:integer;

proceure p(f: proctype);
begin
    write(f);
end;
Aspect26 commented 7 years ago

the first version will be supported also with the TP mode turned on