Statements

Execution Statements

  • An execution statement consists of one or more function/primitive calls in prefix notion
  • Prefix notation uses only position and space to specify the arguments, no commas or parentheses are needed or accepted
  • For example, suppose you had a two argument function like this
DEF POW $a $b:
  # do some stuff to compute a^b
  RETURN $result;
END_DEF

which, in a language like python, would look like this

def pow(a, b):
  # do stuff
  return result

To compute something like (a^b)^(c^d), you would write

POW POW $a $b POW $c $d;

correponding to pow(pow(a, b), pow(c, d)) in python.

But to compute a^(b^(c^d)), you would write

POW $a POW $b POW $c $d;

correponding to pow(a, pow(b, pow(c, d)) in python.

  • Statements must be ended by the semi-colon (;) token

IF Statements

An IF statement consists of an opening statement, body, and closing statement

IF opening statement

  • IF, followed by an expression that evaluates to a boolean (this is called the conditional), followed by a colon (:) to end the statement:
# ok
IF LESS 4 2:
# synatx error
IF LESS 4 2 0:

IF body

  • The body consists of a sequence of statements of any length, as long as those statements do not evaluate to a function/receiver opening or closing statement.
  • The body is executed only in the case that the conditional evaluates to TRUE.

IF closing statement

  • The single token END_IF
  • This token must appear as its own line; e.g.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
 # correct syntax
 IF LESS 4 2:
   RETURN PLUS $n 1;
 END_IF

 # syntax error
 IF LESS 4 2:
   RETURN PLUS $n 1; END_IF

 # syntax error
 IF LESS 4 2:
   RETURN PLUS $n 1;
 END_IF ASSIGN 'i' 0;
 ...

WHILE Statements

A WHILE statement consists of an opening statement, body, and closing statement

WHILE opening statement

  • WHILE, followed by an expression that evaluates to a boolean (this is called the conditional), followed by a colon (:) to end the statement:
# ok
ASSIGN 'i' 0;
WHILE LESS $i 15:
  ...

WHILE body

  • The body consists of a sequence of statements of any length, as long as those statements do not evaluate to a function/receiver opening or closing statement.
  • Execution of the body is repeated as long as the conditional evaluates to TRUE, for a maximum number of iterations of 10000.

WHILE closing statement

  • The single token END_WHILE
  • This token must appear as its own line; e.g.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
 # correct syntax
 ASSIGN 'i' 0;
 WHILE LESS $i 15:
   ASSIGN 'j' PLUS $j $i;
   ASSIGN 'i' PLUS $i 1;
 END_WHILE

 # syntax error
 ASSIGN 'i' 0;
 WHILE LESS $i 15:
   ASSIGN 'j' PLUS $j $i;
   ASSIGN 'i' PLUS $i 1; END_WHILE

 # syntax error
 IF LESS 4 2:
   RETURN PLUS $n 1;
 END_IF ASSIGN 'i' 0;
 ...
  • You can nest IF and WHILE statements, as long as each opening statement has a corresponding closing statement and in the correct order:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
 # parses
 IF LESS $j 200:
   ASSIGN 'i' 0;
   WHILE LESS $i 15:
     ASSIGN 'j' PLUS $j $i;
     ASSIGN 'i' PLUS $i 1;
     IF GREATER $j 300:
       RETURN $j;
     END_IF
   END_WHILE
 END_IF

 # syntax error
 IF LESS $j 200:
   ASSIGN 'i' 0;
   WHILE LESS $i 15:
     ASSIGN 'j' PLUS $j $i;
     ASSIGN 'i' PLUS $i 1;
   END_IF
 END_WHILE

RETURN/ACCEPT/REJECT Statement

  • RETURN statements immediately end execution of the function scope it is contained in
  • ACCEPT/REJECT statements immediately end execution of the receiver scope it is contained in