1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
program main( input, output );
(* local variables *)
var x, y: integer;
var a, b: real;
var c: array[ 1..10 ] of integer;
var d: array[ 11..20 ] of real;
(* local function: mixed argument types *)
function foo( a: integer; x: real; z: integer ): integer;
procedure boo( a: real );
begin
(* scope check on boo's a, main's b, d[] and y; and foo's z*)
boo( a * b + d[y + z] )
end;
begin
(* boo is visible; so is main's b *)
boo( b );
(* function return statement; scope and type check on foo's a and main's y *)
foo := a + y
end;
(* local procedure *)
procedure bar( c: integer );
begin
(* nonlocal update *)
d[ c[foo(x,a,y)] ] := b
end;
(* location function: recursive *)
function moo( d: integer ): integer;
begin
if ( d = 0 ) then
moo := 1
else
moo := d * moo( d - 1 )
end;
begin
(* FUNCTION call check: recursive and correct arguments *)
y := foo( x + foo( y, 0.001, a ) * 1, 2.3, b );
(* ARRAY access check: recursive, correct arguments *)
y := c[ x + c[y] * 45 ];
(* FUNCTION call and ARRAY access *)
y := foo( x + c[y + foo(c[1], d[2], a)] * 1, 2.3 + d[c[foo(c[3],b,d[y])]] );
(* IF-THEN check *)
if ( c[x] * 6 < 7 + moo( y ) and a > d[c[x]] ) then
begin
c[moo(foo(8,9.10,11.0)) + c[12]] := moo( c[y - 1] )
end;
(* PROCEDURE call: correct arguments, not used as expression *)
bar( c[x] );
(* FOR check *)
b := 10.0;
for a := 1.0 to 2.0 * b do
begin
bar( c[x + moo( c[x + moo( c[x + moo(1)] )] )] );
a := a + 0.0000001
end
end.
|