i := x + y; # this is a comment j := a - b; # this computes "a + (-b)" # a comment; still in the comment # and more comment
foo1 _foo1 f_o__o1 foo_1__ _ __ ___1
<test>
<stmt list-1>
<stmt list-2>
-1
-2
<stmt>
The semantics of the for statement are identical to those of the following while statement:
expr-1
expr-2
input
output
Two new boolean constants are supported, true and false. In addition, two boolean operators are introduced, and and or. Both operators take boolean expressions as arguments and return a boolean value. Both are short-circuiting, meaning that the second (rightmost) argument is not evaluated if the result of the first argument fully determines the result. They are both left-associative, and and has higher precedence than or; but and has lower precedence that all other operators. Example:
true
false
and
or
if a = 0 or x / a > 3 and b then end; # test parses as "(a = 0) or (((x / a) > 3) and b)" # if a = 0, then don't evaluate the rest of the test
In the extended language, the following notation references an array element:
<lvalue>
var a:array [5] of array [3] of int; var b: array [3] of int; a[1][i+j] := b[k-1] * 2; a[1] := b; # This is illegal b := input; # So is this
var
procedure foo(var x: int, var y: int, var z: array [10] of int); begin x := x+y; y := y+x; x[5] := x*y; end foo;
var a: int, b : array [10] of int; const c: int = 5; var d: array [5] of int; foo(a,17,b); #legal foo(b[5],a+b[7],b); #legal foo(c,17,b); #illegal foo(17,a,b); #illegal foo(a+b[7],20,b); #illegal foo(a,17,d); #illegal
Arguments of scalar types can be passed by either value or reference. Arrays must be passed by reference, and as a result var must precede arrays which are declared as formal parameters. The size of the array being passed must match the type of the array formal.
The following are legal function declarations:
procedure foo(x:int, y:bool) : int; begin end foo; procedure bar():bool; var x:int; begin end bar;
foo(foo(3,bar()), i < foo(x+y,bar()));
To return a value from a function, the return statement is used with an expression. Both forms are captured by
return
then
if
The following illustrates some legal uses of return statements:
procedure foo(x:int,y:bool):int; begin if y then return x; end; return x * 5; end foo;