- // This program should print the number 20.
- program Twenty:
- int a;
- int b;
- a := 2;
- b := 1;
- if not (a < 0) then
- int b;
- b := - 2; // (the inner b, the outer one is still 1)
- a := a * b // a = -4
- else
- int c;
- c := a - b;
- a := a * (c - b)
- fi;
- print a * (a - b) // -4 * (-4 - 1) = -4 * (-5) = 20
- end
- // This program should print the number 20.
- program Twenty:
- int a;
- int b;
- a := 2;
- b := 1;
- while a >= 0 do
- int b;
- b := - 2; // (the inner b, the outer one is still 1)
- a := a * b // a = -4
- od;
- print a * (a - b) // -4 * (-4 - 1) = -4 * (-5) = 20
- end
- // This program should print the number 20.
- program Twenty2:
- int a;
- int b;
- a : = 2;
- b := 1;
- if not (a < 0) then
- int b;
- b := - 2; // (the inner b, the outer one is still 1)
- a := a * b // a = -4
- else
- int c;
- c := a - b;
- a := a * (c - b)
- fi;
- print a * (a - b) // -4 * (-4 - 1) = -4 * (-5) = 20
- end
- // Euclid's algorithm for the greatest common divisor.
- program GCD:
- int a; int b;
- a := 15;
- b := 20;
- print a; print b;
- while a != b do
- if a < b then b := b - a
- else a := a - b
- fi
- od;
- print a
- end
- program Hiding :
- int a;
- int b;
- a := 2;
- b := 5;
- while not (a != b) do
- int b;
- b := 2 * a;
- print b;
- a := a + 1
- od;
- print b
- end
- program condtional:
- if 3 < 3 then
- print false
- fi
- end
- program condtional2 :
- if 3<3 then print false fi
- end
- program lexicallyOk :
- intt a;
- int b;
- a :== 2;
- b := 5;
- while (a != b) do not print else do
- int b;
- b := 2 *** a;
- print b;
- a := a + 1
- od;
- print b
- end
- program lexically-Ok-2
- program Print:
- print(77)
- end
- program bad_expression:
- int a;
- int b;
- if4 a < b then5
- 2int b;
- b := 2 * a
- 5else
- bool b;
- b := 2 * a
- fii
- end