t74_caselist.pas 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. program t74_caselist;
  2. { t74 -- comma-separated CASE labels, and ranges that actually work.
  3. CALC.INC's IBMCh has
  4. 'G', 'I', 'O', 'Q': Ch := #00;
  5. The parser read ONE label and then demanded ':', so the list was ENoSemi.
  6. While fixing that, the range emitter turned out to be wrong too: it compared
  7. the selector with lo and then with hi, BOTH requiring equality, so `1..5'
  8. matched nothing unless lo = hi. A minimal probe (i := 3; case i of 1..5)
  9. printed the ELSE arm. No error, just a wrong answer - which is why this
  10. fixture pins the low edge, the high edge, a list mixing values and ranges,
  11. and misses on both a char list and a range list. }
  12. var
  13. c : char;
  14. i : integer;
  15. begin
  16. c := 'I';
  17. case c of
  18. 'G', 'I', 'O', 'Q': writeln ('group')
  19. else
  20. writeln ('other')
  21. end;
  22. c := 'A';
  23. case c of
  24. 'G', 'I', 'O', 'Q': writeln ('group')
  25. else
  26. writeln ('other')
  27. end;
  28. i := 3;
  29. case i of
  30. 1..5: writeln ('range')
  31. else
  32. writeln ('outside')
  33. end;
  34. i := 5;
  35. case i of
  36. 1..5: writeln ('range')
  37. else
  38. writeln ('outside')
  39. end;
  40. i := 7;
  41. case i of
  42. 1..5, 7, 9..10: writeln ('list')
  43. else
  44. writeln ('miss')
  45. end;
  46. i := 8;
  47. case i of
  48. 1..5, 7, 9..10: writeln ('list')
  49. else
  50. writeln ('miss')
  51. end;
  52. i := 10;
  53. case i of
  54. 1..5, 7, 9..10: writeln ('list')
  55. else
  56. writeln ('miss')
  57. end
  58. end.