t75_arrvar.pas 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. program t75_arrvar;
  2. { t75 -- variable ARRAY subscripts.
  3. CALC.INC:130 has `XPos[Count]' - a run-time index into a typed-constant
  4. array - and later `Sheet[FX,FY]'. A CONSTANT index folds into boff; a
  5. run-time one is (i - lower) * elemsize from the base, and the element's
  6. address rides in DI, the same shape string subscripts use. What is new is
  7. the WIDTH: an array element is one byte or two, not always a character.
  8. Covers a global Integer array, a global Byte array, a typed-constant array
  9. indexed by a Char, a LOCAL array, writes whose right-hand side also uses a
  10. subscript (DI must survive the parse), and reads used in expressions. }
  11. type
  12. Letters = array ['A'..'C'] of Integer;
  13. const
  14. X : Letters = (10, 20, 30);
  15. var
  16. a : array [1..5] of Integer;
  17. b : array [1..5] of Byte;
  18. i : Integer;
  19. c : Char;
  20. procedure Local;
  21. var
  22. v : array [1..3] of Integer;
  23. k : Integer;
  24. begin
  25. for k := 1 to 3 do
  26. v[k] := k * 5;
  27. writeln (v[2])
  28. end;
  29. begin
  30. for i := 1 to 5 do
  31. a[i] := i * 10;
  32. writeln (a[3]);
  33. i := 2;
  34. writeln (a[i]);
  35. a[i] := 99;
  36. writeln (a[2]);
  37. c := 'C';
  38. writeln (X[c]);
  39. for i := 1 to 3 do
  40. b[i] := i;
  41. writeln (b[2]);
  42. Local;
  43. b[2] := 7;
  44. a[3] := b[2] + 1;
  45. writeln (a[3])
  46. end.