The Pascal Reserved Words and Required Identifiers
Total Page:16
File Type:pdf, Size:1020Kb
APPENDIX I THE PASCAL RESERVED WORDS AND REQUIRED IDENTIFIERS The following are the Pascal reserved words. Each has a special meaning and may not be redefined: AND ARRAY BEGIN CASE CONST DIV DO DOWNTO ELSE END FILE FOR FUNCTION GOTO IF IN LABEL MOD NIL NOT OF OR PACKED PROCEDURE PROGRAM RECORD REPEAT SET THEN TO TYPE UNTIL VAR WHILE WITH The following are the 'required identifiers' of the Pascallanguage. It is possible, but inadvisible, to redefine them du ring a program. INTEGER REAL CHAR BOOLEAN ABS ARCTAN CHR COS DISPOSE EOF EOLN EXP FALSE GET INPUT LN MAXINT NEW ODD ORD OUTPUT PACK PAGE PRED PUT READ READLN RESET REWRITE ROUND SIN SQR SQRT SUCC TEXT TRUE TRUNC UNPACK WRITE WRITELN The following word is a required directive and has also been assigned a special meaning in the language: FORWARD Some implementations have additional predefined functions and procedures. APPENDIX 11 SYNTAX DIAGRAMS Pascal syntax should follow the route indicated in the following diagrams. In these diagrams the following rules hold: (a) 'Letter' means any one of the 26 letters of the English alphabet.1t may be in either upper case or lower case. The Pascallanguage does not differentiate between upper case and lower case letters except within character strings. (b) 'Digit' means any one of the decimal digits 0 .. 9. (c) 'Character' me ans any one letter or digit or other symbol. In theory this means any of the printable characters in a character set such as ASCII (see Appendix IV) but in practice there are often implementation limitations. (d) All other tokens appearing within circles or boxes with semicircular ends should be reproduced in the program exactly as they appear in the diagram, except that letters may be in upper or lower case. (e) All items in solid rectangular boxes are defined in this appendix. program 241 block ~---r--~ unsigned integer ~--__ '- ./ identifier (constant identifier) 242 statement expression 1---------1 function identifier procedure identifier )------..1 unsigned integer 1----------------' 243 parameter I ist ,--------------------------, '----~I conformant array parameter specification !-,___ ....J ~---------------------------~see note 3 expression '--....lo..__ .lo.... __.l!..... __.lo.... __.lo.... __.l..j~simple expression 244 simple expression term factor - .........---------+-1 unsigned constant I-----------,.......,~ function identifier 245 type t }------~ type identifier 1-----1 simple type 246 field list variable -~-+-l variable identifier I------------------...,..-'~ field identifier array identifier record identifier field identifier pointer identifier I--------...,..-'-~ t file identifier 247 constant identifier unsigned number unsigned number u nsigned integer l+-----+l~ unsigned integer unsigned integer Note 1 The semi-colon before the END of a CASE statement was not permitted in so me earlier Pascal implementations. Note 2 The requirement for a parameter list in procedural and func tional parameters was introduced in BS 6192 : 1982. It may not be per mitted in some earlier implementations. Note 3 Conformant array parameters are a feature of Level 1 of BS 6192: 1982. They are not discussed in this book which claims to comply only with Level 0 of the Standard. APPENDIX 111 INTERACTIVE INPUT In Chapter 8 it was briefly mentioned that there are two main ways of implementing INPUT when a keyboard is used. One is direct and the other is via a line buffer. This appendix considers the two methods in more detail and the implications they have when programming for interactive operation. III.1 mE UNE BUFFER MEmOD The line buffer method requires that the < newline > key must be pressed after the called-for data has been entered. Figure III.1 shows diagram matically what is happening immediately before the < newline > key is pressed. The line buffer is acting as though it were in write mode with the keyboard supplying the data. Fig III.1 the fine buffer method of interactive input before the <newline> key is depressed: the fine buffer can be considered as a file in write mode with the arrow representing the key board's buffer variable Now is the time for all good men Une buffer Figure III.2 shows the position immediately after pressing the < newline > key. The line buffer is now in read mode and the Pascal pro gram's buffer variable is positioned to read the data. 249 Fig I1I.2 the line buffer method of interactive inputs after the <newline> key is pressed; the line buffer is in read mode and the Pascal buffer variable is positioned to read the whole line I Keyboard I EOLN Une buffer Pascal program being executed To see how this works in practice, let us look at a simple program: EBQ§BB~ CharHandling (INPUT, OUTPUT); character : CHAR; I!~§H! B~E~B! WRITE ('Input a character )'; READ (character); WRITELN ('Character is )', character); WRITELN ~~!lb character = 'X' ~~!? The result of running this program using the line buffer method is Input a character >II-f Character is )A Input a character >B-f Character is >8 Input a character >X-f Character is >X Note that each character input has been followed by the pressing of the < newline > key. The line buffer can introduce one feature that may be undesirable. Let us run the program again, but this time we shall supply more data than is needed to satisfy the first read list: 250 Input. a charact.er >RBX~ Charact.er is jA Input. a charact.er >Charact.er is >B Input. a charact.er >Charact.er is >X On the second iteration there were still two characters, Band X, in the buffer. The READ statement accepted the B without waiting for a new character to be keyed in. Similarly, on the next iteration X was accepted. The judicious use of READLN will avert the problem of unwanted data left in the buffer, but see the remarks on the use of READLN for inter active working at the end of Chapter 8. An essential feature of any interactive working is that there should be a method of correcting errors made by mis-keying. The usual way to do this is by use of a < backspace > or similar key. The great advantage of the line buffer method is that such errors can usually be corrected before the <newline> key is pressed. The corrections are made in the line buffer by the computer's operating system and no special provision is needed in the Pascal program. A dis advantage of the line buffer method is that < newline > always has to pressed. In many programs (games and computer drafting are examples) it is adefinite disadvantage not to have some form of immediate single keystoke entry. For this reasons so me implementations using a line buffer also provide an additional predefined function which scans the keyboard and, if a key is pressed, returns its value. III.2 THE DIRECT METHOn The direct method of interactive data entry is exemplified diagrammatically in Fig. 111.3. Each character value is passed straight from the keyboard to the buffer variable. If we run the above CharHandling pro gram with this method we would get the following: Input. a charact.er >RCharact.er is >A Input. a charact.er )BCharact.er is >B Input. a charact.er >XCharact.er is >X This layout differs from that obtained with the line buffer method because we have not had to press the < newline > key after entering each character. For games and similar programs the ability of the direct method to 251 Fig 111.3 the direct method of interactive input: each character is passed straight from the keyboard to the Pascal program; the pro grammer must write his or her own procedure for dealing with ,backspaced' corrections Pascal program being executed respond to the single entry of any key can be a distinct advantage. Also there is no line buffer to hold unwanted characters. The main disadvantage of this method is that for certain applications the Pascal programmer may need to provide his own procedure for the correction of keying errors. APPENDIX IV ASUBSET OF THE ACSII CODE The American Standard Code for Information Interchange is used to define the ORD values of characters in many Pascal implementations. The table on the next page lists those characters that are likely to be used generally by Pascal programmers, together with their values. 253 Ord Chr Ord Chr Ord Chr 32 < space > 64 (aJ 33 ! 65 A 97 a 34 " 66 B 98 b 35 #or f: 67 C 99 c 36 $ 68 D 100 d 37 % 69 E 101 e 38 & 70 F 102 f 39 ' (quote) 71 G 103 g 40 ( 72 H 104 h 41 ) 73 105 42 * 74 J 106 j 43 + 75 K 107 k 44 , (comma) 76 L 108 45 77 M 109 m 46 . (fuH stop) 78 N 110 n 47 / 79 0 111 0 48 0 80 P 112 P 49 1 81 Q 113 q 50 2 82 R 114 51 3 83 S 115 s 52 4 84 T 116 53 5 85 U 117 u 54 6 86 V 118 v 55 7 87 W 119 w 56 8 88 X 120 x 57 9 89 Y 121 Y 58 90 Z 122 z 59 91 [ 123 { 60 < 61 = 93 ] 125 } 62 > 94 t 63 ? In addition to the above there are several control characters that, when output to some printers, have special significance. Among these are 8 Back-space 9 Horizontal tabulate 10 Line feed 12 Form feed (to the top of next page) 13 Carriage return REFERENCES BS 6192: 1982 (1982). Computer programming language Pascal, British Standards Institution, London Huggins, E. (1979). Microprocessors and Microcomputers: Their Use and Programming, Macmillan, London and Basingstoke Jensen, K.