# Section 6.7.13:
Assert Statement

An assertion is a statement made by the writer of the program that, at the point in the code where the assert statement appears, the argument (a logical value) is true. If it should not be true then an exception is raised on the object involved.

#### Concrete Syntax

assert statement = Assert_SY, expression ;

#### Abstract Syntax

This statement type makes use of the built-in routine with the 'Assert' identity. This is defined as in the following invariant -

Predefined_Call ::
id : token
args : Feature
impl : Feature
rval : [Value_Expression] ;
inv mk_Predefined_Call(expid,args,imp,val) ==
expid = Assert
and len args.args = 2
and args(2).kind = BOOL
and imp.impl = assert_built_in(args(1),args(2))
and val = nil

#### Static Semantics

The invariant above completely defines the well-formedness condition of an assert statement. The implementation is given below in the dynamic statement section.

#### Dynamic Semantics

The assertion statement raises an exception if the argument given is false, otherwise does nothing.

assert_built_in(self : SAME, log : bool)
post true
errs Assert_fail : not log -> raise self

Note that this definition does not specify how the assertion is to be implemented. In practical terms it is, of course, the equivalent of

if ~log then
raise self
end

| Specification Index |  | Language Index |  | Section 6 Index

Comments or enquiries should be made to Keith Hopper . Page last modified: Monday, 29 May 2000. |