Slide 9.5: Reduction rules of assignments (cont.)
Slide 9.7: Control
Home

An Assignment Example (Cont.)


Reduce the first statement, “a ':=' '2' '+' '3';”:
    <a ':=' '2' '+' '3' | Env0>
 ⇒ <a ':=' 2 '+' 3 | Env0>              (Rules 1, 7, and 10)
 ⇒ <a ':=' 5 | Env0>                    (Rules 3 and 17)
 ⇒ Env0 & {a=5} = {a=5}                 (Rule 16)
Update the environment from Env0 to {a=5}:
    <a ':=' '2' '+' '3';  b ':=' a '*' '4';
         a ':=' b '-' '5' | Env0>
 ⇒ <b ':=' a '*' '4';  a ':=' b '-' '5' | {a=5}>   (Rule 18)
Reduce the second statement, “b ':=' a '*' '4';”:
    <b ':=' a '*' '4' | {a=5}>
 ⇒ <b ':=' 5 '*' '4' | {a=5}>           (Rules 15 and 9)
 ⇒ <b ':=' 5 '*' 4 | {a=5}>             (Rules 1 and 12)
 ⇒ <b ':=' 20 | {a=5}>                  (Rules 5 and 17)
 ⇒ {a=5} & {b=20} = {a=5, b=20}         (Rule 16)
Update the environment from {a=5} to {a=5, b=20}:
    <b ':=' a '*' '4';  a ':=' b '–' '5' | {a=5}>
 ⇒ <a ':=' b '–' '5' | {a=5, b=20}>     (Rule 18)
Reduce the third statement, “a ':=' b '–' '5';”:
    <a ':=' b '–' '5' | {a=5, b=20}>
 ⇒ <a ':=' 20 '–' '5' | {a=5, b=20}>    (Rules 15 and 8)
 ⇒ <a ':=' 20 '–' 5 | {a=5, b=20}>      (Rules 1 and 11) 
 ⇒ <a ':=' 15 | {a=5, b=20}>            (Rules 4 and 17)
 ⇒ {a=5, b=20} & {a=15} = {a=15, b=20}  (Rule 16)
The program reduces to the environment {a=15, b=20}, which is the semantics of the program. Note that these reductions are incomplete because we have skipped the reductions of identifiers.