home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug175.arc / JRTMAN1.LBR / JRTMAN.0Z4 / JRTMAN.004
Text File  |  1979-12-31  |  14KB  |  380 lines

  1. .OP
  2.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -19-
  3.  
  4.  
  5.  
  6.       4.    Data Types
  7.  
  8.  
  9.            Pascal  is  a  language  rich in data types. Unlike Basic, which
  10.       provides only  two  or  three  data  types,  Pascal  provides  eight:
  11.       integers,  real  numbers, Booleans, characters, structured variables,
  12.       sets, pointers, and dynamic strings.  These forms can be combined  in
  13.       records and arrays to form data aggregates that closely relate to the
  14.       application  area.   Records and arrays can contain other records and
  15.       arrays and pointers with  no  restrictions  on  nesting  or  even  on
  16.       recursive definitions.
  17.  
  18.            It  is  these  features  that  set  Pascal  apart  from  earlier
  19.       languages  like  Cobol,  Fortran,  PL/I.    Pascal   recognizes   the
  20.       importance  of  powerful  facilities  for  describing  the  data in a
  21.       program as well as the active statements.
  22.  
  23.  
  24.       4.1   Integers
  25.  
  26.            Integers  or  whole  numbers  occupy  two   bytes.    They   are
  27.       represented  in  twos  complement  format.   The  range  is -32768 to
  28.       +32767.
  29.  
  30.            Integer literals in the source program and in  console  or  disk
  31.       input  may  be  entered  as hex values.  Standard Intel hex format is
  32.       used.  The last character must be an `H'.  A leading zero is required
  33.       if the first digit is A, B, C, D, E, or F.
  34.  
  35.                   1ah    +0C35H   -0ffh   0c00h   1234H
  36.  
  37.  
  38.       4.2   Real numbers
  39.  
  40.            Real numbers have 14 digits and are expressed in floating  point
  41.       format. The exponent range is from -64 to +63.  The exponent field is
  42.       not required in the source program or input, but when present it must
  43.       be  entered  in  a  fixed  format.   The exponent format is `e+00' or
  44.       `e-00'. (see NOTES section 2.1.2).
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.       Copy compliments of Merle Schnick              SECTION 4:  Data Types
  55. .PAè
  56.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -20-
  57.  
  58.  
  59.  
  60.                   32.01e+04   1.075   -3.14159   -1234567.8901234E-47
  61.  
  62.            In source programs,  the  decimal  point  must  be  included  to
  63.       distinguish real numbers from integers. (NOTE: This version of Pascal
  64.       requires  that at least one digit is entered to the RIGHT and LEFT of
  65.       the decimal point. i.e., 4. and .4 will produce errors where 4.0  and
  66.       0.4 will not).
  67.  
  68.  
  69.       4.3   Booleans
  70.  
  71.            Boolean  variables  may  have  only  two  values: TRUE or FALSE.
  72.       Booleans may be used directly in output statements but should NOT  be
  73.       used directly in input statements.
  74.  
  75.  
  76.       4.4   Char
  77.  
  78.            The char data type is one character.  Packed char fields are not
  79.       meaningful  on 8-bit microcomputers and are not supported.  The ASCII
  80.       character set is used in JRT Pascal.
  81.  
  82.  
  83.       4.5   Structured variables
  84.  
  85.            Structured variables are records or arrays which are treated  as
  86.       aggregates.   For  example:  a  record  of one type could be compared
  87.       directly against a record of another type.  Structured variables  may
  88.       be    compared   (all   six   operators),   assigned,   input/output,
  89.       concatenated, used as parameters and function return  values  without
  90.       restriction.
  91.  
  92.            In  addition  to  the  CONCAT builtin function, the `+' operator
  93.       indicates concatenation of structured variables or dynamic strings.
  94.  
  95.            Structured variables to be compared may have different  lengths.
  96.       The result is determined as if the shorter one is extended by spaces.
  97.  
  98.            In  assigning  structured variables of different lengths, if the
  99.       receiving field is  shorter  then  truncation  will  occur.   If  the
  100.       receiving  field  is  longer  then the remainder of it is padded with
  101.       spaces.
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.       Copy compliments of Merle Schnick              SECTION 4:  Data Types
  109. .PAè
  110.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -21-
  111.  
  112.  
  113.  
  114.       Arrays of type char constitute fixed length strings.  Unlike  dynamic
  115.       strings,  these  have  no (hidden) two byte length prefix.  Arrays of
  116.       fixed length strings are useful for many type of text processing.
  117.  
  118.                   TYPE
  119.                   CHAR100 = ARRAY [1..100] OF CHAR;
  120.                   TABLE = ARRAY [1..40] OF CHAR100;
  121.                   VAR
  122.                   T : TABLE;
  123.                   BEGIN
  124.                   T:= ' ';          (*CLEARS ENTIRE TABLE*)
  125.                   T[1,8] := '*';    (*STORE 1 CHARACTER  *)
  126.                   T[15] := 'JRT Pascal is the best';
  127.                   ...
  128.                   END;
  129.  
  130.  
  131.  
  132.       4.6   Dynamic strings
  133.  
  134.       Dynamic strings are  an  extension  to  standard  Pascal.   A  hidden
  135.       two-byte prefix on the string contains the string's current length in
  136.       bytes.   JRT Pascal dynamic strings may be up to 64k bytes in length.
  137.       Of course the computer's main storage size restricts the  size  to  a
  138.       smaller value.  Other Pascals limit strings to 255 bytes.
  139.  
  140.            The  maximum  size  of  a  string  variable is declared with the
  141.       variable definition.  If no size is  specified,  the  default  is  80
  142.       bytes.
  143.  
  144.                   VAR
  145.                   S1 : STRING;
  146.                   S2 : STRING[4000];
  147.                   S3 : STRING[12];
  148.  
  149.            Dynamic  strings  may  be  used  in  the  same way as structured
  150.       variables:
  151.        comparisons,  assignment,  input/output,  parameters,  and  function
  152.       return values.
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.       Copy compliments of Merle Schnick              SECTION 4:  Data Types
  163. .PAè
  164.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -22-
  165.  
  166.  
  167.  
  168.            NOTE  -  Dynamic  string  variables  may  NOT  be  used  in READ
  169.       statements directed to files, only to the console.   To  read  string
  170.       data from files, fixed strings (arrays of characters) must be used.
  171.  
  172.            The  individual  characters  of  a  string  may  be accessed and
  173.       updated.  If an attempt is made to access  an  element  of  a  string
  174.       beyond the current length of the string, a run-time error occurs.
  175.  
  176.                   S1[4] := 'X';
  177.                   WRITELN( S2[1500] );
  178.                   S1[J] := S1[J+1];
  179.                   S3[1] := UPCASE( S3[1] );
  180.  
  181.            Several  builtin  procedures  and  functions  are  available  to
  182.       enhance  string  processing.   Refer  to  the  sections  on   builtin
  183.       functions and on builtin procedure for complete descriptions.
  184.  
  185.                   name        purpose
  186.                   ----       ---------
  187.                   CONCAT      concatenate n strings
  188.                   COPY        extract portion of string
  189.                   DELETE      delete portion of string
  190.                   INSERT      insert a string into another
  191.                   LENGTH      return current string size
  192.                   POS         search string for a pattern
  193.  
  194.  
  195.       4.7   Sets
  196.  
  197.            Set  variables  occupy  16 bytes.  The entire ASCII caracter set
  198.       may by represented in the 128 bits.
  199.  
  200.                   LOW_CASE := ['a'..'z'];
  201.                   UP_CASE  := ['A'..'Z'];
  202.                   NUMERIC  := ['0'..'9'];
  203.                   ALPHAMERIC := LOW_CASE + UP_CASE + NUMERIC;
  204.                   ALPHABETIC := ALPHAMERIC - NUMERIC
  205.  
  206.                   IF NOT (INPUT_CHAR IN ALPHAMERIC) THEN
  207.                         WRITELN('INVALID INPUT CHAR');
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.       Copy compliments of Merle Schnick              SECTION 4:  Data Types
  217. .PAè
  218.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -23-
  219.  
  220.  
  221.  
  222.            NOTE - Set variables have no meaningful format  in  text  format
  223.       input/output.   Sets  may  be  input/output  to  disk files which are
  224.       opened for binary format processing.
  225.  
  226.  
  227.       4.8   Pointers
  228.  
  229.            Pointers  contain  the  virtual  address  of  dynamic  variables
  230.       created  by  the  NEW procedure and of ghost variables created by the
  231.       MAP procedure. Pointers are two bytes in size.
  232.  
  233.            The value stored in a pointer variable is NOT the actual address
  234.       of the dynamic variable - it is  the  virtual  address.   The  actual
  235.       address  of  a dynamic variable may be obtained with the ADDR builtin
  236.       function.
  237.  
  238.                   ACTUAL_ADDRESS := ADDR( PTR^ );
  239.  
  240.            Note that the actual address of a dynamic  variable  may  change
  241.       during  program  execution,  but the virtual address is fixed for the
  242.       life of the variable.
  243.  
  244.  
  245.       4.9   Dynamic arrays
  246.  
  247.            Dynamic arrays are a  JRT  extension  to  the  Pascal  language.
  248.       Arrays  are a widely used device for storing and retrieving logically
  249.       identical data elements.
  250.  
  251.            Often it is not known in advance how many data elements will  be
  252.       processed - thus it is necessary to create arrays to hold the maximum
  253.       number of elements that ever may be processed.
  254.  
  255.            With  dynamic  arrays,  the  array's  actual  size  need  not be
  256.       "hard-coded" into the source program.  The array size may  vary  with
  257.       each  run  of  the program or even at different times within the same
  258.       run.
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.       Copy compliments of Merle Schnick              SECTION 4:  Data Types
  271. .PAè
  272.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -24-
  273.  
  274.  
  275.  
  276.            In some programs, dynamic arrays can greatly improve storage use
  277.       efficiency.  This implies that the program can operate  over  a  much
  278.       wider range of situations.
  279.  
  280.            IMPORTANT  -  Dynamic arrays MUST be actual variables - they may
  281.       NOT be elements of other arrays or fields of record variables.  Files
  282.       of dynamic arrays are not allowed.
  283.  
  284.  
  285.     Declaring dynamic arrays
  286.  
  287.            The declarations of dynamic arrays in either  the  TYPE  or  VAR
  288.       sections  is  identical  to static arrays except that the indexes are
  289.       not specified as subranges.  The indexes must be specified as  either
  290.       the  reserved  word  INTEGER  or CHAR.  No other index declaration is
  291.       allowed in dynamic arrays.  Static and dynamic  indexes  may  not  be
  292.       mixed in the same array declaration.
  293.  
  294.               TYPE
  295.               MATRIX = ARRAY [ INTEGER, INTEGER ] OF REAL;
  296.  
  297.               VAR
  298.               M : MATRIX;
  299.               TABLE : ARRAY [ CHAR ] OF STRING [20];
  300.               INDEX : ARRAY [ INTEGER, CHAR ] OF INTEGER;
  301.  
  302.  
  303.     Allocating and deallocating dynamic arrays
  304.  
  305.            A  dynamic  array  may  not  be  referenced  until  it  has been
  306.       allocated.  Doing  so  would  cause  a  run-time  error.   Allocation
  307.       accomplishes two purposes:
  308.  
  309.               1. establish the dynamic arrays currnet lower and upper
  310.                  index bounds for each dimension.
  311.  
  312.               2. allocate storage for the dynamic array in dynamic
  313.                  storage.
  314.  
  315.            Current  bounds are stored in an array control block (ACB) which
  316.       also contains an allocation flag, dimension count,  and  the  virtual
  317.       address of the dynamic array.
  318.  
  319.            A builtin procedure performs the allocation operation.
  320.  
  321.               ALLOCATE ( dyn_array_variable [ subrange_expr1,...
  322.                                     subrange_exp_n ] );
  323.  
  324.       Copy compliments of Merle Schnick              SECTION 4:  Data Types
  325. .PAè
  326.       JRT Pascal  User's Guide     version 3.0          NOT FOR SALE   -25-
  327.  
  328.  
  329.  
  330.            Note  that  an  ALLOCATE  must  be  used for each array VARIABLE
  331.       declared, NOT for aaray TYPES.
  332.  
  333.               ALLOCATE ( M [1..10, 0..50] );
  334.               ALLOCATE ( TABLE ['A'..'M'] );
  335.               ALLOCATE ( INDEX [I..I+10, CHAR1..CHAR2] );
  336.  
  337.  
  338.            The bounds of a  dynamic  array  may  be  changed  by  executing
  339.       another  ALLOCATE  with  different  parameters.  The data stored in a
  340.       dynamic array is lost when it is reallocated.
  341.  
  342.            Dynamic arrays follow the standard Pascal  rules  for  scope  of
  343.       reference.    They   remain   allocated  until  they  are  explicitly
  344.       deallocated.
  345.  
  346.            Since dynamic arrays use storage,  they  should  be  deallocated
  347.       when they are no longer needed.
  348.  
  349.               DEALLOCATE ( dyn_array_variable );
  350.  
  351.           Examples:
  352.  
  353.               DEALLOCATE ( M );
  354.               DEALLOCATE ( TABLE );
  355.               DEALLOCATE ( INDEX );
  356.  
  357.            Dynamic arrays declared and allocated within a procedure are not
  358.       automatically deallocated on the termination of that procedure.
  359.  
  360.  
  361.     Programming Notes:
  362.  
  363.         1.  Dynamic  arrays  may  not  be  referenced  as  structures. Only
  364.           elements of dynamic arrays may be referenced in programs.
  365.  
  366.         2. FILLCHAR should not be used to initialize dynamic arrays.
  367.  
  368.         3.  Dynamic  arrays  should  always  be  DEALLOCATED  before  being
  369.           reallocated to a different size
  370.  
  371.         4.  Full  file variables now supported.  File variables may be used
  372.           as reference parameters (indicated by VAR) but should NOT be used
  373.           as value parameters. (see section 7.)
  374.  
  375.  
  376.  
  377.  
  378.       Copy compliments of Merle Schnick              SECTION 4:  Data Types
  379. .PAè
  380.