home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug003.arc / PASCAL.001 < prev    next >
Text File  |  1979-12-31  |  7KB  |  150 lines

  1.                        PASCAL_FOR_BASIC_PROGRAMMERS.
  2.                                                   
  3.                                Dixon Kenney.
  4.  
  5.                                   PART I.
  6.  
  7.      Iεá thi≤á serie≤á oµá articles¼á ╔ wil∞ attemptinτ t∩á teacΦá yo⌡á thσ ì
  8. programminτá languagσá calleΣá Pascal«á  However¼á ╔á wil∞á bσá makinτá tw∩ ì
  9. assumption≤ -
  10.  
  11.      i⌐á  Yo⌡ alread∙ kno≈ ho≈  t∩ prograφ iε Basiπ - a⌠ leas⌠á enougΦ ì
  12.           to write moderately complex programs; and
  13.      ii⌐  thσ versioε oµ Pasca∞ useΣ i≤ "Turb∩  Pascal"¼ whicΦ i≤ ver∙ ì
  14.           suitablσ fo≥ thσ Microbee¼ anΣ i≤ solΣ b∙ A.T« fo≥ thei≥ ne≈ ì
  15.           3.5 inch drives.
  16.  
  17. Let's look at a very simple Pascal program -
  18.  
  19. á1áááá Prograφ Banking_1a;
  20.  
  21.  3áááá√ *¬ Thi≤ prograφ take≤ ß customer'≤ accoun⌠ number¼ namσ and
  22. á4áááá  *¬ openinτ balance¼á anΣ print≤ thσ informatioε t∩ thσ 
  23.  5      ** screeε }ì
  24.  
  25.  7  áá√ *¬ Declaratioε Par⌠ }
  26.  
  27. á9ááááConst
  28.  
  29. 11áááá  CustNamσ  ╜ 'FRE─ NURK';
  30. 12áááá  AccNuφ    ╜ 7666;
  31. 13áááá  OpBalancσ ╜ 568.72;
  32.  
  33. 15ááá√ *¬ Prograφ Bod∙ }
  34.  
  35. 17ááááBegin
  36.  
  37. 19áááá  ClrScr;
  38. 20áááá  Writeln╗  Writeln;
  39. 21áááá  Writeln('Custome≥ Namσ  ║ ':18¼ CustName);
  40. 22áááá  Writeln('Accoun⌠ Numbe≥ ║ ':18¼ AccNum);
  41. 23áááá  Writeln('Openinτ Balance║ ':18¼ OpBalance:8:2)
  42.  
  43. 25ááááEnd«    √ *¬ Prograφ Bankinτ 1ß }
  44.  
  45. NOTE║á Thσ linσ number≤ arσ NO╘ par⌠ oµ thσ program«  The∙ arσ therσ simpl∙ ì
  46. t∩ hel≡ referencσ thσ particula≥ line≤ iε thσ program.
  47.  
  48.      Therσá arσ │ part≤ t∩ ever∙ prograφ writteε iε Pascal«á Thσ firs⌠ par⌠ ì
  49. i≤ thσ Prograφ heading«  Thi≤ i≤ linσ ▒ oµ thi≤ program« Thσ seconΣ par⌠ i≤ ì
  50. calleΣá thσ Declaratioε part«á  Iε Pascal¼á i⌠ i≤ necessaryô t∩á definσá al∞ ì
  51. variable≤ anΣ constant≤ beforσ the∙ arσ used«  
  52.  
  53. áááááááááIε BASIC¼á al∞ variable≤ anΣ constant≤ arσ declareΣ ì
  54. ááááááááá"oεá thσ runó - a⌠ an∙ timσ yo⌡ caε sa∙ LE╘ ┴ ╜ 10¼ ì
  55. áááááááááor LET A1$ = "FRED".
  56.  
  57.      Iεá thσá Declaratioεá part¼á thσ Pasca∞á programme≥á define≤á al∞á hi≤ ì
  58. constant≤á anΣá give≤ theφ thei≥ values╗á define≤ al∞á hi≤á variables¼á anΣ ì
  59. declare≤ wha⌠ typσ oµ datuφ eacΦ onσ is╗á define≤ hi≤ labels¼ function≤ anΣ ìèprocedures«á  Onl∙á theεá caεá thesσ value≤ bσ useΣ iεá thσá program«á  Thσ ì
  60. Declaratioε par⌠ oµ thi≤ prograφ i≤ iε line≤ 9-11«á  Thσ thirΣ par⌠ oµá thσ ì
  61. prograφ i≤ thσ Prograφ Body¼á thσ executablσ part«  Here¼ i⌠ begin≤ a⌠ linσ ì
  62. 17¼ anΣ finishe≤ a⌠ linσ 25«  
  63.  
  64.      Comment≤á ma∙á bσá placeΣá anywherσ iε ßá Pasca∞á program«á  The∙á arσ ì
  65. delimiteΣ witΦ thσ √ anΣ ² sign≤  Alternatively¼á yo⌡ caε usσ (¬ anΣ *⌐á iµ ì
  66. thσ firs⌠ pai≥ arσ no⌠ oε you≥ computer«á  However¼ a≤ witΦ BASIC¼ comment≤ ì
  67. arσá ignoreΣá iε thσ prograφ executioε - the∙ arσ therσ simpl∙ t∩ hel≡á thσ ì
  68. humaε programmer.
  69.  
  70.      Nearl∙ ever∙ statemen⌠ i≤ finisheΣ witΦ thσ semi-colon«á Thi≤ i≤á useΣ ì
  71. a≤á ß statemen⌠ SEPARATOR¼á no⌠ a≤ ß terminator«á  Consequently¼á therσ arσ ì
  72. certaiεá occasion≤ wheε i⌠ i≤ unnecessary¼á anΣ other≤ wheε it≤á appearancσ ì
  73. wil∞á causσ ß Synta° error«á  I⌠ i≤ neve≥ used¼á fo≥á exam-ple¼á afte≥á thσ ì
  74. reserveΣá worΣ BEGI╬ o≥ iε fron⌠ oµ thσ reserveΣ worΣ EN─ (comparσ line≤ 1╖ ì
  75. anΣ 23).
  76.  
  77.      Iεá BASIC¼á thσ statemen⌠ separato≥ i≤ eithe≥ thσ coloε o≥á thσá CR/L╞ ì
  78. sequence.
  79.  
  80.           Now, lets look at the various lines in turn.
  81.  
  82. Line_1ôá - thσá Prograφ headinτ statement«á  Thσ worΣ PROGRA═ i≤ ßá reserveΣ ì
  83. worΣá - i⌠á canno⌠á bσ re-defineΣ iε an∙ circumstances«á ¿á Word≤á iεá thi≤ ì
  84. categor∙á wil∞ bσ underlineΣ iε prograφ listing≤ iε thi≤á series¼á althougΦ ì
  85. the∙á arσá no⌠á underlineΣ iε aε actua∞ program.⌐á Iεá Turb∩á Pascal¼á thi≤ ì
  86. statemen⌠ i≤ optional¼ bu⌠ i⌠ i≤ requireΣ iε jus⌠ abou⌠ ever∙ othe≥ versioε ì
  87. oµ Pascal«  Ofteε i⌠ take≤ thi≤ forφ -
  88.  
  89.           Program program_name (Input, Output);
  90.  
  91.      Thσ lis⌠ iε parenthese≤ followinτ thσ prograφ namσ i≤ ß lis⌠ oµ files«  ì
  92. Pasca∞á see≤ everythinτ a≤ ß file¼á includinτ device≤ sucΦ a≤ thσá keyboarΣ ì
  93. anΣ thσ VDU«á  INPU╘ i≤ thσ logica∞ devicσ CON:¼ whicΦ iε nearl∙ ever∙ casσ ì
  94. i≤ thσ Keyboard¼á althougΦ i⌠ caε bσ redefined«  OUTPU╘ i≤ als∩ thσ logica∞ ì
  95. devicσ CON:¼á whicΦ herσ i≤ thσ VDU«á  Again¼á i⌠ caε bσ redefined«á  Othe≥ ì
  96. file≤ ma∙ als∩ bσ mentioned«  Almos⌠ always¼ thesσ wil∞ bσ file≤ oε disk.
  97.  
  98.      Lines_9-13.ôá  Iε thσ Declaratioε  part¼á wσ arσ defininτ constant≤á wσ ì
  99. wil∞ usσ iε thσ program«  Thσ Constan⌠ declaratioε sectioε i≤ headeΣ b∙ thσ ì
  100. reserveΣ worΣ CONST«  EacΦ constan⌠ i≤ defineΣ iε thi≤ wa∙ -
  101.  
  102.           constant_label = value ;
  103.  
  104.      Noticσá tha⌠ eacΦ declaratioε i≤ terminateΣ b∙ ß semi-colon¼á althougΦ ì
  105. thσ worΣ CONS╘ i≤ not«á  Thσ typσ oµ thσ constan⌠ - whethe≥ i⌠ i≤ ßá strinτ ì
  106. o≥á ß numeriπ constan⌠ - i≤ determineΣ b∙ thσ valuσ assigneΣ t∩ thσá label«  ì
  107. Constant≤ ma∙ no⌠ bσ changeΣ b∙ an∙ subsequen⌠ statemen⌠ iε thσ program.
  108.  
  109.      Lines_17-25.ôá  Thi≤ i≤ thσ maiε bod∙ oµ thσ program«á  I⌠ i≤ delimiteΣ ì
  110. b∙ thσ reserveΣ word≤ BEGI╬ anΣ END«á  Noticσ thσ perioΣ followinτ thσ worΣ ì
  111. EN─á - i⌠á i≤ thσ onl∙ timσ ß perioΣ i≤ useΣ iεá thσá program¼á unless¼á oµ ì
  112. course¼á i⌠ i≤ par⌠ oµ somσ data«  Thesσ tw∩ word≤ arσ als∩ useΣ t∩ delimi⌠ ì
  113. ßá grou≡á oµá statement≤á whicΦ makσ u≡ ßá compounΣá statemen⌠á withiεá thσ ì
  114. program«á  S∩ therσ ma∙ bσ quitσ ß fe≈ BEGIN≤ anΣ END≤ iε ß program«á  EacΦ ì
  115. BEGI╬ mustô havσ ß correspondinτ END.
  116.  
  117. è     Linσá 2░á show≤ tha⌠ statement≤ d∩ no⌠ neeΣ t∩ bσ oε ßá separatσá linσ ì
  118. froφá eacΦá othe≥ - thesσ tw∩ arσ separateΣ b∙á thσá semi-colon«á  However¼ ì
  119. statement≤ arσ ofteε writteε onσ t∩ ß linσ iε orde≥ t∩ aiΣ readabil-ity.
  120.  
  121.      Linσ 1╣ i≤ thσ equivalen⌠ oµ BASIC'≤ CL╙ - i⌠ clear≤ thσ screen«  Thi≤ ì
  122. worΣ i≤ peculia≥ t∩ Turb∩ Pasca∞ - iε othe≥ versioε yo⌡ woulΣ probabl∙ havσ ì
  123. t∩ prin⌠ thσ ASCI╔ characte≥ 2╢ █ ^┌ ▌ t∩ achievσ this.
  124.  
  125.      Line≤á 20-23«á  Thσá procedurσ WRITEL╬ i≤ equivalen⌠ t∩ BASIC'≤á PRINTÖ ì
  126. statement«  Iε linσ 20¼ i⌠ i≤ a≤ iµ wσ haΣ written
  127.  
  128.                20 PRINT : PRINT
  129.  
  130.      Likσá PRINT¼á WRITEL╬ caε havσ aε outpu⌠ lis⌠ oµ string≤ ¿á whicΦá arσ ì
  131. encloseΣ iε singlσ quotσ marksô - █ º ▌ )¼á constant≤ o≥ variablσ labels¼ a≤ ì
  132. iε linσ 21¼ fo≥ example«  Item≤ iε thσ lis⌠ arσ separateΣ b∙ commas.
  133.  
  134. áááááááááDon'⌠ confusσ thσ usσ oµ thσ commß witΦ BASIC'╙ usσ ì
  135. áááááááááoµ it«á  Iε BASIC¼á i⌠ i≤ useΣ t∩ tabulatσ data¼ iε ì
  136. áááááááááconjunctioε witΦ thσ semi-colon«á Iε PASCAL¼á i⌠ i≤ ì
  137. ááááááááásimpl∙ ß separator¼ witΦ n∩ tabulatioε meaning«  Bσ ì
  138. ááááááááácareful¼á too¼á oµ thσ differencσ iε thσ usσ oµ thσ ì
  139. ááááááááácolon, which will now be explained.
  140.  
  141.      Thσá coloε iε thσ WRITEL╬ statemen⌠ function≤ a≤ ß fielΣ widtΦá indicß ì
  142. tor«á  Iε linσ 22¼ thσ strinτ Accoun⌠ Numbe≥ :Ö wil∞ appear¼ lef⌠ justified¼ ì
  143. iεá ßá fielΣá 1╕á column≤ wide«á  Thi≤ mean≤ tha⌠ therσ i≤ n∩á neeΣá fo≥á ß ì
  144. tabulatioε functioε equivalen⌠ t∩ TAB(⌐ iε BASIC«  Iε Linσ 23¼ thσ valuσ iε ì
  145. OpBalanceÖá wil∞ bσ printed¼á righ⌠ justified¼á  iε ß fielΣ ╕ column≤á wide¼ ì
  146. witΦ ▓ decima∞ places«á  OpBalance:8:2Ö i≤ equivalen⌠ t∩ MicroWorlΣá Basic'≤ ì
  147. [F8.▓ O1]¼ o≥ MicroSoft'≤ PRIN╘ USINGÖ statements.
  148.  
  149.                                END PART ONE
  150.