| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- MODULE Showcase12;
- // Step-8.2/8.3 showcase. Exercises, in one small session:
- // - named-CONST folding in an array bound (M = N*2-1)
- // - a forward pointer type (Link = POINTER TO Node; Node later)
- // - a trailing ';' before a record's END
- // - empty statements (';;' and a lone ';')
- // - 1-character string literals passed to ARRAY OF CHAR
- // - a qualified type name (Showcase12Lib.Point) and qualified call
- // Expected ExitCode: 42.
- IMPORT Showcase12Lib;
- CONST
- N = 4; // folded: N used below
- M = N * 2 - 1; // folds to 7 — the bound of Vec
- TYPE
- Vec = ARRAY [0 .. M] OF INTEGER; // 8 elements
- Link = POINTER TO Node; // forward: Node is declared later
- Node = RECORD
- value : INTEGER;
- next : Link; // trailing ';' before END is accepted
- END;
- VAR
- ExitCode : INTEGER;
- v : Vec;
- head : Link;
- pt : Showcase12Lib.Point; // qualified type name
- i, sum : INTEGER;
- BEGIN
- sum := 0;
- FOR i := 0 TO M DO v[i] := i; sum := sum + v[i] END;; // 0+..+7 = 28
- ; // empty statement
- NEW(head); head^.value := 9; head^.next := NIL;
- sum := sum + head^.value; // 37
- sum := sum + Showcase12Lib.Score("A")
- + Showcase12Lib.Score("B"); // +2+3 = 42
- pt.x := 42;
- IF sum = pt.x THEN ExitCode := sum ELSE ExitCode := 1 END
- END Showcase12.
|