showcase1.mod 895 B

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