home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / PASTUT34 / PRINCIPS.TXT < prev    next >
Text File  |  1993-06-12  |  5KB  |  113 lines

  1.                        FIRST PRINCIPLES.
  2.                        ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  3.  
  4.  Turbo Pascal is a structured, typed language.  It is ALGOL-like, using a
  5.  hierarchical structure (nesting) and free format.
  6.  
  7.  To appreciate these opening statements, a brief historical review of
  8.  high-level languages is helpful.
  9.  
  10.    1957   FORTRAN        numerically orientated - fixed format.
  11.  
  12.    1960   ALGOL          numerically orientated - structured and typed.
  13.  
  14.    1965   BASIC          simple for teaching in schools and colleges.
  15.  
  16.    1971   Pascal         for teaching program concepts and allowing
  17.                          efficient implementation of large programs.
  18.                          ALGOL-like.
  19.  
  20.    1980   Ada            designed for US Dept. of Defense. Pascal-like.
  21.  
  22.    1983   Turbo Pascal   an enhanced version of Pascal.
  23.  
  24.  FORTRAN and BASIC have fixed format, such that each statement is located
  25.  at a (fixed) point on a line after a line number, obligatory in BASIC,
  26.  optional in FORTRAN.  ALGOL introduced free format, which allows the
  27.  statements to be indented by varying amounts, so making programs more
  28.  readable.
  29.  
  30.  ALGOL also introduced 'compound statements', such that several
  31.  statements can form the body of a 'for loop' provided that they are
  32.  surrounded in 'begin-end' brackets.
  33.  
  34.  ALGOL also uses a hierarchical structure (nesting), whereby compound
  35.  statements can be executed repeatedly under the control of the 'for
  36.  loop', which itself is embedded or nested within other statements.
  37.  
  38.  Whereas with FORTRAN and BASIC, 'if' statements require the use of GOTO,
  39.  ALGOL eliminates the need for the GOTO-statement, by its implementation
  40.  of compound statements.  The 'if-then-else' statement can be similarly
  41.  accommodated and with suitable use of free format can produce a very
  42.  readable program structure, as shown below.
  43.  
  44.    IF condition THEN
  45.      BEGIN
  46.         statement 1;
  47.         ......
  48.         statement m
  49.      END
  50.    ELSE
  51.      BEGIN
  52.         statement n;
  53.         ......
  54.         statement r
  55.      END;
  56.  
  57.  
  58.  To quote Edsger Dijkstra (1968), 'The difficulty in reading programs,
  59.  which make much use of GOTO statements is a result of the "conceptual
  60.  gap" between the static structure of the program (spread out on the
  61.  page) and the dynamic structure of the corresponding computations
  62.  (spread out in time)'.
  63.  
  64.  From this observation, the Structure Principle was defined as:
  65.  
  66.    'The static structure of the program should correspond in a simple way
  67.    with the dynamic structure of the corresponding computations'.
  68.  
  69.  Whereas ALGOL introduced the concept of separate data types such as
  70.  integer, real and Boolean, Pascal is even more strongly typed, including
  71.  character, string and pointer types, etc.  Integer and real data types
  72.  are further subdivided by size and range.  The purpose of data typing
  73.  is to avoid errors and ambiguities at run-time, when for example 5.999
  74.  should really be 6 for correct decision making within the program.
  75.  
  76.  It follows that all variables must be declared and typed at the start of
  77.  the program.  In fact, all labels, constants, user-defined types and
  78.  variables must be predeclared, together with any procedures and
  79.  functions.  It is also important to initialize all variables, so as to
  80.  ensure that spurious values are not acquired from the old contents of a
  81.  memory location.
  82.  
  83.  In Pascal, variable names can be of any length and are chosen to be
  84.  meaningful to the reader.  An assignment (i.e. giving a value to a memory
  85.  location defined by a variable name) is indicated by := 
  86.  
  87.  With two exceptions, statements must be separated by a semi-colon (;),
  88.  although one is not needed before END, but if included only implies a
  89.  'null' statement.  The exceptions are that a semi-colon is not placed
  90.  between END and ELSE in an IF-THEN-ELSE structure and the last END in the
  91.  program or unit is followed by a period (.). 
  92.  
  93.  
  94.  The text of the program is not 'case' sensitive, lower case being used in
  95.  most instances.  In the examples above, capitals have been used on
  96.  occasions to highlight 'reserved' words like BEGIN and END.
  97.  
  98.  All implementations of Pascal are based on 'Pascal User Manual and
  99.  Report' 1975 by Kathleen Jensen and Prof. Niklaus Wirth, the Pascal
  100.  originator.
  101.  
  102.                e.g.  UCSD    ISO    ANSI    Turbo
  103.  
  104.  Syntactic errors are found at compile time, semantic errors at run time
  105.  and logical errors are detected in Turbo Pascal by using the 'watch'
  106.  window and 'tracing', facilities which are available in the 'Integrated
  107.  Development Environment', which is one of the most helpful features of
  108.  Turbo Pascal.
  109.  
  110.  
  111.  PRINCIPS.TXT
  112.  1.3.90
  113.