Control


Other than the assignment statement, two control structures, if- and while-statments, are added to the abstract syntax:
     P ::= L
     L ::= S ';' L1 | S
     S ::= I ':=' E
         | 'if'  E  'then' L1  'else' L2  'fi
         | 'while'  E  'do'  L  'od'
Reduction rules for if-statements are the following:
  1.                  <E|Env> ⇒ <E1|Env>                 
    <'if' E 'then' L1 'else' L2 'fi' | Env> ⇒ <'if' E1 'then' L1 'else' L2 'fi' | Env>
  1.                          V > 0                         
    <'if' V 'then' L1 'else' L2 'fi' | Env> ⇒ <L1 | Env>
  1.                          V ≤ 0                         
    <'if' V 'then' L1 'else' L2 'fi' | Env> ⇒ <L2 | Env>
Reduction rules for while-statements are as follows:
  1.          <E|Env> ⇒ <V|Env>, V≤0         
    <'while' E 'do' L 'od' | Env> ⇒ Env
  1.              <E|Env> ⇒ <V|Env>, V>0             
    <'while' E 'do' L 'od' | Env> ⇒ <L ; 'while' E 'do' L 'od' | Env>
Note that the last rule is recursive. It states that if, given environment Env, the expression E evaluates to a positive value, then execution of the while-loop under Env reduces to an execution of L, followed by the execution of the same while-loop all over again.