| 123456789101112131415161718192021222324252627 |
- MODULE Showcase1;
- // Tour of the V3 step-1 integer pipeline: modern tokens (0x hex,
- // // comments), both IMPORT forms, folded CONSTs, every operator,
- // precedence, parens, unary minus on literals and variables.
- // Expected ExitCode: 50 (hand-computed, truncating DIV).
- IMPORT Dummy;
- FROM Elsewhere IMPORT Thing;
- CONST
- Ten = 10;
- NegThree = -3;
- Mask = 0xFF; (* 255 *)
- Big = 0x10; (* 16 *)
- VAR
- ExitCode, tmp, acc : INTEGER;
- BEGIN
- (* (10 + 255) * 2 - 100 DIV 7 + (-3) = 530 - 14 - 3 = 513 *)
- tmp := (Ten + Mask) * 2 - 100 DIV 7 + NegThree;
- (* 513 MOD 100 - (-3) + 2 = 13 + 3 + 2 = 18 *)
- acc := tmp MOD 100 - NegThree + 2;
- (* 18 * 3 - (513 - 18) DIV 100 + 16 - 16 + (-513) + 513
- = 54 - 4 + 0 + 0 = 50; unary minus needs parens after
- a binary operator, per Wirth simpleExpr *)
- ExitCode := acc * 3 - (tmp - acc) DIV 100 + Big - Big + (-tmp) + tmp
- END Showcase1.
|