The BESM-6 Pascal compiler I'm experimenting with has a notable difference from Standard Pascal: formal arguments of formal parameters-procedures or functions are not specified, but are checked at runtime:
PASCAL COMPILER 15.0 (15.02.82)
00001 1 0 PROGRAM MAIN(OUTPUT);
00007 2 1 PROCEDURE P(FUNCTION F:INTEGER);
00007 3 3 BEGIN
00015 4 3 WRITELN(F(P));
00036 5 2 END;
00037 6 1 FUNCTION F(I:INTEGER):INTEGER;
00037 7 3 BEGIN
00045 8 3 F := I + 5
00045 9 2 END;
00047 10 2 BEGIN
00050 11 2 P(F);
00072 12 0 END.
Here we pass an integer function F
to the procedure P
and we attempt to call it with a procedure argument, whereas it accepts an integer argument and returns it incremented by 5 (e.g. in case of WRITELN(F(5))
, 10
would be printed.
The compilation succeeds, and at runtime the following happens:
FORMAL PROC CALL ERROR
FOR 1 PARAMETR CALL FROM 001032
PASCAL PM DUMP
9 STACK LENGTH. NAME= P.LINE=3
3586 STACK LENGTH. NAME= MAIN.LINE=12
PASCAL PMD END
I've been able to verify that actual parameters are checked for number and for "severe" type discrepancies. E.g. passing CHAR to a function which accepts INTEGER succeeds, but attempting to pass a procedure instead of an integer fails.
Standard Pascal would not accept the code as written; it requires the formal parameter prototypes to be declared the same way as in actual definitions, like
PROCEDURE P(FUNCTION F(I:INTEGER):INTEGER);
and all type checks are done at compile time.
In his book Systematic Programming: An Introduction, Wirth provides a syntax diagram
and an example
using the syntax accepted by the BESM-6 Pascal compiler. It appears that the compiler author was following the book quite closely; are there any extant compilers accepting that syntax?