!TITLE Executable Statements !KEY In IMP80 a condition can form part of any executable statement. Conditions are therefore described before the various types of executable statement. !) is not equal to < is less than <= is less than or equal to > is greater than >= is greater than or equal to == refers to the same variable as ## (or \==) does not refer to the same variable as In the case of the last two comparators, == and ##, the items being compared are references to variables, which must be of identical type. The condition is true if the addresses of the variables referred to are equal (==) or not equal (##). (Note that the address of a reference variable is the address of the variable to which it refers: see Section 6.1.2) {EMAS IMP80: the == and ## comparators cannot be used to compare references to arrays.} !PAGE The other forms of simple condition are as follows: a) This is known as a double-sided condition. Example: A+B <= C+D < E+F This condition is true if A+B <= C+D and C+D < E+F . The third expression is only evaluated if the condition between the first two expressions is true. The comparators == and ## (or \==) may not be used in double-sided conditions. !PAGE b) String resolution Example: A -> B.(C).D The resolution is attempted. If it succeeds the condition is true AND the resolution is performed. If it fails the condition is false, but no event is signalled. c) Compound condition (see below) enclosed in brackets Example: (A>0 %or B<=0) d) Any of the above forms preceded by the keyword %not The effect of preceding a simple condition with %not is to reverse the truth value of the condition. !PAGE Examples: %not A <= 0 (equivalent to A > 0) %not 23 <= I+J <= 99 Compound conditions can be produced by combining simple conditions using the keywords %and and %or: %and %and .... %or %or ...... Examples: A+B <= C+D %and C+D < E+F I = 20 %or A -> B.("..").C %or X > Y >= Z+3.47 !PAGE It is not valid to combine %and and %or, as in X < Y %and B = C %or D = 24 However a compound condition enclosed in brackets is treated as a form of simple condition (see above). Thus (X < Y %and B = C) %or D = 24 is valid. Note that the form %not (X < Y %and B = C) is also permitted. By combining %and and %or and brackets, conditions of arbitrary complexity can be produced: Example: (A <= B %or C == D) %and S -> ("Jim").T %and %c (X <= Y <= Z %or (P_K = 23 %and Q < 0)) !PAGE The testing of conditions proceeds from left to right, simple condition by simple condition, terminating any clause as soon as an inevitable outcome for the clause has been established. Thus, in the example above, if A <= B were true then C == D would not be evaluated; if A <= B were false and C == D were false then the remainder of the condition would not be evaluated. Example: A = 0 %or B/A = C If the variable A has the value 0 the whole condition will be true without B/A = C being tested. B/A = C %or A = 0 In this case an event will be signalled ("overflow") if variable A has the value 0. !> ! is an imperative statement which may be made conditional. The following IMP80 statement types are instructions: statement described in assignment Section 2 routine call Section 3.2 %monitor Section 4.2.4 %signal %event Section 3.1 %return Section 3.2 %result= Section 3.2 jump Section 4.2.1 %stop Section 4.2.3 %exit Section 4.4.3 %continue Section 4.4.3 !PAGE In addition, a can be formed by use of the keyword %and: %and %and ...... Example: X = 23 %and %continue The last of the series of instructions in a compound instruction can be any of those listed above; the other component instructions can only be assignments, routine calls or %monitor statements. ! %then or %unless %then !PAGE In the first form, the instruction is executed if the condition is true; in the second, the instruction is not executed if the condition is true. If the instruction is not executed, nothing is done. Examples: %if 0 < I <= 9 %and K > 0 %then B(I) = K %unless J = I %then A(I,J) = 0 %if and %unless statements can be elaborated to allow specification of an alternative instruction, to be executed if the first one is not: %if %then %else %unless %then %else Example: %if X < 47.2 %then Y = Z+3 %else Y = 0.0 !PAGE Note that the first instruction in these elaborated %if and %unless statements must be unconditional but the second instruction can be conditional. Example: %if STATE < 0 %then ERROR = IN %else %c %if STATE = 0 %then ERROR = CALCULATION %else ERROR = OUT The simple forms of %if and %unless statements (i.e. those without the %else) can be made simpler still: %if %unless Examples: B(I) = K %if 0 <= I <= 9 %and K>0 A(I,J) = 0 %unless J = I !> !