EXPR.PAS 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. program expr;
  2. (* Program to test various types of expressions *)
  3. type string80 = STRING[80];
  4. var Flag : boolean;
  5. Ch1, Ch2 : char;
  6. I, J, K : integer;
  7. X, Y : real;
  8. Str1, Str2, Str3 : string80;
  9. Str4, Str5: string[80];
  10. begin
  11. (* Assign values correctly *)
  12. I := 10;
  13. J := 122;
  14. K := 55;
  15. X := 1.25;
  16. Y := 44.5;
  17. (* Assign values of different type *)
  18. I := 10.5;
  19. J := 122.78;
  20. K := 55.35;
  21. X := 1;
  22. Y := 44;
  23. (* String Assignment *)
  24. Str1 := 'Hello there ';
  25. Str2 := 'Sally';
  26. Ch1 := 'A';
  27. Ch2 := ^G;
  28. Str3 := Str1; (* valid because of same type *)
  29. Str4 := Str1; (* not valid because of different type *)
  30. Str5 := Str4; (* not valid because of different type *)
  31. (* Translator converts expression *)
  32. Y := Y + 100;
  33. writeln('Y = ',Y); writeln;
  34. (* Translator converts expression *)
  35. X := X + I;
  36. writeln('X = ',X); writeln;
  37. (* Expressions below will not be translated *)
  38. Str3 := 'Hello ' + 'There';
  39. Str3 := Ch1 + ' big hello';
  40. Str3 := Ch1 + Str1;
  41. Str3 := Str1 + Str2;
  42. (* Expression below will not be translated *)
  43. Flag := Str2 = 'Sally';
  44. END.
  45.