home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
mbug
/
mbug003.arc
/
PASCAL.001
< prev
next >
Wrap
Text File
|
1979-12-31
|
7KB
|
150 lines
PASCAL_FOR_BASIC_PROGRAMMERS.
Dixon Kenney.
PART I.
Iεá thi≤á serie≤á oµá articles¼á ╔ wil∞ attemptinτ t∩á teacΦá yo⌡á thσ ì
programminτá languagσá calleΣá Pascal«á However¼á ╔á wil∞á bσá makinτá tw∩ ì
assumption≤ -
i⌐á Yo⌡ alread∙ kno≈ ho≈ t∩ prograφ iε Basiπ - a⌠ leas⌠á enougΦ ì
to write moderately complex programs; and
ii⌐ thσ versioε oµ Pasca∞ useΣ i≤ "Turb∩ Pascal"¼ whicΦ i≤ ver∙ ì
suitablσ fo≥ thσ Microbee¼ anΣ i≤ solΣ b∙ A.T« fo≥ thei≥ ne≈ ì
3.5 inch drives.
Let's look at a very simple Pascal program -
á1áááá Prograφ Banking_1a;
3áááá√ *¬ Thi≤ prograφ take≤ ß customer'≤ accoun⌠ number¼ namσ and
á4áááá *¬ openinτ balance¼á anΣ print≤ thσ informatioε t∩ thσ
5 ** screeε }ì
7 áá√ *¬ Declaratioε Par⌠ }
á9ááááConst
11áááá CustNamσ ╜ 'FRE─ NURK';
12áááá AccNuφ ╜ 7666;
13áááá OpBalancσ ╜ 568.72;
15ááá√ *¬ Prograφ Bod∙ }
17ááááBegin
19áááá ClrScr;
20áááá Writeln╗ Writeln;
21áááá Writeln('Custome≥ Namσ ║ ':18¼ CustName);
22áááá Writeln('Accoun⌠ Numbe≥ ║ ':18¼ AccNum);
23áááá Writeln('Openinτ Balance║ ':18¼ OpBalance:8:2)
25ááááEnd« √ *¬ Prograφ Bankinτ 1ß }
NOTE║á Thσ linσ number≤ arσ NO╘ par⌠ oµ thσ program« The∙ arσ therσ simpl∙ ì
t∩ hel≡ referencσ thσ particula≥ line≤ iε thσ program.
Therσá arσ │ part≤ t∩ ever∙ prograφ writteε iε Pascal«á Thσ firs⌠ par⌠ ì
i≤ thσ Prograφ heading« Thi≤ i≤ linσ ▒ oµ thi≤ program« Thσ seconΣ par⌠ i≤ ì
calleΣá thσ Declaratioε part«á Iε Pascal¼á i⌠ i≤ necessaryô t∩á definσá al∞ ì
variable≤ anΣ constant≤ beforσ the∙ arσ used«
áááááááááIε BASIC¼á al∞ variable≤ anΣ constant≤ arσ declareΣ ì
ááááááááá"oεá thσ runó - a⌠ an∙ timσ yo⌡ caε sa∙ LE╘ ┴ ╜ 10¼ ì
áááááááááor LET A1$ = "FRED".
Iεá thσá Declaratioεá part¼á thσ Pasca∞á programme≥á define≤á al∞á hi≤ ì
constant≤á anΣá give≤ theφ thei≥ values╗á define≤ al∞á hi≤á variables¼á anΣ ì
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σ ì
Declaratioε par⌠ oµ thi≤ prograφ i≤ iε line≤ 9-11«á Thσ thirΣ par⌠ oµá thσ ì
prograφ i≤ thσ Prograφ Body¼á thσ executablσ part« Here¼ i⌠ begin≤ a⌠ linσ ì
17¼ anΣ finishe≤ a⌠ linσ 25«
Comment≤á ma∙á bσá placeΣá anywherσ iε ßá Pasca∞á program«á The∙á arσ ì
delimiteΣ witΦ thσ √ anΣ ² sign≤ Alternatively¼á yo⌡ caε usσ (¬ anΣ *⌐á iµ ì
thσ firs⌠ pai≥ arσ no⌠ oε you≥ computer«á However¼ a≤ witΦ BASIC¼ comment≤ ì
arσá ignoreΣá iε thσ prograφ executioε - the∙ arσ therσ simpl∙ t∩ hel≡á thσ ì
humaε programmer.
Nearl∙ ever∙ statemen⌠ i≤ finisheΣ witΦ thσ semi-colon«á Thi≤ i≤á useΣ ì
a≤á ß statemen⌠ SEPARATOR¼á no⌠ a≤ ß terminator«á Consequently¼á therσ arσ ì
certaiεá occasion≤ wheε i⌠ i≤ unnecessary¼á anΣ other≤ wheε it≤á appearancσ ì
wil∞á causσ ß Synta° error«á I⌠ i≤ neve≥ used¼á fo≥á exam-ple¼á afte≥á thσ ì
reserveΣá worΣ BEGI╬ o≥ iε fron⌠ oµ thσ reserveΣ worΣ EN─ (comparσ line≤ 1╖ ì
anΣ 23).
Iεá BASIC¼á thσ statemen⌠ separato≥ i≤ eithe≥ thσ coloε o≥á thσá CR/L╞ ì
sequence.
Now, lets look at the various lines in turn.
Line_1ôá - thσá Prograφ headinτ statement«á Thσ worΣ PROGRA═ i≤ ßá reserveΣ ì
worΣá - i⌠á canno⌠á bσ re-defineΣ iε an∙ circumstances«á ¿á Word≤á iεá thi≤ ì
categor∙á wil∞ bσ underlineΣ iε prograφ listing≤ iε thi≤á series¼á althougΦ ì
the∙á arσá no⌠á underlineΣ iε aε actua∞ program.⌐á Iεá Turb∩á Pascal¼á thi≤ ì
statemen⌠ i≤ optional¼ bu⌠ i⌠ i≤ requireΣ iε jus⌠ abou⌠ ever∙ othe≥ versioε ì
oµ Pascal« Ofteε i⌠ take≤ thi≤ forφ -
Program program_name (Input, Output);
Thσ lis⌠ iε parenthese≤ followinτ thσ prograφ namσ i≤ ß lis⌠ oµ files« ì
Pasca∞á see≤ everythinτ a≤ ß file¼á includinτ device≤ sucΦ a≤ thσá keyboarΣ ì
anΣ thσ VDU«á INPU╘ i≤ thσ logica∞ devicσ CON:¼ whicΦ iε nearl∙ ever∙ casσ ì
i≤ thσ Keyboard¼á althougΦ i⌠ caε bσ redefined« OUTPU╘ i≤ als∩ thσ logica∞ ì
devicσ CON:¼á whicΦ herσ i≤ thσ VDU«á Again¼á i⌠ caε bσ redefined«á Othe≥ ì
file≤ ma∙ als∩ bσ mentioned« Almos⌠ always¼ thesσ wil∞ bσ file≤ oε disk.
Lines_9-13.ôá Iε thσ Declaratioε part¼á wσ arσ defininτ constant≤á wσ ì
wil∞ usσ iε thσ program« Thσ Constan⌠ declaratioε sectioε i≤ headeΣ b∙ thσ ì
reserveΣ worΣ CONST« EacΦ constan⌠ i≤ defineΣ iε thi≤ wa∙ -
constant_label = value ;
Noticσá tha⌠ eacΦ declaratioε i≤ terminateΣ b∙ ß semi-colon¼á althougΦ ì
thσ worΣ CONS╘ i≤ not«á Thσ typσ oµ thσ constan⌠ - whethe≥ i⌠ i≤ ßá strinτ ì
o≥á ß numeriπ constan⌠ - i≤ determineΣ b∙ thσ valuσ assigneΣ t∩ thσá label« ì
Constant≤ ma∙ no⌠ bσ changeΣ b∙ an∙ subsequen⌠ statemen⌠ iε thσ program.
Lines_17-25.ôá Thi≤ i≤ thσ maiε bod∙ oµ thσ program«á I⌠ i≤ delimiteΣ ì
b∙ thσ reserveΣ word≤ BEGI╬ anΣ END«á Noticσ thσ perioΣ followinτ thσ worΣ ì
EN─á - i⌠á i≤ thσ onl∙ timσ ß perioΣ i≤ useΣ iεá thσá program¼á unless¼á oµ ì
course¼á i⌠ i≤ par⌠ oµ somσ data« Thesσ tw∩ word≤ arσ als∩ useΣ t∩ delimi⌠ ì
ßá grou≡á oµá statement≤á whicΦ makσ u≡ ßá compounΣá statemen⌠á withiεá thσ ì
program«á S∩ therσ ma∙ bσ quitσ ß fe≈ BEGIN≤ anΣ END≤ iε ß program«á EacΦ ì
BEGI╬ mustô havσ ß correspondinτ END.
è Linσá 2░á show≤ tha⌠ statement≤ d∩ no⌠ neeΣ t∩ bσ oε ßá separatσá linσ ì
froφá eacΦá othe≥ - thesσ tw∩ arσ separateΣ b∙á thσá semi-colon«á However¼ ì
statement≤ arσ ofteε writteε onσ t∩ ß linσ iε orde≥ t∩ aiΣ readabil-ity.
Linσ 1╣ i≤ thσ equivalen⌠ oµ BASIC'≤ CL╙ - i⌠ clear≤ thσ screen« Thi≤ ì
worΣ i≤ peculia≥ t∩ Turb∩ Pasca∞ - iε othe≥ versioε yo⌡ woulΣ probabl∙ havσ ì
t∩ prin⌠ thσ ASCI╔ characte≥ 2╢ █ ^┌ ▌ t∩ achievσ this.
Line≤á 20-23«á Thσá procedurσ WRITEL╬ i≤ equivalen⌠ t∩ BASIC'≤á PRINTÖ ì
statement« Iε linσ 20¼ i⌠ i≤ a≤ iµ wσ haΣ written
20 PRINT : PRINT
Likσá PRINT¼á WRITEL╬ caε havσ aε outpu⌠ lis⌠ oµ string≤ ¿á whicΦá arσ ì
encloseΣ iε singlσ quotσ marksô - █ º ▌ )¼á constant≤ o≥ variablσ labels¼ a≤ ì
iε linσ 21¼ fo≥ example« Item≤ iε thσ lis⌠ arσ separateΣ b∙ commas.
áááááááááDon'⌠ confusσ thσ usσ oµ thσ commß witΦ BASIC'╙ usσ ì
áááááááááoµ it«á Iε BASIC¼á i⌠ i≤ useΣ t∩ tabulatσ data¼ iε ì
áááááááááconjunctioε witΦ thσ semi-colon«á Iε PASCAL¼á i⌠ i≤ ì
ááááááááásimpl∙ ß separator¼ witΦ n∩ tabulatioε meaning« Bσ ì
ááááááááácareful¼á too¼á oµ thσ differencσ iε thσ usσ oµ thσ ì
ááááááááácolon, which will now be explained.
Thσá coloε iε thσ WRITEL╬ statemen⌠ function≤ a≤ ß fielΣ widtΦá indicß ì
tor«á Iε linσ 22¼ thσ strinτ Accoun⌠ Numbe≥ :Ö wil∞ appear¼ lef⌠ justified¼ ì
iεá ßá fielΣá 1╕á column≤ wide«á Thi≤ mean≤ tha⌠ therσ i≤ n∩á neeΣá fo≥á ß ì
tabulatioε functioε equivalen⌠ t∩ TAB(⌐ iε BASIC« Iε Linσ 23¼ thσ valuσ iε ì
OpBalanceÖá wil∞ bσ printed¼á righ⌠ justified¼á iε ß fielΣ ╕ column≤á wide¼ ì
witΦ ▓ decima∞ places«á OpBalance:8:2Ö i≤ equivalen⌠ t∩ MicroWorlΣá Basic'≤ ì
[F8.▓ O1]¼ o≥ MicroSoft'≤ PRIN╘ USINGÖ statements.
END PART ONE