Imp
Copyright (c) 1998-1999 Redshift Software Inc. All Rights Reserved

2

Programs

 

2.1
Control Structure
 
 


IMP has a small set of control structures with unusual semantics. Each control structure uses the conditional statement on (expression) statement to direct program flow. A conditional statement controls a number of statements, executing them when the conditional expression is true. Thus the usual order of operations is for the program to evaluate all the conditional expressions, execute the statements whose conditions are true and return the logical value of the entire expression.


2.1.1
IF
 
 
The format of if is as follows:
if conditional statement
else conditional statement
...
else statement
The if statement executes only the first true conditional statement or a default statement (if one exists).

2.1.2
LOOP
 
 
The format of loop is as follows:
loop variable declaration {
[statement]
[conditional statement]
...
}
The loop statement executes its body until a conditional statement is false.

2.1.3
CASE
 
 
The format of case is as follows:
case variable declaration {
conditional statement [statement]
...
}
The case statement consists of a number of conditional statements. There is no preferred order of evaluation for the conditionals i.e. the programmer can not assume that the conditional statements execute in any particular order. All conditionals evaluating to true are executed.

2.1.4
GUARD
 
 


The format of the guard block is as follows:

guard variable declaration {
[statement conditional statement]*
...
}

The guard staement consists of a number of statements each followed by a conditional statement. The conditional statement may contain a handle statement that deals with the exception when the conditional expression executes. If the guard does not invoke a handle call the exception continues up the call chain. If an exception reaches the top of the call chain without being handled the program terminates.

The format of the handle call is as follows:

handle ([variable declaration]) {
[statement]*
...
}

The format of fail is as follows:

fail (exception type, [record]);

The format of recover is as follows:

recover (exception type, [record]);

 

 

 

 


 
Reference
 
1 Lexical
2 Programs
3 Declarations
4 Expressions
5 Statements
6 Preprocessor
7 EBNF