1 08/04/86 Multics Pascal extensions
2
3 This segment lists a number of extensions to ISO standard Pascal that
4 are implemented in the Multics version. For a list of Multics
5 implementation restrictions and incompatible deviations from the
6 standard, type "help pascal_limitations.gi". Except for the deviations
7 documented there, Multics Pascal is an upwards-compatible extension
8 that includes ISO Pascal.
9
10
11 Those extensions marked SOL belong to a set of extensions documented
12 in "The Programming Language Pascal, Specifications and
13 Implementation", AFNOR-SOL, 92080 Paris La Defense, Paris, France.
14
15 A list of Multics extensions follows. Some of them, as indicated, are
16 documented under other help topics. The remaining ones are described in
17 sections below with corresponding names.
18
19 For meaning of "fixed-string" and "dynamic-string" terms below, see
20 pascal_string.gi.info.
21
22
23 - Underscores in identifiers
24 - Octal, hexadecimal, and binary notation for integers SOL
25 - Fixed-string padding in assignment
26 - Fixed-string manipulation via "sread" and "swrite" SOL
27 - Variable initialization with $value SOL
28 - Expressions of constants in declaration of constants.
29 - Predefined constants "maxreal" and "minreal" SOL
30 - Clock, date and time functions
31 - The "log10" function
32 - The "otherwise" extension to the "case" statement
33 - Dynamic deallocation with "reset"
34 - Passing arguments to a Pascal program argc argv and stop
35 extensions
36 - The $include directive type "help pascal_compile_time.gi" SOL
37 - Conditional compilation type "help pascal_compile_time.gi"
38
39
40 - File I/O extensions type "help pascal_file_io.gi" SOL
41 The extensions are: fconnect, fclose, flush, fget, fput, fupdate.
42 - Importing and exporting variables and procedures
43 type "help pascal_separate_comp.gi" SOL
44 - Pascal parameters type "help pascal_separate_comp.gi" SOL
45 - Communication with other languages
46 type "help pascal_separate_comp.gi"
47 - Dynamic-strings
48 type "help pascal_strings.gi"
49
50
51 Underscores in identifiers:
52 Multics Pascal allows underscores in identifier names. These are not
53 allowed in standard Pascal.
54
55
56 Octal, hexadecimal, and binary notation for integers:
57 Integer constants in these bases are enclosed in quotes ' and
58 followed by the tag "o" for octal, "x" for hexadecimal, or "b" for
59 binary. For example, the statement--
60
61 i := 45;
62
63 Is equivalent to--
64
65 i := '55'o; octal
66 i := '2d'x; hexadecimal
67 i := '101101'b; binary
68
69
70 Fixed-string padding in assignment:
71 Multics Pascal allows a fixed-string packed array 1..n of char
72 to be assigned the value of a shorter fixed-string. The target is
73 padded with blanks, for example:
74
75 var char8 : packed array 1..8 of char;
76 ...
77 char8 := 'FOO';
78
79 which causes char8 to have the value 'FOO '. In standard Pascal,
80 the source and target strings must have the same length.
81
82
83 Fixed-string manipulation with "sread" and "swrite":
84 These two nonstandard functions operate on strings in the same way that
85 "read" and "write" operate on file variables. They are:
86
87 sread string index var_name1 ... var_nameN
88 reads the values of the named variables starting at the index'th
89 position of string, where index is an integer expression and string
90 is a fixed-string array of char variable. The return value
91 of the function is the integer position of the next character in
92 string.
93 swrite string index expression1 ... expressionN
94 writes the values of the expressions into string starting at the
95 index'th position. The return value is the index of the next
96 character to be filled in string.
97
98
99 A further extension allows any of the expression arguments to be of
100 the form:
101 string_variable:length:start
102
103 to specify a substring of the string_variable, where length and start
104 are integer expressions. For example, the Pascal assignment:
105
106 i := swrite s1 10 s2:3:5
107
108 Is equivalent to the PL/1 assignment
109
110 substr s1 10 3 = substr s2 5 3;
111
112 One other extension is the possibility of writing value of variables
113 or constants of enumerated type. The symbolic value is written on 32
114 characters if no length is specified.
115
116 Ex:
117 i := swrite str k enum_value1 enum_value2 : 10 ;
118
119 Both the "sread" and "swrite" functions return -1 in the case of any
120 error such as index out of bounds or invalid input. They also issue
121 warning messages similar to those issued by "read" and "write". These
122 warning messages can be suppressed by the -no_io_warnings control
123 argument to the pascal compiler.
124
125
126 Variable initialization with $value:
127 The $value compiler directive initializes the values of specified
128 variables. It must appear after the "var" section and before the first
129 procedure declaration. It is not allowed inside internal procedures.
130
131 Initializations declared in the $value section are performed the first
132 time that the program segment is made known. Re-initialization can be
133 forced by terminating and re-initiating the segment. Re-initialization
134 is not performed for global variables.
135
136 The syntax of $value is--
137
138 $value var_name1 = value1 ; var_name2 = value2 $
139
140
141 The following rules must be observed--
142
143 - Variables must appear in the order of their declarations in the "var"
144 section.
145 - The values must be single constants.
146 - The syntax "N*constant" is allowed to initialize an array or subarray
147 of N elements.
148 - Initialization of records is not allowed.
149 - Initialization of packed data structures except for packed arrays of
150 char is not allowed.
151
152
153 Expressions of constants in declaration of constants: Expressions are
154 allowed in declarations of constants. Any expression is allowed.
155 This expression must be evaluatable at compilation time, without code
156 generation, and, of course, be of a type allowed for a Pascal
157 constant.
158
159 Examples:
160
161 CONST
162 two = 2;
163 four = two * two;
164 bell = chr 5 + two;
165
166
167 Predefined constants "maxreal" and "minreal":
168 The value of "maxreal" is the largest positive real number allowed.
169 The value of "minreal" is the smallest positive real number allowed.
170 Type "help pascal_limitations.gi" for the numerical values of these
171 constants.
172
173
174 Clock, date and time functions:
175 The "clock" function returns virtual cpu process time in milliseconds.
176 The "date" procedure returns an 8-character date of the form MM/DD/YY.
177 The "time" procedure returns an 8-character time of day of the form
178 HH:MM:SS. Examples:
179
180 var cpu_time: real;
181 date_string, time_string: packed array 1..8 of char;
182 ...
183 cpu_time := clock;
184 date date_string;
185 time time_string;
186
187 Note that date and time accept also dynamic-strings parameters.
188 Their len length must be > 8.
189 In the example above, the following declarations would be
190 acceptable:
191
192 date_string : string 10 ;
193 time_string : string 8;
194
195
196
197 The "log10" function:
198 This function returns the base-10 logarithm of its real argument.
199 Example:
200 log_value := log10 real_number;
201
202
203 The "otherwise" extension to the "case" statement:
204 This extension to the "case" statement provides a default target if
205 none of the other tags is satisfied. The standard "case" statement
206 syntax is--
207
208 case <case_index> of <case_list_element>
209 ; <case_list_element>
210 end
211
212 The extended syntax is--
213
214 case <case_index> of <case_list_element>
215 ; <case_list_element>
216 ; otherwise <statement> ; <statement>
217 end
218
219
220 Dynamic deallocation with "reset":
221 Invoking "reset" on a pointer to a data element causes it to free all
222 allocations that were made in the same area since the corresponding
223 element was allocated. This is a convenient way to clean up all the
224 allocations performed, for example, by a procedure before exiting the
225 procedure. For example:
226
227 new pointer;
228 ...
229 reset pointer;
230
231 cleans up all allocations that were made since before the data pointed
232
233
234 Passing arguments to a Pascal program argc argv and stop
235 extensions:
236 You are allowed to pass arguments to Pascal program.
237 These arguments must be n fixed-strings where n>= 0 which may be
238 followed by an additional optional integer argument. These arguments
239 are passed by the command processor when you call the program at the
240 command level. In this case, the passed arguments are n fixed-strings
241 which are the n arguments found in the command line by the command
242 processor. These arguments may be passed to a main Pascal program
243 from within one other program. In this case, passed arguments must be
244 non-varying fixed-strings PL/1 *char Fortran or PACKED ARRAY
245 1..n OF char Pascal and the Pascal main procedure must be declared
246 "options variable" PL/1 or "descriptors" Fortran or "pl1
247 descriptors" Pascal.
248
249
250 An additional integer Fortran Pascal or fixed bin 35 PL/1
251 argument may be passed. This argument is used by the called Pascal
252 program as return code, set to zero by default. A non null return
253 value can be given to this argument using the STOP extension in the
254 Pascal program.
255
256
257 The predeclared funcion ARGC returns the number of fixed-string
258 arguments passed to the main procedure by the command processor
259 or any other caller.
260
261 The predeclared procedure ARGV NUMBER PARAM returns in
262 the fixed-string PARAM the argument number NUMBER integer.
263 Args are numbered from 1 to ARGC.
264
265 A fatal error occurs if argument list passed to the main
266 procedure has no descriptors or if the referenced argument is not
267 a fixed-string or if it does not exist.
268
269
270 The predeclared procedure STOP causes a GOTO to the "END." sequence of
271 the main procedure of the program.
272
273
274 Syntax:
275 "STOP" "" integer expression ""
276
277
278 Examples:
279 STOP ; * equivalent to "STOP 0" *
280
281 STOP 3 ;
282
283 stop error_code ;
284
285 If the Pascal program was called with arguments, and if the last
286 argument is an integer, this argument is set to the value passed to
287 STOP procedure.
288
289 A fatal error occurs if the main procedure is not active This may
290 occur if the reference to STOP procedure is in an exported procedure.