home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / zsus / z3help / t.lbr / TP.HZP / TP.HLP
Encoding:
Text File  |  1991-11-18  |  19.3 KB  |  423 lines

  1. ;
  2.                        Help for Turbo Pascal (v3.0)                           
  3.  
  4. A- Introduction                         / Logical Devices   
  5. B- Basic data types                     | Standard file I/O
  6. C- Constants                            | Pointers
  7. D- Type conversion                      | Including files
  8. E- Predefined variables                 | Overlays
  9. F- Operators                          L-| Chain and Execute
  10. G- Compiler directives                  | Assembly routines
  11. H- Procedures and Functions             | Internal representation of basic
  12.    (including forward declarations)     |    data types
  13. I- Identifiers and Types                | The heap and the stacks
  14. J- String related routines              | Interrupt Routines in Turbo Pascal
  15. K- Reserved Words                       \ Run-time and I/O errors
  16. :A
  17.                                  Introduction                                 
  18.  
  19.  
  20.     Turbo  Pascal is a Pascal language implementation written  by  Borland 
  21. International.   This  file is written for the user who is already  reasonably 
  22. familiar with Pascal, and just wants a reference for the deeper darker secrets 
  23. of this implementation of the language.
  24.      This  file is intended to be a quick reference for turbo,  for those  who 
  25. are all ready familiar with Pascal, but need technical reference material.
  26.      If  you  can't  find  what you are looking for  anywhere  else,  try  the 
  27. reserved  words  list.   All built in procedures are discussed there  to  some 
  28. extent.  If it isn't there, then it isn't anywhere.
  29. :B
  30.                            Basic Data Types - 1/2                             
  31.  
  32.  
  33. REAL       Reals  are  in the range 1E+38 to 1E-38  and  0.  The  mantissa  is 
  34. approximately 11 significant digits. Reals occupy 6 bytes of memory.  Overflow 
  35. in real calculations will cause an error and stop program execution.
  36.  
  37. INTEGER    Integers  range  from -32768 to 32767.  They require two  bytes  of 
  38. memory. Overflow in arithmetic operations is not detected.
  39.  
  40. BYTE       Bytes are in the range 0..255.  They are compatible  with  Integers 
  41. except as parameters, since BYTES require only 1 byte of memory.
  42.  
  43. BOOLEAN    Booleans have only the values TRUE and FALSE.  Each occupies a byte 
  44. of memory. Ord(FALSE)=0, Ord(TRUE)=1.
  45.  
  46. CHAR       Chars,  like  bytes,  are in the range 0..255,  but  unlike  bytes, 
  47. represent an ASCII character.
  48.                            Basic Data Types - 2/2                             
  49.  
  50.  
  51. STRING     An  array  type of characters which can be referred to as  a  mass. 
  52. Strings  are dynamic,  but are given an initial maximum length between  1  and 
  53. 255.  Strings always occupy their maximum length plus 1 bytes. The first byte, 
  54. which  can  be  referenced as StringVar[0],  holds the current length  of  the 
  55. string.
  56.  
  57. ARRAYS    A generalized array,  holds exactly N * the size of its  constituant 
  58. subparts, where N is the number of elements in the array.
  59. :C
  60.                               Constants - 1/3                                 
  61.  
  62.      Named  constants,  in  addition  to the standard method,  may  be  typed; 
  63. assuming any of the basic data types.  The sytax is:
  64. ______________________________________________________________________________
  65.  
  66. Program ...     ;
  67. Const
  68.      var:type=value;
  69. ...
  70. ______________________________________________________________________________
  71.  
  72.      Values  must be unambiguous constant values.   The variables  named  will 
  73. then  be initialized to the constant value on each distinct run (ie:  new load 
  74. into memory).   Such constants may have their values changed, but will only be 
  75. initialized at the next distinct load (ie:  compilation,  or load into  memory 
  76. from a com file)  
  77.                                Constants - 2/3                                
  78.  
  79. Representing constants:
  80.  
  81.      Numerical  (ie:  unnamed constants) may be included inline.   There are a 
  82. variety of methods for representing these values.
  83. ______________________________________________________________________________
  84.      Ascii:
  85.           #num      if num is constant, then #num is the char corresponding
  86.           ^char     ^char is the control value implied
  87. eg:
  88.           writeln('This is on'^M#10'two lines');
  89. ______________________________________________________________________________
  90.      Hex:
  91.           $num      if num is a legal hex constant then it can be used
  92. eg:
  93.           for i:=$0 to $FF do mem[i+ofs]:=0;
  94. ______________________________________________________________________________
  95.                                Constants - 3/3                                
  96.  
  97.      Strings:
  98.           'string'  Any sequence of ascii characters inside quotes.
  99.                     Single quotes may be built by inserting two quotes.
  100.                     Null strings may be built by using two quotes alone.
  101. eg:
  102.           repeat read(answer) until answer<>'';
  103.           writeln('Hello');
  104.           writeln('Don''t go, please!');
  105. ______________________________________________________________________________
  106.      Sets:
  107.           [const1..const2]
  108.                     const1 and const2 represent the upper and lower bounds of
  109.                     the string.
  110. eg:
  111.           repeat read(kbd,c) until c in [^A..'Z'];
  112. :D
  113.                                 Type Conversion                               
  114.  
  115.      All  ordinal scalars may be converted to one another by using their  type 
  116. as a function name.  (Eg:  Char(65)='A', Integer('7')=55).  This includes user 
  117. defined  ordinal types,  but does NOT include reals.   Subranges will  not  be 
  118. mapped.   Conversion  is  done simply by relaxing  typing  constraints.   (Now 
  119. you've seen everything.  Pascal with weak typing?
  120.      Types  are automatically converted when calling a function or subroutine. 
  121. Ascii  and Byte types,  however,  are incompatible and will be tagged  by  the 
  122. compiler  unless  they  are  explicitly converted.   Bytes  and  Integers  are 
  123. assignment,  and  value parameter compatible,  however they are NOT  reference 
  124. compatible.   I  don't recommend ever passing bytes to integers or integers to 
  125. bytes as VAR parameters for this reason.
  126.      When  comparing  Bytes and Integers,  it is best to force  conversion  to 
  127. happen.  Otherwize results will be unpredictable.
  128.  
  129. EG:
  130.      If i_byte = Byte( j_integer ) then ...
  131.  
  132. NOTE: To convert integers to pointers, use the function Ptr(I):P
  133. :E
  134.                                Predefined Variables                           
  135.  
  136.  
  137.      Turbo provides several built in constants which cannot be redefined, as a 
  138. measure of convenience.  
  139.      Pi has the value useful to such a thing
  140.      True, False are boolean constants
  141.      mem[] is an array of all memory
  142.      port[] is an array of all z80 ports
  143.      nil is the pointer equivalent of zero
  144.      MaxInt is 32767
  145. :F
  146.                                 Operators - 1/4                               
  147.  
  148.  
  149.      This is a list of all operators available in Turbo Pascal.   There is not 
  150. an operator for finding the result of a power operation.   However,  a  simple 
  151. function will provide results correct to several significant digits.
  152. ______________________________________________________________________________
  153. FORTRAN
  154.           VALU = MU ** ZETA
  155. ______________________________________________________________________________
  156. PASCAL
  157.          
  158. Function POWER(BASE,EXPN:Real):Real;
  159. Begin
  160.      POWER:=exp(EXPN * ln( BASE ));
  161. End;
  162.  
  163. ...
  164.      VALU:=POWER(MU,ZETA);
  165. ...
  166.                                 Operators - 2/4                               
  167.  
  168.  
  169.      Operators  of equal precedence are evaluated left to right.   The results 
  170. of  certain operators (so called math operators) depend on the type  of  their 
  171. source.  This table lists all possible sources, and outcomes.
  172. _______________________________________
  173.  
  174. Operands            Result   
  175. Integer,Integer     Integer
  176. Integer,Real        Real
  177. Real,Real           Real
  178. _______________________________________
  179.                                 Operators - 3/4                               
  180.  
  181. Operator  Operation           Operand types       Result    Precedence
  182. ------------------------------------------------------------------------------
  183. + Unary   sign identity       Integer, Real       Tbl 1     1
  184. - unary   sign inversion      Integer, Real       Tbl 1     1
  185. not       bitwize not         Boolean, Integer    Tbl 1     2
  186. *         multiplication      Integer, Real       Tbl 1     3
  187.           set intersection    Set                 Set       3
  188. /         division            Integer, Real       Real      3
  189. div       integer division    Integer             Integer   3
  190. mod       modulo              Integer             Integer   3
  191. and       arithmetic and      Integer             Integer   3
  192.           logical and         Boolean             Boolean   3
  193. shl       shift left          Integer             Integer   3
  194. shr       shift right         Integer             Integer   3
  195. +         addition            Integer, Real       Tbl 1     4
  196.           concatenation       string              string    4
  197.           set union           set                 set       4
  198. -         subtraction         Integer, Real       Tbl 1     4
  199.           set difference      set                 set       4
  200.                                 Operators - 4/4                               
  201.  
  202. Operator  Operation           Operand types       Result    Precedence
  203. ------------------------------------------------------------------------------
  204. or        arithmetic or       Integer             Integer   4
  205.           logical or          Boolean             Boolean   4
  206. xor       arithmetic xor      Integer             Integer   4
  207.           logical xor         Boolean             Boolean   4
  208. =         equality            scalar              boolean   5
  209.                               string              Boolean   5
  210.                               Set                 Boolean   5
  211. <>        inequality          scalar              Boolean   5
  212.                               String              Boolean   5
  213.                               Set                 Boolean   5
  214. >=        greater or equal    scalar              Boolean   5
  215.                               String              Boolean   5
  216.           set inclusion       Set                 Boolean   5
  217. <=        Less or equal       scalar              Boolean   5
  218.                               String              Boolean   5
  219.           set inclusion       Set                 Boolean   5
  220. in*       set membership      membertype, Set     Boolean   5
  221. * only in that order.
  222. :G
  223.                             Compiler Directives - 1/2                         
  224.  
  225.  
  226.      Select  compiler directives by putting them in comments,  preceded  by  a 
  227. dollar-sign ($). E.g.:
  228. {$A+}
  229. Multiple  directives  may  be given in a single line by separating  them  with 
  230. commas. E.g.:
  231. {$B-,I+,V-}
  232. {$I SNOW.DF ,V-} (Note that the Include directive parameter must have a full
  233.                   extention or be ended with a space.)
  234.  
  235. Next Screen lists all of the options:
  236.                              Compiler Directives - 2/2                        
  237.  
  238. Option Default Description/Notes
  239. ______________________________________________________________________________
  240. A      A+      Generate absolute code (+=on, - allows recursion, but slow)
  241. B      B+      I/O selection (Use CON: or TRM: for input, +=CON:)
  242. C      C+      ^C, ^S active during I/O (+=active)
  243. I      I+      I/O error handling (+=errors handled by Turbo)
  244. I      nil     include files (e.g:{$Ifilename.ext} includes may not be nested)
  245. R      R-      index range checking (array index, subrange type
  246.            out of bounds; +=active, slows execution)
  247. V      V+      type checking of VAR parameters (+=on, esp. Strings)
  248. U      U-      ^C active during normal execution (+=active, slows run)
  249. W      W2      with statement level nesting (1-9 allowed)
  250. X      X+      array optimization (+=speed, -=size)
  251. ______________________________________________________________________________
  252.  
  253. Additionally,  the  compiler can use specific start and end  addresses.   To 
  254. specify a new start address,  get into the compiler options menu, and select 
  255. S (just type S,  even though it doesn't appear in the menu).  Similarly, for 
  256. a new end address, select E.
  257. :H
  258.                           Procedures and Functions - 1/5                      
  259.  
  260.  
  261.      Use the keywords Function and Procedure to declare these. A procedure
  262. may  return  or use zero or more values.    In turbo  Pascal,  value  passable 
  263. parameters can be:  Reals,  Integers,  Bytes,  Chars,  Sets, Strings, and User 
  264. defined ordinals.
  265.      Normally  type  checking will be done on all parameters.  To  relax  type 
  266. checking,  use  the $V compiler directive (Q.q.v.).   Type checking will  flag 
  267. attempts to pass differently sized strings.   Relaxing type checking will make 
  268. the strings function normally.   Bytes and Integers are passable directly, and 
  269. will  cause  no  parameter  errors.   Byte and  Integer  types  are  converted 
  270. automagically  before being passed.   (Integers are trucated,  or get an extra 
  271. byte of 0's)
  272.      Functions  may  use  and return zero or more values of which one  may  be 
  273. immediately assigned (:=) to a variable of the same type as the function.  The 
  274. legal return types for functions are  Sets,  Reals,  Strings,  Integers,  User 
  275. defined types, Bytes and Chars.
  276.                           Procedures and Functions - 2/5                      
  277.  
  278.      Two  special  reserved  words are provided to  make  exiting  subroutines 
  279. easier.  These are Halt; and Exit;.
  280.      Halt  stops  the program at that point and returns to CP/M  (without  any 
  281. messages).
  282.      Exit pops all local data from the stack and returns.  A function which is 
  283. exited  will  have an undefined value unless one had been assigned before  the 
  284. Exit call.   (It is normally bad form to assign a return value to the function 
  285. before  the  function end.   In many implementations,  it won't work  at  all.
  286. Turbo Pascal, however, allows the value of the function to be assigned as many 
  287. times as you like, anywhere in the function.)
  288.                           Procedures and Functions - 3/5                      
  289.  
  290. Syntax (revisited):
  291. ______________________________________________________________________________
  292.  
  293. Procedure Identifier(variable list);
  294.  
  295. Function Identifier(variable list):type;
  296. begin
  297.      ...
  298.      Identifier:=Value_to_Return;
  299. end;
  300. ______________________________________________________________________________
  301.  
  302. Note  that the attempt to retrieve the value of the function while inside  the 
  303. function is considered a recursive call,  (see compiler option A, QQV) so that 
  304. while the return value of the function can be stored any number of  times,  it 
  305. can never be retrieved.
  306.     Functions and Procedures may be forward declared (assuming they are not in 
  307. an  overlay,  or external  (q.v:  Overlays,  Assembly  programming)).  Forward 
  308. references are simple devices for creating Catch-22 procedures.) 
  309.                           Procedures and Functions - 4/5                      
  310. eg:
  311.      Program Catch_22;
  312.      Var
  313.           x:integer;
  314.      function Up(Var I:integer): Integer; forward;
  315.      function Down(Var I:integer): Integer;
  316.      begin
  317.           I:=I div 2;
  318.           Writeln(I);
  319.           if I<>1 then I:=Up(I);
  320.      end;
  321.      function Up;
  322.      begin
  323.           while I mod 2 <> 0 do 
  324.           begin
  325.                I:=I*3+1;
  326.                Writeln(I);
  327.           end;
  328.           I:=down(I);
  329.      end;
  330.                           Procedures and Functions - 5/5                      
  331.  
  332.      begin
  333.           write('Enter an Integer: ');
  334.           readln(x);
  335.           x:=Up(x);
  336.           writeln('That''s all folks');
  337.      end.
  338. ______________________________________________________________________________
  339. :I
  340.                           Identifiers and Types - 1/3                         
  341.  
  342. Type
  343.      Types  may  be Basic data types,  Arrays of types,  subranges of  scalars 
  344. combinations  of  records and all of the above.  In general  they  follow  the 
  345. Pascal Standard. Special notes follow
  346.      Identifiers may include underscores (eg: Last_User)
  347.      Absolute variables:
  348.      Variables may be declared absolute either with respect to a constant,  or 
  349. a variable (ie the location of the variable.)
  350. ______________________________________________________________________________
  351.  
  352. VAR  IOByte: Byte absolute $0003;
  353. ______________________________________________________________________________
  354.  
  355.                           Identifiers and Types - 2/3                        
  356.  
  357.      Variant records are declared as follows:
  358.      Variant  records have the advantage of using less memory,  by  overlaying 
  359. parts of the record which are never used in tandem.   In some  implementations 
  360. of  Pascal this was the only way in which to create weak typing.   If you  are 
  361. using  this for weak typing,  I suggest that you first look up type conversion 
  362. (QQV).
  363. ______________________________________________________________________________
  364.  
  365. type 
  366.      variant_type = record
  367.           nonvariant_part: type;
  368.           more_nonvariant_part: type;
  369.           case optional_var : scalar_type of
  370.                scalar_constant: (variant_1:type;
  371.                          variant_1_continued:type
  372.                );
  373.                another_scalar: (variant:type);
  374.     end; {record}
  375.                           Identifiers and Types - 3/3                         
  376.  
  377.  
  378.      Labels are the last biggie.  In the realm of labels there are three laws. 
  379. One of them applies to Turbo Pascal, the other two are relaxed.
  380.  
  381. 1.   Labels shall be declared first.   In Turbo Pascal, Labels can be declared 
  382. anywhere  outside  of the begin end pairs (as can,  in fact,  any  declaration 
  383. block).   Label  declarations always correspond to the  current  block,  which 
  384. brings us to the next rule.
  385.  
  386. 2.   Gotos  shall not jump out of the current block.   Such an  attempt  would 
  387. leave  the  stack in an undefined state.   The compiler catches this  sort  of 
  388. error for you.  See the Halt and Exit functions instead.
  389.  
  390. 3.    All labels are numeric.   In Turbo Pascal,  a label can be any otherwize 
  391. unused and legal identifier, in addition to the normal numerical kind.
  392. :J
  393.                           String Related Routines - 1/2                       
  394.  
  395. Val(St; Var Num; Var Pos);
  396.      Change string St into its numeric value Num;  flagging the first  illegal 
  397. character in Pos if any.  If Pos=0 then conversion was successful.  The number 
  398. may not be padded on the left or right with any non-numeric characters.
  399.  
  400. Str(Num; Var St);
  401.      Change  numeric variable Num into a string (optionally,  format  commands 
  402. can be used, much like with writeln.
  403.  
  404. Delete
  405.  
  406. Insert
  407.  
  408. Copy(st,Pos,Num)
  409.      Copies a substring of st starting at Pos and Num long to it's return.  If 
  410. Pos>length  of  string then '' is returned.  If Pos isn't in [0..255]  then  a 
  411. runtime error is created.
  412.                           String Related Routines - 2/2                       
  413.  
  414. Concat(st,st,...)
  415.      Also the '+' operator.   Concatenates strings, returning the concatenated 
  416. result as its value.
  417.  
  418. Length(st)
  419.      
  420. Pos(Obj,Target)
  421.      Returns zero if match isn't found
  422. :K :TP3
  423. :L :TP2