Commit | Line | Data |
---|---|---|
0f464b75 C |
1 | .ds [[ \fR\z[\h'.15m'[\fP |
2 | .ds ]] \fR\z]\h'.15m']\fP | |
3 | .ND "4 June 1979" | |
4 | . .TM 79-1273-6 39199 39199-11 | |
5 | .RP | |
6 | .TL | |
7 | The Programming Language EFL | |
8 | .AU "MH 2C-570" 2059 | |
9 | Stuart I. Feldman | |
10 | .AI | |
11 | .MH | |
12 | .OK | |
13 | Fortran | |
14 | Preprocessors | |
15 | Ratfor | |
16 | .AB | |
17 | .PP | |
18 | EFL is a clean, general purpose computer language intended to encourage | |
19 | portable programming. | |
20 | It has a uniform and readable syntax and good data and control flow structuring. | |
21 | EFL programs can be translated into efficient Fortran code, | |
22 | so the EFL programmer can take advantage of the ubiquity of Fortran, | |
23 | the valuable libraries of software written in that language, and the portability | |
24 | that comes with the use of a standardized language, | |
25 | without suffering from Fortran's many failings as a language. | |
26 | It is especially useful for numeric programs. | |
27 | The EFL language permits the programmer to express | |
28 | complicated ideas in a comprehensible way, | |
29 | while permitting access to the power of the Fortran environment. | |
30 | EFL can be viewed as a descendant of B. W. Kernighan's Ratfor [1]; | |
31 | the name originally stood for `Extended Fortran Language'. | |
32 | The current version of the EFL compiler is written in | |
33 | portable C. | |
34 | .AE | |
35 | .CS 35 0 35 0 0 1 | |
36 | .SH | |
37 | .ds ~ \\v'.25m'\\s+2~\\s-2\\v'-.25m' | |
38 | .if n .ls 2 | |
39 | .EQ | |
40 | delim @@ | |
41 | .EN | |
42 | .NH 1 | |
43 | INTRODUCTION | |
44 | .NH 2 | |
45 | Purpose | |
46 | .PP | |
47 | EFL is a clean, general purpose computer language intended to encourage | |
48 | portable programming. | |
49 | It has a uniform and readable syntax and good data and control flow structuring. | |
50 | EFL programs can be translated into efficient Fortran code, | |
51 | so the EFL programmer can take advantage of the ubiquity of Fortran, | |
52 | the valuable libraries of software written in that language, and the portability | |
53 | that comes with the use of a standardized language, | |
54 | without suffering from Fortran's many failings as a language. | |
55 | It is especially useful for numeric programs. | |
56 | Thus, the EFL language permits the programmer to express | |
57 | complicated ideas in a comprehensible way, | |
58 | while permitting access to the power of the Fortran environment. | |
59 | .NH 2 | |
60 | History | |
61 | .PP | |
62 | EFL can be viewed as a descendant of B. W. Kernighan's Ratfor [1]; | |
63 | the name originally stood for `Extended Fortran Language'. | |
64 | A. D. Hall designed the initial version of the language and wrote a preliminary version of a compiler. | |
65 | I extended and modified the language and wrote a full compiler (in C) for it. | |
66 | The current compiler is much more than a simple preprocessor: | |
67 | it attempts to diagnose all syntax errors, to provide readable Fortran output, | |
68 | and to avoid a number of niggling restrictions. To achieve this goal, a sizable two-pass translator is needed. | |
69 | .NH 2 | |
70 | Notation | |
71 | .PP | |
72 | In examples and syntax specifications, | |
73 | .B boldface | |
74 | type is used to indicate literal words and punctuation, such as | |
75 | \fBwhile\fR. | |
76 | Words in | |
77 | .I italic | |
78 | type | |
79 | indicate an item in a category, such as an | |
80 | .I expression. | |
81 | A construct surrounded by double brackets represents a list of one or more of those items, separated by commas. | |
82 | Thus, the notation | |
83 | .DS C | |
84 | \fI\*([[ item \*(]]\fR | |
85 | .DE | |
86 | could refer to any of the following: | |
87 | .DS B | |
88 | .I | |
89 | item | |
90 | item\fB, \fIitem | |
91 | \fIitem\fB, \fIitem\fB, \fIitem\fR | |
92 | .DE | |
93 | .PP | |
94 | The reader should have a fair degree of familiarity with some procedural language. | |
95 | There will be occasional references to Ratfor and to Fortran | |
96 | which may be ignored if the reader is unfamiliar with those languages. | |
97 | .bp | |
98 | .NH 1 | |
99 | LEXICAL FORM | |
100 | .NH 2 | |
101 | Character Set | |
102 | .PP | |
103 | The following characters are legal in an EFL program: | |
104 | .KS | |
105 | .TS | |
106 | center; | |
107 | ll. | |
108 | \fIletters \fBa b c d e f g h i j k l m\fI | |
109 | \fBn o p q r s t u v w x y z\fI | |
110 | digits \fB0 1 2 3 4 5 6 7 8 9\fI | |
111 | white space \fIblank tab\fI | |
112 | quotes \fB\' "\fI | |
113 | sharp \fB#\fI | |
114 | continuation \fB\(ru\fI | |
115 | braces \fB{ }\fI | |
116 | parentheses \fB( )\fI | |
117 | other \fB, ; : . + \- \(** /\fI | |
118 | \fB= < > & \*~ | $\fI | |
119 | .TE | |
120 | .KE | |
121 | Letter case (upper or lower) is ignored except within strings, | |
122 | so `\fBa\fR' and `\fBA\fR' are treated as the same character. | |
123 | All of the examples below are printed in lower case. | |
124 | An exclamation mark (`\fB!\fR') may be used in place of a tilde (`\fB\*~\fR'). | |
125 | Square brackets (`[' and `]') may be used in place of braces (`{' and `}'). | |
126 | .NH 2 | |
127 | Lines | |
128 | .PP | |
129 | EFL is a line-oriented language. | |
130 | Except in special cases (discussed below), | |
131 | the end of a line marks the end of a token and the end of a statement. | |
132 | The trailing portion of a line may be used for a comment. | |
133 | There is a mechanism for diverting input from one source file to another, | |
134 | so a single line in the program may be replaced by a number of lines from the other file. | |
135 | Diagnostic messages are labeled with the line number of the file on which they are detected. | |
136 | .NH 3 | |
137 | White Space | |
138 | .PP | |
139 | Outside of a character string or comment, | |
140 | any sequence of one or more spaces or tab characters acts as a single space. | |
141 | Such a space terminates a token. | |
142 | .NH 3 | |
143 | Comments | |
144 | .PP | |
145 | A comment may appear at the end of any line. | |
146 | It is introduced by a sharp (#) character, | |
147 | and continues to the end of the line. | |
148 | (A sharp inside of a quoted string does not mark a comment.) | |
149 | The sharp and succeeding characters on the line are discarded. | |
150 | A blank line is also a comment. | |
151 | Comments have no effect on execution. | |
152 | .NH 3 | |
153 | Include Files | |
154 | .PP | |
155 | It is possible to insert the contents of a file at a point in the source text, | |
156 | by referencing it in a line like | |
157 | .DS C | |
158 | .B | |
159 | include joe | |
160 | .R | |
161 | .DE | |
162 | No statement or comment may follow an | |
163 | .B include | |
164 | on a line. | |
165 | In effect, the | |
166 | .B include | |
167 | line is replaced by the lines in the named file, | |
168 | but diagnostics refer to the line number in the included file. | |
169 | \fBInclude\fRs may be nested at least ten deep. | |
170 | .NH 3 | |
171 | Continuation | |
172 | .PP | |
173 | Lines may be continued explicitly by using the underscore (\fB_\fR) character. | |
174 | If the last character of a line (after comments and trailing white space have been stripped) is an underscore, | |
175 | the end of line and the initial blanks on the next line are ignored. | |
176 | Underscores are ignored in other contexts (except inside of quoted strings). | |
177 | Thus | |
178 | .DS B | |
179 | 1_000_000_ | |
180 | 000 | |
181 | .DE | |
182 | equals @10 sup 9@. | |
183 | .PP | |
184 | There are also rules for continuing lines automatically: | |
185 | the end of line is ignored whenever it is obvious that the statement is not complete. | |
186 | To be specific, a statement is continued if the last token on a line is an operator, comma, | |
187 | left brace, or left parenthesis. | |
188 | (A statement is not continued just because of unbalanced braces or parentheses.) | |
189 | Some compound statements are also continued automatically; | |
190 | these points are noted in the sections on executable statements. | |
191 | .NH 3 | |
192 | Multiple Statements on a Line | |
193 | .PP | |
194 | A semicolon terminates the current statement. | |
195 | Thus, it is possible to write more than one statement on a line. | |
196 | A line consisting only of a semicolon, or a semicolon following a semicolon, forms a null statement. | |
197 | .NH 2 | |
198 | Tokens | |
199 | .PP | |
200 | A program is made up of a sequence of tokens. | |
201 | Each token is a sequence of characters. | |
202 | A blank terminates any token other than a quoted string. | |
203 | End of line also terminates a token unless explicit continuation (see above) is signaled by an underscore. | |
204 | .NH 3 | |
205 | Identifiers | |
206 | .PP | |
207 | An identifier is a letter or a letter followed by letters or digits. | |
208 | The following is a list of the reserved words that have special meaning in EFL. | |
209 | They will be discussed later. | |
210 | .KF | |
211 | .TS | |
212 | center; | |
213 | lll . | |
214 | .B | |
215 | array exit precision | |
216 | automatic external procedure | |
217 | break false read | |
218 | call field readbin | |
219 | case for real | |
220 | character function repeat | |
221 | common go return | |
222 | complex goto select | |
223 | continue if short | |
224 | debug implicit sizeof | |
225 | default include static | |
226 | define initial struct | |
227 | dimension integer subroutine | |
228 | do internal true | |
229 | double lengthof until | |
230 | doubleprecision logical value | |
231 | else long while | |
232 | end next write | |
233 | equivalence option writebin | |
234 | .R | |
235 | .TE | |
236 | .KE | |
237 | The use of these words is discussed below. | |
238 | These words may not be used for any other purpose. | |
239 | .NH 3 | |
240 | Strings | |
241 | .PP | |
242 | A character string is a sequence of characters surrounded by quotation marks. | |
243 | If the string is bounded by single-quote marks ( \fB\'\fR ), it may contain double | |
244 | quote marks ( \fB"\fR ), and vice versa. | |
245 | A quoted string may not be broken across a line boundary. | |
246 | .DS | |
247 | .B | |
248 | \'hello there\' | |
249 | "ain\'t misbehavin\'" | |
250 | .R | |
251 | .DE | |
252 | .NH 3 | |
253 | Integer Constants | |
254 | .PP | |
255 | An integer constant is a sequence of one or more digits. | |
256 | .DS B | |
257 | .B | |
258 | 0 | |
259 | 57 | |
260 | 123456 | |
261 | .R | |
262 | .DE | |
263 | .NH 3 | |
264 | Floating Point Constants | |
265 | .PP | |
266 | A floating point constant contains a dot and/or an exponent field. | |
267 | An | |
268 | .I "exponent field" | |
269 | is a letter | |
270 | .B d | |
271 | or | |
272 | .B e | |
273 | followed by an optionally signed integer constant. | |
274 | If | |
275 | @I@ | |
276 | and | |
277 | @J@ | |
278 | are integer constants and | |
279 | @E@ | |
280 | is an exponent field, then a floating constant has one of the following forms: | |
281 | .DS B | |
282 | .I | |
283 | \fB.\fPI | |
284 | I\fB.\fP | |
285 | I\fB.\fPJ | |
286 | IE | |
287 | I\fB.\fPE | |
288 | \fB.\fPIE | |
289 | I\fB.\fPJE | |
290 | .R | |
291 | .DE | |
292 | .NH 3 | |
293 | Punctuation | |
294 | .PP | |
295 | Certain characters are used to group or separate objects in the language. | |
296 | These are | |
297 | .TS | |
298 | center; | |
299 | ll. | |
300 | parentheses ( ) | |
301 | braces { } | |
302 | comma , | |
303 | semicolon ; | |
304 | colon : | |
305 | end-of-line | |
306 | .TE | |
307 | The end-of-line is a token (statement separator) | |
308 | when the line is neither blank nor continued. | |
309 | .NH 3 | |
310 | Operators | |
311 | .PP | |
312 | The EFL operators are written as sequences of one or more | |
313 | non-alphanumeric characters. | |
314 | .DS B | |
315 | + \- \(** / \(**\(** | |
316 | < <= > >= == \*~= | |
317 | && |\|| & | | |
318 | += \-= \(*= /= \(**\(**= | |
319 | &&= |\||= &= |= | |
320 | \-> . $ | |
321 | .DE | |
322 | A dot (`\fB.\fR') is an operator when it qualifies a structure element name, | |
323 | but not when it acts as a decimal point in a numeric constant. | |
324 | There is a special mode (see the Atavisms section) | |
325 | in which some of the operators may be represented by a string consisting of a dot, an identifier, and a dot | |
326 | (\fIe.g., \fB.lt.\fR ). | |
327 | .NH 2 | |
328 | Macros | |
329 | .PP | |
330 | EFL has a simple macro substitution facility. | |
331 | An identifier may be defined to be equal to a string of tokens; | |
332 | whenever that name appears as a token in the program, | |
333 | the string replaces it. | |
334 | A macro name is given a value in a | |
335 | .B define | |
336 | statement like | |
337 | .DS | |
338 | define count n += 1 | |
339 | .DE | |
340 | Any time the name | |
341 | .B count | |
342 | appears in the program, it is replaced by the statement | |
343 | .DS C | |
344 | .B | |
345 | n += 1 | |
346 | .R | |
347 | .DE | |
348 | A | |
349 | .B define | |
350 | statement must appear alone on a line; | |
351 | the form is | |
352 | .DS C | |
353 | \fBdefine \fIname \fIrest-of-line\fR | |
354 | .DE | |
355 | Trailing comments are part of the string. | |
356 | .NH 1 | |
357 | PROGRAM FORM | |
358 | .NH 2 | |
359 | Files | |
360 | .PP | |
361 | A | |
362 | .I file | |
363 | is a sequence of lines. | |
364 | A file is compiled as a single unit. | |
365 | It may contain one or more procedures. | |
366 | Declarations and options that appear outside of a procedure | |
367 | affect the succeeding procedures on that file. | |
368 | .NH 2 | |
369 | Procedures | |
370 | .PP | |
371 | Procedures are the largest grouping of statements in EFL. | |
372 | Each procedure has a name by which it is invoked. | |
373 | (The first procedure invoked during execution, known as the | |
374 | .I main | |
375 | procedure, | |
376 | has the null name.) | |
377 | Procedure calls and argument passing are discussed in Section 8. | |
378 | .NH 2 | |
379 | Blocks | |
380 | .PP | |
381 | Statements may be formed into groups inside of a procedure. | |
382 | To describe the scope of names, it is convenient to introduce the ideas of | |
383 | .I block | |
384 | and of | |
385 | .I "nesting level." | |
386 | The beginning of a program file is at nesting level zero. | |
387 | Any options, macro definitions, | |
388 | or variable declarations there are also at level zero. | |
389 | The text immediately following a | |
390 | .B procedure | |
391 | statement is at level 1. | |
392 | After the declarations, | |
393 | a left brace marks the beginning of a new block and increases the nesting level by 1; | |
394 | a right brace drops the level by 1. | |
395 | (Braces inside declarations do not mark blocks.) | |
396 | (See Section 7.2). | |
397 | An | |
398 | .B end | |
399 | statement marks the end of the procedure, level 1, and the return to level 0. | |
400 | A name | |
401 | (variable or macro) | |
402 | that is defined at level | |
403 | @k@ | |
404 | is defined throughout that block and in all deeper nested levels in which that name is not | |
405 | redefined or redeclared. | |
406 | Thus, a procedure might look like the following: | |
407 | .DS B | |
408 | .ta .7i 1.4i 2.1i 2.8i | |
409 | .B | |
410 | # block 0 | |
411 | procedure george | |
412 | real x | |
413 | x = 2 | |
414 | . . . | |
415 | if(x > 2) | |
416 | { # new block | |
417 | integer x # a different variable | |
418 | do x = 1,7 | |
419 | write(,x) | |
420 | . . . | |
421 | } # end of block | |
422 | end # end of procedure, return to block 0 | |
423 | .DE | |
424 | .NH 2 | |
425 | Statements | |
426 | .PP | |
427 | A statement is terminated by end of line or by a semicolon. | |
428 | Statements are of the following types: | |
429 | .DS B | |
430 | Option | |
431 | Include | |
432 | Define | |
433 | .sp .3 | |
434 | Procedure | |
435 | End | |
436 | .sp .3 | |
437 | Declarative | |
438 | Executable | |
439 | .DE | |
440 | The | |
441 | .B option | |
442 | statement is described in Section 10. | |
443 | The | |
444 | .B include, | |
445 | .B define, | |
446 | and | |
447 | .B end | |
448 | statements have been described above; | |
449 | they may not be followed by another statement on a line. | |
450 | Each procedure begins with a | |
451 | .B procedure | |
452 | statements and finishes with an | |
453 | .B end | |
454 | statement; these are discussed in Section 8. | |
455 | Declarations describe types and values of variables and | |
456 | procedures. | |
457 | Executable statements cause specific actions to be taken. | |
458 | A block is an example of an executable statement; it is made up | |
459 | of declarative and executable statements. | |
460 | .NH 2 | |
461 | Labels | |
462 | .PP | |
463 | An executable statement may have a | |
464 | .I label | |
465 | which may be used in a branch statement. | |
466 | A label is an identifier followed by a colon, as in | |
467 | .DS B | |
468 | .B | |
469 | .ta 1i | |
470 | read(, x) | |
471 | if(x < 3) goto error | |
472 | . . . | |
473 | error: fatal("bad input") | |
474 | .R | |
475 | .DE | |
476 | .NH 1 | |
477 | DATA TYPES AND VARIABLES | |
478 | .PP | |
479 | EFL supports a small number of basic (scalar) types. | |
480 | The programmer may define objects made up of variables of basic type; | |
481 | other aggregates may then be defined in terms of previously defined aggregates. | |
482 | .NH 2 | |
483 | Basic Types | |
484 | .PP | |
485 | The basic types are | |
486 | .DS B | |
487 | \fBlogical | |
488 | \fBinteger | |
489 | \fBfield(\fIm\|\fB:\fIn\|\fB) | |
490 | \fBreal | |
491 | \fBcomplex | |
492 | \fBlong real | |
493 | \fBlong complex | |
494 | \fBcharacter(\fIn\|\fB) | |
495 | .R | |
496 | .DE | |
497 | A logical quantity may take on the two values true and false. | |
498 | An integer may take on any whole number value in some machine-dependent range. | |
499 | A field quantity is an integer restricted to a particular closed interval | |
500 | @([m:n])@. | |
501 | A `real' quantity is a floating point approximation to a real or rational number. | |
502 | A long real is a more precise approximation to a rational. | |
503 | (Real quantities are represented as single precision floating point numbers; | |
504 | long reals are double precision floating point numbers.) | |
505 | A complex quantity is an approximation to a complex number, and is represented as a pair of reals. | |
506 | A character quantity is a fixed-length string of @n@ characters. | |
507 | .NH 2 | |
508 | Constants | |
509 | .PP | |
510 | There is a notation for a constant of each basic type. | |
511 | .LP | |
512 | A logical may take on the two values | |
513 | .DS B | |
514 | .B | |
515 | true | |
516 | false | |
517 | .R | |
518 | .DE | |
519 | An integer or field constant is a fixed point constant, | |
520 | optionally preceded by a plus or minus sign, as in | |
521 | .DS B | |
522 | .B | |
523 | 17 | |
524 | \-94 | |
525 | +6 | |
526 | 0 | |
527 | .R | |
528 | .DE | |
529 | A long real (`double precision') constant is a floating point constant containing an exponent field that | |
530 | begins with the letter | |
531 | .B d. | |
532 | A real (`single precision') constant is any other floating point constant. | |
533 | A real or long real constant may be preceded by a plus or minus sign. | |
534 | The following are valid | |
535 | .B real | |
536 | constants: | |
537 | .DS B | |
538 | .B | |
539 | 17.3 | |
540 | \-.4 | |
541 | 7.9e\-6 @(~=~7.9 times 10 sup -6 )@ | |
542 | 14e9 @(~=~1.4 times 10 sup 10 )@ | |
543 | .R | |
544 | .DE | |
545 | The following are valid | |
546 | .B "long real" | |
547 | constants | |
548 | .DS B | |
549 | .B | |
550 | 7.9d\-6 @(~=~7.9 times 10 sup -6 )@ | |
551 | 5d3 | |
552 | .R | |
553 | .DE | |
554 | .LP | |
555 | A character constant is a quoted string. | |
556 | .NH 2 | |
557 | Variables | |
558 | .PP | |
559 | A variable is a quantity with a name and a location. | |
560 | At any particular time the variable may also have a value. | |
561 | (A variable is said to be | |
562 | .I undefined | |
563 | before it is initialized or assigned its first value, | |
564 | and after certain indefinite operations are performed.) | |
565 | Each variable has certain attributes: | |
566 | .NH 3 | |
567 | Storage Class | |
568 | .PP | |
569 | The association of a name and a location is either | |
570 | transitory or permanent. | |
571 | Transitory association is achieved when arguments are passed to procedures. | |
572 | Other associations are permanent (static). | |
573 | (A future extension of EFL may include dynamically allocated variables.) | |
574 | .NH 3 | |
575 | Scope of Names | |
576 | .PP | |
577 | The names of | |
578 | common areas | |
579 | are global, | |
580 | as are procedure names: | |
581 | these names may be used anywhere in the program. | |
582 | All other names are local to the block in which they are declared. | |
583 | .NH 3 | |
584 | Precision | |
585 | .PP | |
586 | Floating point variables are either of normal or | |
587 | .B long | |
588 | precision. | |
589 | This attribute may be stated independently of the basic type. | |
590 | .NH 2 | |
591 | Arrays | |
592 | .PP | |
593 | It is possible to declare rectangular arrays (of any dimension) of values of the same type. | |
594 | The index set is always a cross-product of intervals of integers. | |
595 | The lower and upper bounds of the intervals must be constants for arrays that are local or | |
596 | .B common. | |
597 | A formal argument array may have intervals that are of length equal to one of the other formal arguments. | |
598 | An element of an array is denoted by the array name followed by a parenthesized comma-separated list of integer values, | |
599 | each of which must lie within the corresponding interval. | |
600 | (The intervals may include negative numbers.) | |
601 | Entire arrays may be passed as procedure arguments or in input/output lists, | |
602 | or they may be initialized; | |
603 | all other array references must be to individual elements. | |
604 | .NH 2 | |
605 | Structures | |
606 | .PP | |
607 | It is possible to define new types which are made up of elements of other types. | |
608 | The compound object is known as a | |
609 | .I structure; | |
610 | its constituents are called | |
611 | .I members | |
612 | of the structure. | |
613 | The structure may be given a name, | |
614 | which acts as a type name in the remaining statements within the scope of its declaration. | |
615 | The elements of a structure may be of any type | |
616 | (including previously defined structures), | |
617 | or they may be arrays of such objects. | |
618 | Entire structures may be passed to procedures or be used in input/output lists; | |
619 | individual elements of structures may be referenced. | |
620 | The uses of structures will be detailed below. | |
621 | The following structure might represent a symbol table: | |
622 | .DS B | |
623 | .B | |
624 | .ta .7i 1.4i 2.1i | |
625 | struct tableentry | |
626 | { | |
627 | character(8) name | |
628 | integer hashvalue | |
629 | integer numberofelements | |
630 | field(0:1) initialized, used, set | |
631 | field(0:10) type | |
632 | } | |
633 | .DE | |
634 | .NH 1 | |
635 | EXPRESSIONS | |
636 | .PP | |
637 | Expressions are syntactic forms that yield a value. | |
638 | An expression may have any of the following forms, recursively applied: | |
639 | .DS B | |
640 | .I | |
641 | primary | |
642 | \fB(\fI expression \fB)\fI | |
643 | unary-operator expression | |
644 | expression binary-operator expression | |
645 | .DE | |
646 | In the following table of operators, | |
647 | all operators on a line have equal precedence | |
648 | and have higher precedence than operators on later lines. | |
649 | The meanings of these operators are described in sections 5.3 and 5.4. | |
650 | .DS B | |
651 | .B | |
652 | \-> . | |
653 | \(**\(** | |
654 | \(** / \fIunary\fB + \- ++ \-\- | |
655 | + \- | |
656 | < <= > >= == \*~= | |
657 | & && | |
658 | | |\|| | |
659 | $ | |
660 | = += \-= \(**= /= \(**\(**= &= |= &&= |\||= | |
661 | .R | |
662 | .DE | |
663 | Examples of expressions are | |
664 | .DS B | |
665 | .B | |
666 | a<b && b<c | |
667 | \-(a + sin(x)) / (5+cos(x))\(**\(**2 | |
668 | .R | |
669 | .DE | |
670 | .NH 2 | |
671 | Primaries | |
672 | .PP | |
673 | Primaries are the basic elements of expressions, as follows: | |
674 | .NH 3 | |
675 | Constants | |
676 | .PP | |
677 | Constants are described in Section 4.2. | |
678 | .NH 3 | |
679 | Variables | |
680 | .PP | |
681 | Scalar variable names are primaries. | |
682 | They may appear on the left or the right side of an assignment. | |
683 | Unqualified names of aggregates (structures or arrays) | |
684 | may only appear as procedure arguments and in input/output lists. | |
685 | .NH 3 | |
686 | Array Elements | |
687 | .PP | |
688 | An element of an array is denoted by the array name followed by a parenthesized list of subscripts, | |
689 | one integer value for each declared dimension: | |
690 | .DS B | |
691 | .B | |
692 | a(5) | |
693 | b(6,\|\-3,\|4) | |
694 | .R | |
695 | .DE | |
696 | .NH 3 | |
697 | Structure Members | |
698 | .PP | |
699 | A structure name followed by a dot followed by the name of a member of that structure constitutes a reference to | |
700 | that element. | |
701 | If that element is itself a structure, the reference may be further qualified. | |
702 | .DS B | |
703 | .B | |
704 | a.b | |
705 | x(3).y(4).z(5) | |
706 | .R | |
707 | .DE | |
708 | .NH 3 | |
709 | Procedure Invocations | |
710 | .PP | |
711 | A procedure is invoked by an expression of one of the forms | |
712 | .DS B | |
713 | \fIprocedurename \fB( )\fR | |
714 | \fIprocedurename \fB( \fIexpression\fB )\fR | |
715 | \fIprocedurename \fB( \fIexpression-1\fB, \fI...\fB, \fIexpression-n \fB)\fR | |
716 | .DE | |
717 | The | |
718 | .I procedurename | |
719 | is either the name of a variable | |
720 | declared | |
721 | .B external | |
722 | or it is the name of a | |
723 | function known to the EFL compiler (see Section 8.5), | |
724 | or it is the actual name of a procedure, as it appears in a | |
725 | .B procedure | |
726 | statement. | |
727 | If a | |
728 | .I procedurename | |
729 | is declared | |
730 | .B external | |
731 | and is an argument of the current procedure, | |
732 | it is associated with the procedure name passed as actual argument; | |
733 | otherwise it is the actual name of a procedure. | |
734 | Each | |
735 | .I expression | |
736 | in the above is called an | |
737 | .I "actual argument". | |
738 | Examples of procedure invocations are | |
739 | .DS B | |
740 | .B | |
741 | f(x) | |
742 | work() | |
743 | g(x, y+3, 'xx') | |
744 | .R | |
745 | .DE | |
746 | When one of these procedure invocations is to be performed, | |
747 | each of the actual argument expressions is first evaluated. | |
748 | The types, precisions, and bounds of actual and formal arguments should agree. | |
749 | If an actual argument is a variable name, array element, or structure member, | |
750 | the called procedure is permitted to use the corresponding formal argument as the left side | |
751 | of an assignment or in an input list; | |
752 | otherwise it may only use the value. | |
753 | After the formal and actual arguments are associated, | |
754 | control is passed to the first executable statement of the procedure. | |
755 | When a | |
756 | .B return | |
757 | statement is executed in that procedure, | |
758 | or when control reaches the | |
759 | .B end | |
760 | statement of that procedure, | |
761 | the function value is made available as the value of the procedure invocation. | |
762 | The type of the value is determined by the attributes of | |
763 | the | |
764 | .I procedurename | |
765 | that are declared or implied in the calling procedure, | |
766 | which must agree with the attributes declared for the function in its procedure. | |
767 | In the special case of a generic function, | |
768 | the type of the result is also affected by the type of the argument. | |
769 | See Chapter 8 for details. | |
770 | .NH 3 | |
771 | Input/Output Expressions | |
772 | .PP | |
773 | The EFL input/output syntactic forms | |
774 | may be used as integer primaries that have | |
775 | a non-zero value | |
776 | if an error occurs during the input or output. | |
777 | See Section 7.7. | |
778 | .NH 3 | |
779 | Coercions | |
780 | .PP | |
781 | An expression of one precision or type may be converted to another by an expression of the form | |
782 | .DS C | |
783 | \fIattributes \fB( \fIexpression \fB)\fR | |
784 | .DE | |
785 | At present, the only | |
786 | .I attributes | |
787 | permitted are precision and basic types. | |
788 | Attributes are separated by white space. | |
789 | An arithmetic value of one type may be coerced to any other arithmetic type; | |
790 | a character expression of one length may be coerced to a character expression of another length; | |
791 | logical expressions may not be coerced to a nonlogical type. | |
792 | As a special case, | |
793 | a quantity of | |
794 | .B complex | |
795 | or | |
796 | .B "long complex" | |
797 | type may be constructed from two integer or real quantities | |
798 | by passing two expressions (separated by a comma) in the coercion. | |
799 | Examples and equivalent values are | |
800 | .DS B | |
801 | .B | |
802 | integer(5.3) = 5 | |
803 | long real(5) = 5.0d0 | |
804 | complex(5,3) = @5+3i@ | |
805 | .R | |
806 | .DE | |
807 | Most conversions are done implicitly, | |
808 | since most binary operators permit operands of different arithmetic types. | |
809 | Explicit coercions are of most use when it is necessary to convert the type of an actual argument | |
810 | to match that of the corresponding formal parameter in a procedure call. | |
811 | .NH 3 | |
812 | Sizes | |
813 | .PP | |
814 | There is a notation which yields the amount of memory required to store a datum | |
815 | or an item of specified type: | |
816 | .DS B | |
817 | \fBsizeof ( \fIleftside\fB ) | |
818 | \fBsizeof ( \fIattributes\fB ) | |
819 | .R | |
820 | .DE | |
821 | In the first case, | |
822 | .I leftside | |
823 | can denote a variable, array, array element, or structure member. | |
824 | The value of | |
825 | .B sizeof | |
826 | is an integer, which gives the size in arbitrary units. | |
827 | If the size is needed in terms of the size of some specific unit, this | |
828 | can be computed by division: | |
829 | .DS B | |
830 | .B | |
831 | sizeof(x) / sizeof(integer) | |
832 | .R | |
833 | .DE | |
834 | yields the size of the variable | |
835 | .B x | |
836 | in integer words. | |
837 | .PP | |
838 | The distance between consecutive elements of an array may not equal | |
839 | .B sizeof | |
840 | because certain data types require final padding on some machines. | |
841 | The | |
842 | .B lengthof | |
843 | operator gives this larger value, again in arbitrary units. | |
844 | The syntax is | |
845 | .DS B | |
846 | \fBlengthof ( \fIleftside\fB ) | |
847 | \fBlengthof ( \fIattributes\fB ) | |
848 | .R | |
849 | .DE | |
850 | .NH 2 | |
851 | Parentheses | |
852 | .PP | |
853 | An expression surrounded by parentheses is itself an expression. | |
854 | A parenthesized expression must be evaluated before an expression of which it is a part is evaluated. | |
855 | .NH 2 | |
856 | Unary Operators | |
857 | .PP | |
858 | All of the unary operators in EFL are prefix operators. | |
859 | The result of a unary operator has the same type as its operand. | |
860 | .NH 3 | |
861 | Arithmetic | |
862 | .PP | |
863 | Unary | |
864 | .B + | |
865 | has no effect. | |
866 | A unary | |
867 | .B \- | |
868 | yields the negative of its operand. | |
869 | .PP | |
870 | The prefix operator | |
871 | .B ++ | |
872 | adds one to its operand. | |
873 | The prefix operator | |
874 | .B \-\- | |
875 | subtracts one from its operand. | |
876 | The value of either expression is the result of the addition or subtraction. | |
877 | For these two operators, the operand must be a scalar, | |
878 | array element, or structure member of arithmetic type. | |
879 | (As a side effect, the operand value is changed.) | |
880 | .NH 3 | |
881 | Logical | |
882 | .PP | |
883 | The only logical unary operator is complement | |
884 | (\fB\*~\fR). | |
885 | This operator is defined by the equations | |
886 | .DS B | |
887 | .B | |
888 | \*~ true = false | |
889 | \*~ false = true | |
890 | .R | |
891 | .DE | |
892 | .NH 2 | |
893 | Binary Operators | |
894 | .PP | |
895 | Most EFL operators have two operands, separated by the operator. | |
896 | Because the character set must be limited, | |
897 | some of the operators are denoted by strings of two or three special characters. | |
898 | All binary operators except exponentiation are left associative. | |
899 | .NH 3 | |
900 | Arithmetic | |
901 | .PP | |
902 | The binary arithmetic operators are | |
903 | .KS | |
904 | .TS | |
905 | center; | |
906 | ll. | |
907 | + addition | |
908 | @-@ subtraction | |
909 | \(** multiplication | |
910 | / division | |
911 | \(**\(** exponentiation | |
912 | .TE | |
913 | .KE | |
914 | Exponentiation is right associative: | |
915 | a\(**\(**b\(**\(**c = a\(**\(**(b\(**\(**c) = @a sup {(b sup c )}@ | |
916 | The operations have the conventional meanings: | |
917 | @8+2~=~10@, | |
918 | @8-2 ~=~ 6@, | |
919 | @8\(** 2 ~=~ 16@, | |
920 | @8/2~=~ 4@, | |
921 | @8 \(**\(** 2 ~=~ 8 sup 2 ~=~ 64@. | |
922 | .PP | |
923 | The type of the result of a binary operation | |
924 | @A~op~B@ | |
925 | is determined by the types of its operands: | |
926 | .KS | |
927 | .TS | |
928 | center; | |
929 | l|lllll . | |
930 | Type of B | |
931 | .sp .5 | |
932 | Type of A integer real long real complex long complex | |
933 | _ | |
934 | integer integer real long real complex long complex | |
935 | real real real long real complex long complex | |
936 | long real long real long real long real long complex long complex | |
937 | complex complex complex long complex complex long complex | |
938 | long complex long complex long complex long complex long complex long complex | |
939 | .TE | |
940 | .KE | |
941 | If the type of an operand differs from the type of the result, | |
942 | the calculation is done as if the operand were first coerced to the type of the result. | |
943 | If both operands are integers, the result is of type integer, and is computed exactly. | |
944 | (Quotients are truncated toward zero, so | |
945 | @8/3 = 2@.) | |
946 | .NH 3 | |
947 | Logical | |
948 | .PP | |
949 | The two binary logical operations in EFL, | |
950 | .B and | |
951 | and | |
952 | .B or, | |
953 | are defined by the truth tables: | |
954 | .KS | |
955 | .TS | |
956 | center; | |
957 | cccc | |
958 | aaaa . | |
959 | A B A and B A or B | |
960 | _ | |
961 | false false false false | |
962 | false true false true | |
963 | true false false true | |
964 | true true true true | |
965 | .R | |
966 | .TE | |
967 | .R | |
968 | .KE | |
969 | Each of these operators comes in two forms. | |
970 | In one form, the order of evaluation is specified. | |
971 | The expression | |
972 | .DS C | |
973 | .B | |
974 | a && b | |
975 | .R | |
976 | .DE | |
977 | is evaluated by first evaluating | |
978 | .B a ; | |
979 | if it is false then the expression is false and | |
980 | .B b | |
981 | is not evaluated; | |
982 | otherwise the expression has the value of | |
983 | .B b. | |
984 | The expression | |
985 | .DS C | |
986 | .B | |
987 | a |\|| b | |
988 | .R | |
989 | .DE | |
990 | is evaluated by first evaluating | |
991 | .B a; | |
992 | if it is true then the expression is true and | |
993 | .B b | |
994 | is not evaluated; | |
995 | otherwise the expression has the value of | |
996 | .B b. | |
997 | The other forms of the operators | |
998 | (\fB&\fR for \fBand\fR and \fB|\fR for \fBor\fR) | |
999 | do not imply an order of evaluation. | |
1000 | With the latter operators, | |
1001 | the compiler may speed up the code by | |
1002 | evaluating the operands in any order. | |
1003 | .NH 3 | |
1004 | Relational Operators | |
1005 | .PP | |
1006 | There are six relations between arithmetic quantities. | |
1007 | These operators are not associative. | |
1008 | .KS | |
1009 | .TS | |
1010 | center; | |
1011 | ccs | |
1012 | lll. | |
1013 | EFL Operator Meaning | |
1014 | _ | |
1015 | < < less than | |
1016 | <= @<=@ less than or equal to | |
1017 | == @=@ equal to | |
1018 | \*~= @!=@ not equal to | |
1019 | > > greater than | |
1020 | >= @>=@ greater than or equal | |
1021 | .TE | |
1022 | .KE | |
1023 | Since the complex numbers are not ordered, the only relational operators that may take complex operands | |
1024 | are | |
1025 | \fB==\fR | |
1026 | and | |
1027 | \fB\*~=\fR . | |
1028 | The character collating sequence is not defined. | |
1029 | .NH 3 | |
1030 | Assignment Operators | |
1031 | .PP | |
1032 | All of the assignment operators are right associative. | |
1033 | The simple form of assignment is | |
1034 | .DS C | |
1035 | \fIbasic-left-side \fB= \fIexpression\fR | |
1036 | .DE | |
1037 | A | |
1038 | .I basic-left-side | |
1039 | is a scalar variable name, array element, or structure member of basic type. | |
1040 | This statement computes the expression on the right side, and stores that value | |
1041 | (possibly after coercing the value to the type of the left side) | |
1042 | in the location named by the left side. | |
1043 | The value of the assignment expression is the value assigned to the left side after coercion. | |
1044 | .PP | |
1045 | There is also an assignment operator corresponding to each binary arithmetic and logical operator. | |
1046 | In each case, | |
1047 | @a ~op = ~ b@ | |
1048 | is equivalent to | |
1049 | @a ~=~ a ~ op~ b@. | |
1050 | (The operator and equal sign must not be separated by blanks.) | |
1051 | Thus, | |
1052 | .B n+=2 | |
1053 | adds 2 to n. | |
1054 | The location of the left side is evaluated only once. | |
1055 | .NH 2 | |
1056 | Dynamic Structures | |
1057 | .PP | |
1058 | EFL does not have an address (pointer, reference) type. | |
1059 | However, there is a notation for dynamic structures, | |
1060 | .DS B | |
1061 | \fIleftside \fB\-> \fIstructurename\fR | |
1062 | .DE | |
1063 | This expression is a structure with the shape implied by | |
1064 | .I structurename | |
1065 | but starting at the location of | |
1066 | .I leftside. | |
1067 | In effect, this overlays the structure template at the specified location. | |
1068 | The | |
1069 | .I leftside | |
1070 | must be a variable, array, array element, or structure member. | |
1071 | The type of the | |
1072 | .I leftside | |
1073 | must be one of the types in the structure declaration. | |
1074 | An element of such a structure is denoted in the usual way using the dot operator. | |
1075 | Thus, | |
1076 | .DS C | |
1077 | .B | |
1078 | place(i) \-> st.elt | |
1079 | .R | |
1080 | .DE | |
1081 | refers to the | |
1082 | .B elt | |
1083 | member of the | |
1084 | .B st | |
1085 | structure starting at the | |
1086 | @i sup th@ | |
1087 | element of the array | |
1088 | .B place. | |
1089 | .NH 2 | |
1090 | Repetition Operator | |
1091 | .PP | |
1092 | Inside of a list, an element of the form | |
1093 | .DS C | |
1094 | \fIinteger-constant-expression \fB$\fI constant-expression\fR | |
1095 | .DE | |
1096 | is equivalent to the appearance of the | |
1097 | .I expression | |
1098 | a number of times equal to the first expression. | |
1099 | Thus, | |
1100 | .DS C | |
1101 | .B | |
1102 | (3, 3$4, 5) | |
1103 | .R | |
1104 | .DE | |
1105 | is equivalent to | |
1106 | .DS C | |
1107 | .B | |
1108 | (3, 4, 4, 4, 5) | |
1109 | .R | |
1110 | .DE | |
1111 | .NH 2 | |
1112 | Constant Expressions | |
1113 | .PP | |
1114 | If an expression is built up out of operators (other than functions) and constants, | |
1115 | the value of the expression is a constant, and may be used anywhere a constant is required. | |
1116 | .NH 1 | |
1117 | DECLARATIONS | |
1118 | .PP | |
1119 | Declarations statement describe the meaning, shape, and size of named | |
1120 | objects in the EFL language. | |
1121 | .NH 2 | |
1122 | Syntax | |
1123 | .PP | |
1124 | A declaration statement is made up of attributes and variables. | |
1125 | Declaration statements are of two form: | |
1126 | .DS B | |
1127 | .I | |
1128 | attributes variable-list | |
1129 | attributes { declarations } | |
1130 | .R | |
1131 | .DE | |
1132 | In the first case, each name in the | |
1133 | .I variable-list | |
1134 | has the specified attributes. | |
1135 | In the second, each name in the declarations also has the specified attributes. | |
1136 | A variable name may appear in more than one variable list, | |
1137 | so long as the attributes are not contradictory. | |
1138 | Each name of a nonargument variable may be accompanied by an initial value specification. | |
1139 | The | |
1140 | .I declarations | |
1141 | inside the braces are one or more declaration statements. | |
1142 | Examples of declarations are | |
1143 | .DS B | |
1144 | .B | |
1145 | integer k=2 | |
1146 | .sp .5 | |
1147 | long real b(7,3) | |
1148 | .sp .5 | |
1149 | common(cname) | |
1150 | { | |
1151 | integer i | |
1152 | long real array(5,0:3) x, y | |
1153 | character(7) ch | |
1154 | } | |
1155 | .R | |
1156 | .DE | |
1157 | .ne 1i | |
1158 | .NH 2 | |
1159 | Attributes | |
1160 | .NH 3 | |
1161 | Basic Types | |
1162 | .PP | |
1163 | The following are basic types in declarations | |
1164 | .DS | |
1165 | .B | |
1166 | logical | |
1167 | integer | |
1168 | field(@m:n@) | |
1169 | character(@k@) | |
1170 | real | |
1171 | complex | |
1172 | .R | |
1173 | .DE | |
1174 | In the above, the quantities @k@, @m@, and @n@ denote integer constant expressions with the properties | |
1175 | @k>0@ and @n>m@. | |
1176 | .NH 3 | |
1177 | Arrays | |
1178 | .PP | |
1179 | The dimensionality may be declared by an | |
1180 | .B array | |
1181 | attribute | |
1182 | .EQ C | |
1183 | bold array( b sub 1 , ..., b sub n bold ) | |
1184 | .EN | |
1185 | Each of the @b sub i@ | |
1186 | may either be a single integer expression or a pair of integer expressions separated by a colon. | |
1187 | The pair of expressions form a lower and an upper bound; the single expression is an upper bound with | |
1188 | an implied lower bound of 1. | |
1189 | The number of dimensions is equal to | |
1190 | @n,@ | |
1191 | the number of bounds. | |
1192 | All of the integer expressions must be constants. | |
1193 | An exception is permitted only if all of the variables associated with an | |
1194 | array declarator are formal arguments of the procedure; in this case, each bound | |
1195 | must have the property that | |
1196 | @upper - lower + 1@ | |
1197 | is equal to a formal argument of the procedure. | |
1198 | (The compiler has limited ability to simplify expressions, but it will recognize | |
1199 | important cases such as | |
1200 | .B "(0:n\-1)". | |
1201 | The upper bound for the last dimension | |
1202 | @(b sub n )@ | |
1203 | may be marked by an asterisk | |
1204 | ( \fB\(**\fR ) | |
1205 | if the size of the array is not known. | |
1206 | The following are legal @bold array@ attributes: | |
1207 | .DS B | |
1208 | .B | |
1209 | array(5) | |
1210 | array(5, 1:5, \-3:0) | |
1211 | array(5, \(**) | |
1212 | array(0:m\-1, m) | |
1213 | .R | |
1214 | .DE | |
1215 | .NH 3 | |
1216 | Structures | |
1217 | .PP | |
1218 | A structure declaration is of the form | |
1219 | .DS B | |
1220 | \fBstruct \fIstructname \fB{ \fI declaration statements \fB}\fR | |
1221 | .DE | |
1222 | The | |
1223 | .I structname | |
1224 | is optional; if it is present, it acts as if it were the name of a type in the rest of its scope. | |
1225 | Each name that appears inside the | |
1226 | .I declarations | |
1227 | is a | |
1228 | .I member | |
1229 | of the structure, and has a special meaning when used to qualify any variable declared with the structure type. | |
1230 | A name may appear as a member of any number of structures, | |
1231 | and may also be the name of an ordinary variable, | |
1232 | since a structure member name is used only in contexts where the parent type is known. | |
1233 | The following are valid structure attributes | |
1234 | .DS B | |
1235 | .B | |
1236 | struct xx | |
1237 | { | |
1238 | integer a, b | |
1239 | real x(5) | |
1240 | } | |
1241 | ||
1242 | struct { xx z(3); character(5) y } | |
1243 | .R | |
1244 | .DE | |
1245 | The last line defines a structure containing an array of three @bold xx 's@ | |
1246 | and a character string. | |
1247 | .NH 3 | |
1248 | Precision | |
1249 | .PP | |
1250 | Variables of floating point | |
1251 | (@bold real@ or @bold complex@) type may be declared to be | |
1252 | @bold long@ | |
1253 | to ensure they have higher precision than ordinary floating point variables. | |
1254 | The default precision is | |
1255 | \fBshort\fR. | |
1256 | .NH 3 | |
1257 | Common | |
1258 | .PP | |
1259 | Certain objects called | |
1260 | .I common\ areas | |
1261 | have external scope, | |
1262 | and may be referenced by any procedure that has a declaration for the name using a | |
1263 | .DS C | |
1264 | \fBcommon ( \fI commonareaname \fB)\fR | |
1265 | .DE | |
1266 | attribute. | |
1267 | All of the variables declared with a particular \fBcommon\fR attribute are in the same | |
1268 | block; the order in which they are declared is significant. | |
1269 | Declarations for the same block in differing procedures must have the variables in the same order and with the | |
1270 | same types, precision, and shapes, though not necessarily with the same names. | |
1271 | .NH 3 | |
1272 | External | |
1273 | .PP | |
1274 | If a name is used as the procedure name in a procedure invocation, | |
1275 | it is implicitly declared to have the | |
1276 | .B external | |
1277 | attribute. | |
1278 | If a procedure name is to be passed as an argument, it is necessary to declare | |
1279 | it in a statement of the form | |
1280 | .DS B | |
1281 | \fBexternal \*([[ \fIname \fB\*(]]\fR | |
1282 | .DE | |
1283 | If a name has the external attribute and it is a formal argument of | |
1284 | the procedure, | |
1285 | then it is associated with a procedure identifier passed as an actual argument | |
1286 | at each call. | |
1287 | If the name is not a formal argument, then that name is the actual name | |
1288 | of a procedure, as it appears in the corresponding | |
1289 | .B procedure | |
1290 | statement. | |
1291 | .NH 2 | |
1292 | Variable List | |
1293 | .PP | |
1294 | The elements of a variable list in a declaration | |
1295 | consist of a name, | |
1296 | an optional dimension specification, | |
1297 | and an optional initial value specification. | |
1298 | The name follows the usual rules. | |
1299 | The dimension specification is the same form and meaning as the parenthesized list in an | |
1300 | .B array | |
1301 | attribute. | |
1302 | The initial value specification is an equal sign (\fB=\fR) followed by a constant expression. | |
1303 | If the name is an array, the right side of the equal sign may be a parenthesized list of constant expressions, | |
1304 | or repeated elements or lists; the total number of elements in the list must not exceed the number of elements of the | |
1305 | array, which are filled in column-major order. | |
1306 | .NH 2 | |
1307 | The Initial Statement | |
1308 | .PP | |
1309 | An initial value may also be specified for a simple variable, | |
1310 | array, array element, or member of a structure | |
1311 | using a statement of the form | |
1312 | .DS B | |
1313 | \fBinitial \*([[ \fIvar \fB= \fIval \*(]]\fR | |
1314 | .DE | |
1315 | The @var@ may be a variable name, array element specification, or member of structure. | |
1316 | The right side follows the same rules as for an initial value specification | |
1317 | in other declaration statements. | |
1318 | .NH 1 | |
1319 | EXECUTABLE STATEMENTS | |
1320 | .PP | |
1321 | Every useful EFL program contains executable statements \(em | |
1322 | otherwise it would not do anything and would not need to be run. | |
1323 | Statements are frequently made up of other statements. | |
1324 | Blocks are the most obvious case, | |
1325 | but many other forms contain statements as constituents. | |
1326 | .PP | |
1327 | To increase the legibility of EFL programs, | |
1328 | some of the statement forms can be broken without an explicit continuation. | |
1329 | A square (\fR\(sq\fP) in the syntax represents a point where the end of a line will be ignored. | |
1330 | .NH 2 | |
1331 | Expression Statements | |
1332 | .NH 3 | |
1333 | Subroutine Call | |
1334 | .PP | |
1335 | A procedure invocation that returns no value is known as a subroutine call. | |
1336 | Such an invocation is a statement. | |
1337 | Examples are | |
1338 | .DS B | |
1339 | .B | |
1340 | work(in, out) | |
1341 | run(\|) | |
1342 | .R | |
1343 | .DE | |
1344 | .PP | |
1345 | Input/output statements (see Section 7.7) | |
1346 | resemble procedure invocations | |
1347 | but do not yield a value. | |
1348 | If an error occurs | |
1349 | the program stops. | |
1350 | .NH 3 | |
1351 | Assignment Statements | |
1352 | .PP | |
1353 | An expression that is a simple assignment (\fB=\fR) or | |
1354 | a compound assignment (\fB+=\fR etc.) is a statement: | |
1355 | .DS B | |
1356 | .B | |
1357 | a = b | |
1358 | a = sin(x)/6 | |
1359 | x \(**= y | |
1360 | .R | |
1361 | .DE | |
1362 | .NH 2 | |
1363 | Blocks | |
1364 | .PP | |
1365 | A block is a compound statement that acts as a statement. | |
1366 | A block begins with a left brace, | |
1367 | optionally followed by declarations, | |
1368 | optionally followed by executable statements, | |
1369 | followed by a right brace. | |
1370 | A block may be used anywhere a statement is permitted. | |
1371 | A block is not an expression and does not have a value. | |
1372 | An example of a block is | |
1373 | .DS B | |
1374 | .B | |
1375 | { | |
1376 | integer i # this variable is unknown outside the braces | |
1377 | .sp .3 | |
1378 | big = 0 | |
1379 | do i = 1,n | |
1380 | if(big < a(i)) | |
1381 | big = a(i) | |
1382 | } | |
1383 | .R | |
1384 | .DE | |
1385 | .NH 2 | |
1386 | Test Statements | |
1387 | .PP | |
1388 | Test statements permit execution of certain statements conditional on the truth of a predicate. | |
1389 | .NH 3 | |
1390 | If Statement | |
1391 | .PP | |
1392 | The simplest of the test statements is the | |
1393 | .B if | |
1394 | statement, of form | |
1395 | .DS C | |
1396 | \fBif ( \fIlogical-expression\fB ) \fR\(sq\fP \fIstatement\fR | |
1397 | .DE | |
1398 | The logical expression is evaluated; | |
1399 | if it is true, then the | |
1400 | .I statement | |
1401 | is executed. | |
1402 | .NH 3 | |
1403 | If-Else | |
1404 | .PP | |
1405 | A more general statement is of the form | |
1406 | .DS B | |
1407 | \fBif ( \fIlogical-expression \fB) \fR\(sq\fP \fI statement-1 \fR\(sq\fP \fBelse \fR\(sq\fP \fI statement-2 \fR | |
1408 | .DE | |
1409 | If the expression is | |
1410 | .B true | |
1411 | then | |
1412 | .I statement-1 | |
1413 | is executed, otherwise | |
1414 | .I statement-2 | |
1415 | is executed. | |
1416 | Either of the consequent statements may itself be an | |
1417 | .B if-else | |
1418 | so a completely nested test sequence is possible: | |
1419 | .DS B | |
1420 | .B | |
1421 | if(x<y) | |
1422 | if(a<b) | |
1423 | k = 1 | |
1424 | else | |
1425 | k = 2 | |
1426 | else | |
1427 | if(a<b) | |
1428 | m = 1 | |
1429 | else | |
1430 | m = 2 | |
1431 | .R | |
1432 | .DE | |
1433 | An | |
1434 | .B else | |
1435 | applies to the nearest preceding un-\fBelse\fRd \fBif\fR. | |
1436 | A more common use is as a sequential test: | |
1437 | .DS B | |
1438 | .B | |
1439 | if(x==1) | |
1440 | k = 1 | |
1441 | else if(x==3 | x==5) | |
1442 | k = 2 | |
1443 | else | |
1444 | k = 3 | |
1445 | .R | |
1446 | .DE | |
1447 | .NH 3 | |
1448 | Select Statement | |
1449 | .PP | |
1450 | A multiway test on the value of a quantity is succinctly stated as a | |
1451 | .B select | |
1452 | statement, which has the general form | |
1453 | .DS B | |
1454 | \fBselect( \fIexpression\fB ) \fR\(sq\fP \fIblock\fR | |
1455 | .DE | |
1456 | Inside the block | |
1457 | two special types of labels are recognized. | |
1458 | A prefix of the form | |
1459 | .DS B | |
1460 | \fBcase \fI\*([[ constant \*(]] \fB:\fR | |
1461 | .DE | |
1462 | marks the statement to which control is passed if the | |
1463 | expression | |
1464 | in the select has a value equal to one of the case constants. | |
1465 | If the expression equals none of these constants, but there is | |
1466 | a label | |
1467 | .B default | |
1468 | inside the select, | |
1469 | a branch is taken to that point; | |
1470 | otherwise the statement following the right brace is executed. | |
1471 | Once execution begins at a | |
1472 | .B case | |
1473 | or | |
1474 | .B default | |
1475 | label, it continues until the next | |
1476 | .B case | |
1477 | or | |
1478 | .B default | |
1479 | is encountered. | |
1480 | The | |
1481 | .B else-if | |
1482 | example above is better written as | |
1483 | .DS B | |
1484 | .B | |
1485 | select(x) | |
1486 | { | |
1487 | case 1: | |
1488 | k = 1 | |
1489 | case 3,5: | |
1490 | k = 2 | |
1491 | default: | |
1492 | k = 3 | |
1493 | } | |
1494 | .R | |
1495 | .DE | |
1496 | Note that control does not `fall through' to the next case. | |
1497 | .NH 2 | |
1498 | Loops | |
1499 | .PP | |
1500 | The loop forms provide the best way of repeating a statement | |
1501 | or sequence of operations. | |
1502 | The simplest (\fBwhile\fR) form is theoretically sufficient, but it is very convenient to have | |
1503 | the more general loops available, since each expresses a mode of control | |
1504 | that arises frequently in practice. | |
1505 | .NH 3 | |
1506 | While Statement | |
1507 | .PP | |
1508 | This construct has the form | |
1509 | .DS C | |
1510 | \fBwhile ( \fIlogical-expression\fB ) \fR\(sq\fP \fIstatement\fR | |
1511 | .DE | |
1512 | The expression is evaluated; if it is true, the statement is executed, and then the test is performed again. | |
1513 | If the expression is false, execution proceeds to the next statement. | |
1514 | .NH 2 | |
1515 | For Statement | |
1516 | .PP | |
1517 | The | |
1518 | .B for | |
1519 | statement is a more elaborate looping construct. | |
1520 | It has the form | |
1521 | .DS C | |
1522 | \fBfor ( \fIinitial-statement \fB, \fR\(sq\fP \fIlogical-expression \fB, \fR\(sq\fP \fI iteration-statement \fB) \fR\(sq\fP \fIbody-statement | |
1523 | .DE | |
1524 | Except for the behavior of the | |
1525 | .B next | |
1526 | statement (see Section 7.6.3), this construct is equivalent to | |
1527 | .DS B | |
1528 | \fIinitial-statement | |
1529 | \fBwhile ( \fIlogical-expression\fB ) | |
1530 | { | |
1531 | \fIbody-statement | |
1532 | \fIiteration-statement | |
1533 | } | |
1534 | .DE | |
1535 | This form is useful for general arithmetic iterations, and for various pointer-type operations. | |
1536 | The sum of the integers from 1 to 100 can be computed by the fragment | |
1537 | .DS B | |
1538 | .B | |
1539 | n = 0 | |
1540 | for(i = 1, i <= 100, i += 1) | |
1541 | n += i | |
1542 | .R | |
1543 | .DE | |
1544 | Alternatively, the computation could be done by the single statement | |
1545 | .DS B | |
1546 | .B | |
1547 | for( { n = 0 ; i = 1 } , i<=100 , { n += i ; ++i } ) | |
1548 | ; | |
1549 | .R | |
1550 | .DE | |
1551 | Note that the body of the | |
1552 | .B for | |
1553 | loop is a null statement in this case. | |
1554 | An example of following a linked list will be given later. | |
1555 | .NH 3 | |
1556 | Repeat Statement | |
1557 | .PP | |
1558 | The statement | |
1559 | .DS B | |
1560 | \fBrepeat \fR\(sq\fP \fIstatement\fR | |
1561 | .DE | |
1562 | executes the statement, then does it again, without any termination test. | |
1563 | Obviously, a test inside the | |
1564 | .I statement | |
1565 | is needed to stop the loop. | |
1566 | .NH 3 | |
1567 | Repeat...Until Statement | |
1568 | .PP | |
1569 | The | |
1570 | .B while | |
1571 | loop performs a test before each iteration. | |
1572 | The statement | |
1573 | .DS B | |
1574 | \fBrepeat \fR\(sq \fIstatement \fR\(sq \fBuntil ( \fIlogical-expression \fB) | |
1575 | .DE | |
1576 | executes the | |
1577 | .I statement, | |
1578 | then evaluates the logical; | |
1579 | if the logical is | |
1580 | true the loop is complete; | |
1581 | otherwise control returns to the | |
1582 | .I statement. | |
1583 | Thus, the body is always executed at least once. | |
1584 | The | |
1585 | .B until | |
1586 | refers to the nearest preceding | |
1587 | .B repeat | |
1588 | that has not been paired with an | |
1589 | .B until. | |
1590 | In practice, this appears to be the least frequently used looping construct. | |
1591 | .NH 3 | |
1592 | Do Loops | |
1593 | .PP | |
1594 | The simple arithmetic progression is a very common one in numerical applications. | |
1595 | EFL has a special loop form for ranging over an ascending arithmetic sequence | |
1596 | .DS B | |
1597 | \fBdo \fIvariable \fB= \fIexpression-1, expression-2, expression-3\fR | |
1598 | \fIstatement\fR | |
1599 | .DE | |
1600 | The variable is first given the value | |
1601 | .I expression-1. | |
1602 | The statement is executed, then | |
1603 | .I expression-3 | |
1604 | is added to the variable. | |
1605 | The loop is repeated until the variable exceeds | |
1606 | .I expression-2. | |
1607 | If | |
1608 | .I expression-3 | |
1609 | and the preceding comma are omitted, the increment is taken to be 1. | |
1610 | The loop above is equivalent to | |
1611 | .DS B | |
1612 | t2 = expression-2 | |
1613 | t3 = expression-3 | |
1614 | for(variable = expression-1 , variable <= t2 , variable += t3) | |
1615 | statement | |
1616 | .DE | |
1617 | (The compiler translates EFL | |
1618 | .B do | |
1619 | statements into Fortran | |
1620 | DO statements, | |
1621 | which are in turn usually compiled into excellent code.) | |
1622 | The | |
1623 | .B do | |
1624 | .I variable | |
1625 | may not be changed inside of the loop, | |
1626 | and | |
1627 | .I expression-1 | |
1628 | must not exceed | |
1629 | .I expression-2. | |
1630 | The sum of the first hundred positive integers could be computed by | |
1631 | .DS B | |
1632 | .B | |
1633 | n = 0 | |
1634 | do i = 1, 100 | |
1635 | n += i | |
1636 | .R | |
1637 | .DE | |
1638 | .NH 2 | |
1639 | Branch Statements | |
1640 | .PP | |
1641 | Most of the need for branch statements in programs can be | |
1642 | averted by using the loop and test constructs, | |
1643 | but there are programs where they are very useful. | |
1644 | .NH 3 | |
1645 | Goto Statement | |
1646 | .PP | |
1647 | The most general, and most dangerous, branching statement is the simple unconditional | |
1648 | .DS B | |
1649 | \fBgoto \fIlabel\fR | |
1650 | .DE | |
1651 | After executing this statement, the next statement performed is the one following the given label. | |
1652 | Inside of a | |
1653 | .B select | |
1654 | the case labels of that block may be used as labels, as in the following example: | |
1655 | .KS | |
1656 | .B | |
1657 | .TS | |
1658 | center; | |
1659 | lll . | |
1660 | select(k) | |
1661 | { | |
1662 | case 1: | |
1663 | error(7) | |
1664 | ||
1665 | case 2: | |
1666 | k = 2 | |
1667 | goto case 4 | |
1668 | ||
1669 | case 3: | |
1670 | k = 5 | |
1671 | goto case 4 | |
1672 | ||
1673 | case 4: | |
1674 | fixup(k) | |
1675 | goto default | |
1676 | ||
1677 | default: | |
1678 | prmsg("ouch") | |
1679 | } | |
1680 | .TE | |
1681 | .KE | |
1682 | .R | |
1683 | (If two | |
1684 | .B select | |
1685 | statements are nested, | |
1686 | the case labels of the outer | |
1687 | .B select | |
1688 | are not accessible from the inner one.) | |
1689 | .NH 3 | |
1690 | Break Statement | |
1691 | .PP | |
1692 | A safer statement is one which transfers control to the statement following the current | |
1693 | .B select | |
1694 | or loop form. | |
1695 | A statement of this sort is almost always needed in a | |
1696 | .B repeat | |
1697 | loop: | |
1698 | .DS B | |
1699 | .B | |
1700 | repeat | |
1701 | { | |
1702 | \fIdo a computation | |
1703 | if\|( finished ) | |
1704 | \fBbreak\fI | |
1705 | } | |
1706 | .R | |
1707 | .DE | |
1708 | More general forms permit controlling a branch out of more than one construct. | |
1709 | .DS C | |
1710 | .B | |
1711 | break 3 | |
1712 | .R | |
1713 | .DE | |
1714 | transfers control to the statement following the third loop and/or | |
1715 | .B select | |
1716 | surrounding the statement. | |
1717 | It is possible to specify which type of construct | |
1718 | (\fBfor\fR, \fBwhile\fR, \fBrepeat\fR, \fBdo\fR, or \fBselect\fR) | |
1719 | is to be counted. | |
1720 | The statement | |
1721 | .DS C | |
1722 | .B | |
1723 | break while | |
1724 | .R | |
1725 | .DE | |
1726 | breaks out of the first surrounding | |
1727 | .B while | |
1728 | statement. | |
1729 | Either of the statements | |
1730 | .DS B | |
1731 | .B | |
1732 | break 3 for | |
1733 | break for 3 | |
1734 | .R | |
1735 | .DE | |
1736 | will transfer to the statement after the third enclosing | |
1737 | .B for | |
1738 | loop. | |
1739 | .NH 3 | |
1740 | Next Statement | |
1741 | .PP | |
1742 | The | |
1743 | .B next | |
1744 | statement causes the first surrounding loop statement to go on to the next iteration: | |
1745 | the next operation performed is the | |
1746 | test of a | |
1747 | .B while, | |
1748 | the | |
1749 | .I iteration-statement | |
1750 | of a | |
1751 | .B for, | |
1752 | the body of a | |
1753 | .B repeat, | |
1754 | the test of a | |
1755 | .B repeat...until, | |
1756 | or the increment of a | |
1757 | .B do. | |
1758 | Elaborations similar to those for | |
1759 | .B break | |
1760 | are available: | |
1761 | .DS B | |
1762 | .B | |
1763 | next | |
1764 | next 3 | |
1765 | next 3 for | |
1766 | next for 3 | |
1767 | .R | |
1768 | .DE | |
1769 | A | |
1770 | .B next | |
1771 | statement ignores | |
1772 | .B select | |
1773 | statements. | |
1774 | .NH 3 | |
1775 | Return | |
1776 | .PP | |
1777 | The last statement of a procedure is followed by a return of control to the caller. | |
1778 | If it is desired to effect such a return from any other point in the procedure, a | |
1779 | .DS B | |
1780 | \fBreturn\fR | |
1781 | .DE | |
1782 | statement may be executed. | |
1783 | Inside a function procedure, the function value is specified as an argument of the statement: | |
1784 | .DS B | |
1785 | \fBreturn ( \fIexpression \fB) | |
1786 | .DE | |
1787 | .NH 2 | |
1788 | Input/Output Statements | |
1789 | .PP | |
1790 | EFL has two input statements (\fBread\fR and \fBreadbin\fR), | |
1791 | two output statements (\fBwrite\fR and \fBwritebin\fR), | |
1792 | and three control statements (\fBendfile\fR, \fBrewind\fR, and \fBbackspace\fR). | |
1793 | These forms may be used either as a primary with a | |
1794 | .B integer | |
1795 | value | |
1796 | or as a statement. | |
1797 | If an exception occurs when one of these forms is used as a statement, | |
1798 | the result is undefined but will probably be treated as a fatal error. | |
1799 | If they are used in a context where they return a value, | |
1800 | they return | |
1801 | zero if no exception occurs. | |
1802 | For the input forms, a negative value indicates end-of-file and | |
1803 | a positive value an error. | |
1804 | The input/output part of EFL very strongly reflects the facilities of Fortran. | |
1805 | .NH 3 | |
1806 | Input/Output Units | |
1807 | .PP | |
1808 | Each I/O statement refers to a `unit', | |
1809 | identified by a small positive integer. | |
1810 | Two special units are defined by EFL, | |
1811 | the | |
1812 | .I "standard input unit" | |
1813 | and the | |
1814 | .I "standard output unit." | |
1815 | These particular units are assumed if no unit is specified in an I/O transmission statement. | |
1816 | .PP | |
1817 | The data on the unit are organized into | |
1818 | .I records. | |
1819 | These records may be read or written in a fixed sequence, | |
1820 | and each transmission moves an integral number of records. | |
1821 | Transmission proceeds from the first record until the | |
1822 | .I "end of file." | |
1823 | .NH 3 | |
1824 | Binary Input/Output | |
1825 | .PP | |
1826 | The | |
1827 | .B readbin | |
1828 | and | |
1829 | .B writebin | |
1830 | statements transmit data in a machine-dependent but swift manner. | |
1831 | The statements are of the form | |
1832 | .DS B | |
1833 | \fBwritebin( \fIunit \fB, \fIbinary-output-list \fB)\fR | |
1834 | \fBreadbin( \fIunit \fB, \fIbinary-input-list \fB)\fR | |
1835 | .DE | |
1836 | Each statement moves one unformatted record between storage and the device. | |
1837 | The | |
1838 | .I unit | |
1839 | is an integer expression. | |
1840 | A | |
1841 | .I binary-output-list | |
1842 | is an | |
1843 | .I iolist | |
1844 | (see below) without any format specifiers. | |
1845 | A | |
1846 | .I binary-input-list | |
1847 | is an | |
1848 | .I iolist | |
1849 | without format specifiers in which each of the expressions | |
1850 | is a variable name, array element, or structure member. | |
1851 | .NH 3 | |
1852 | Formatted Input/Output | |
1853 | .PP | |
1854 | The | |
1855 | .B read | |
1856 | and | |
1857 | .B write | |
1858 | statements | |
1859 | transmit data in the form of lines of characters. | |
1860 | Each statement moves one or more records (lines). | |
1861 | Numbers are translated into decimal notation. | |
1862 | The exact form of the lines is determined by format specifications, | |
1863 | whether provided explicitly in the statement | |
1864 | or implicitly. | |
1865 | The syntax of the statements is | |
1866 | .DS B | |
1867 | \fBwrite( \fIunit \fB,\fI formatted-output-list \fB)\fR | |
1868 | \fBread( \fIunit \fB,\fI formatted-input-list \fB)\fR | |
1869 | .DE | |
1870 | The lists are of the same form as for binary I/O, | |
1871 | except that the lists may include format specifications. | |
1872 | If the | |
1873 | .I unit | |
1874 | is omitted, the standard input or output unit is used. | |
1875 | .NH 3 | |
1876 | Iolists | |
1877 | .PP | |
1878 | An | |
1879 | .I iolist | |
1880 | specifies a set of values to be written or a set of variables into which | |
1881 | values are to be read. | |
1882 | An | |
1883 | .I iolist | |
1884 | is a list of one or more | |
1885 | .I ioexpressions | |
1886 | of the form | |
1887 | .DS B | |
1888 | \fIexpression | |
1889 | \fB{ \fIiolist \fB} | |
1890 | \fIdo-specification \fB{ \fIiolist \fB}\fR | |
1891 | .DE | |
1892 | For formatted I/O, | |
1893 | an | |
1894 | .I ioexpression | |
1895 | may also have the forms | |
1896 | .DS B | |
1897 | \fIioexpression \fB:\fI format-specifier | |
1898 | \fB:\fI format-specifier\fR | |
1899 | .DE | |
1900 | A | |
1901 | .I do-specification | |
1902 | looks just like a | |
1903 | .B do | |
1904 | statement, and has a similar effect: | |
1905 | the values in the braces are transmitted repeatedly until the | |
1906 | .B do | |
1907 | execution is complete. | |
1908 | .NH 3 | |
1909 | Formats | |
1910 | .PP | |
1911 | The following are permissible | |
1912 | .I format-specifiers. | |
1913 | The quantities | |
1914 | @w@, @d@, and @k@ must be integer constant expressions. | |
1915 | .KS | |
1916 | .TS | |
1917 | center; | |
1918 | ll . | |
1919 | \fBi(\fIw\fB)\fR integer with \fIw\fR digits | |
1920 | \fBf(\fIw\fB,\fId\fB)\fR floating point number of \fIw\fR characters, | |
1921 | \fId\fR of them to the right of the decimal point. | |
1922 | \fBe(\fIw\fB,\fId\fB)\fR floating point number of \fIw\fR characters, | |
1923 | \fId\fR of them to the right of the decimal point, | |
1924 | with the exponent field marked with the letter \fBe\fR | |
1925 | \fBl(\fIw\fB)\fR logical field of width \fIw\fR characters, | |
1926 | the first of which is \fBt\fR or \fBf\fR | |
1927 | (the rest are blank on output, ignored on input) | |
1928 | standing for \fBtrue\fR and \fBfalse\fR respectively | |
1929 | \fBc\fR character string of width equal to the length of the datum | |
1930 | \fBc(\fIw\fB)\fR character string of width \fIw\fR | |
1931 | \fBs(\fIk\fB)\fR skip \fIk\fR lines | |
1932 | \fBx(\fIk\fB)\fR skip \fIk\fR spaces | |
1933 | " ... " use the characters inside the string as a Fortran format | |
1934 | .TE | |
1935 | .KE | |
1936 | If no format is specified for an item in a formatted input/output statement, | |
1937 | a default form is chosen. | |
1938 | .PP | |
1939 | If an item in a list is an array name, | |
1940 | then the entire array is transmitted as a sequence of elements, | |
1941 | each with its own format. | |
1942 | The elements are transmitted in column-major order, | |
1943 | the same order used for array initializations. | |
1944 | .NH 3 | |
1945 | Manipulation statements | |
1946 | .PP | |
1947 | The three input/output statements | |
1948 | .DS B | |
1949 | .B | |
1950 | backspace(@unit@) | |
1951 | rewind(@unit@) | |
1952 | endfile(@unit@) | |
1953 | .R | |
1954 | .DE | |
1955 | look like ordinary procedure calls, | |
1956 | but may be used either as statements or as integer expressions | |
1957 | which yield | |
1958 | non-zero | |
1959 | if an error is detected. | |
1960 | .B backspace | |
1961 | causes the specified unit to back up, | |
1962 | so that the next | |
1963 | read will re-read the previous record, | |
1964 | and the next write will over-write it. | |
1965 | .B rewind | |
1966 | moves the device to its beginning, | |
1967 | so that the next input statement will read the first record. | |
1968 | .B endfile | |
1969 | causes the file to be marked so that the record most recently written will be the last record on the file, | |
1970 | and any attempt to read past is an error. | |
1971 | .NH 1 | |
1972 | PROCEDURES | |
1973 | .PP | |
1974 | Procedures are the basic unit of an EFL program, | |
1975 | and provide the means of segmenting a program into separately compilable | |
1976 | and named parts. | |
1977 | .NH 2 | |
1978 | Procedure Statement | |
1979 | .PP | |
1980 | Each procedure begins with a statement of one of the forms | |
1981 | .DS B | |
1982 | \fBprocedure | |
1983 | \fIattributes \fBprocedure \fIprocedurename | |
1984 | \fIattributes \fBprocedure \fIprocedurename \fB( )\fR | |
1985 | \fIattributes \fBprocedure \fIprocedurename \fB( \fI\*([[ name \*(]] \fB) \fR | |
1986 | .DE | |
1987 | The first case specifies the main procedure, where execution begins. | |
1988 | In the two other cases, the | |
1989 | .I attributes | |
1990 | may specify precision and type, | |
1991 | or they may be omitted entirely. | |
1992 | The precision and type of the procedure may be declared in an ordinary declaration statement. | |
1993 | If no type is declared, then the procedure is called a | |
1994 | .I subroutine | |
1995 | and no value may be returned for it. | |
1996 | Otherwise, the procedure is a function and a value of the declared type is returned for each call. | |
1997 | Each | |
1998 | .I name | |
1999 | inside the parentheses in the last form above is called a | |
2000 | .I "formal argument" | |
2001 | of the procedure. | |
2002 | .NH 2 | |
2003 | End Statement | |
2004 | .PP | |
2005 | Each procedure terminates with a statement | |
2006 | .DS C | |
2007 | .B | |
2008 | end | |
2009 | .R | |
2010 | .DE | |
2011 | .NH 2 | |
2012 | Argument Association | |
2013 | .PP | |
2014 | When a procedure is invoked, | |
2015 | the actual arguments are evaluated. | |
2016 | If an actual argument is the name of a variable, an array element, | |
2017 | or a structure member, | |
2018 | that entity becomes associated with the formal argument, | |
2019 | and the procedure may reference the values in the object, | |
2020 | and assign to it. | |
2021 | Otherwise, | |
2022 | the value of the actual is associated with the formal argument, | |
2023 | but the procedure may not attempt to change the value of that formal argument. | |
2024 | .PP | |
2025 | If the value of one of the arguments is changed in the procedure, | |
2026 | it is not permitted that the corresponding actual argument be associated | |
2027 | with another formal argument or with a | |
2028 | .B common | |
2029 | element that is referenced in the procedure. | |
2030 | .NH 2 | |
2031 | Execution and Return Values | |
2032 | .PP | |
2033 | After actual and formal arguments have been associated, | |
2034 | control passes to the first executable statement of the procedure. | |
2035 | Control returns to the invoker | |
2036 | either when the | |
2037 | .B end | |
2038 | statement of the procedure is reached or when a | |
2039 | .B return | |
2040 | statement is executed. | |
2041 | If the procedure is a function | |
2042 | (has a declared type), | |
2043 | and a | |
2044 | @bold return( value )@ | |
2045 | is executed, the value | |
2046 | is coerced to the correct type and precision and returned. | |
2047 | .NH 2 | |
2048 | Known Functions | |
2049 | .PP | |
2050 | A number of functions are known to EFL, and need not be declared. | |
2051 | The compiler knows the types of these functions. | |
2052 | Some of them are | |
2053 | .I generic; | |
2054 | i.e., they name a family of functions that differ in the types of their arguments and return values. | |
2055 | The compiler chooses which element of the set to invoke based upon the attributes of the actual arguments. | |
2056 | .NH 3 | |
2057 | Minimum and Maximum Functions | |
2058 | .PP | |
2059 | The generic functions are | |
2060 | .B min | |
2061 | and | |
2062 | .B max. | |
2063 | The | |
2064 | .B min | |
2065 | calls return the value of their smallest argument; | |
2066 | the | |
2067 | .B max | |
2068 | calls return the value of their largest argument. | |
2069 | These are the only functions that may take different numbers of arguments in different calls. | |
2070 | If any of the arguments are | |
2071 | .B "long real" | |
2072 | then the result is | |
2073 | .B "long real". | |
2074 | Otherwise, if any of the arguments are | |
2075 | .B real | |
2076 | then the result is | |
2077 | .B real; | |
2078 | otherwise all the arguments and the result must be | |
2079 | .B integer. | |
2080 | Examples are | |
2081 | .DS B | |
2082 | .B | |
2083 | min(5, x, \-3.20) | |
2084 | max(i, z) | |
2085 | .R | |
2086 | .DE | |
2087 | .NH 3 | |
2088 | Absolute Value | |
2089 | .PP | |
2090 | The | |
2091 | .B abs | |
2092 | function is a generic function that returns the magnitude of its argument. | |
2093 | For | |
2094 | integer and real arguments the type of the result is identical to the type of the argument; | |
2095 | for complex arguments the type of the result is the real of the same precision. | |
2096 | .NH 3 | |
2097 | Elementary Functions | |
2098 | .PP | |
2099 | The following generic functions take arguments of | |
2100 | \fBreal\fR, \fBlong real\fR, or \fBcomplex\fR | |
2101 | type and return a result of the same type: | |
2102 | .DS | |
2103 | .TS | |
2104 | center; | |
2105 | ll. | |
2106 | .B | |
2107 | sin sine function | |
2108 | cos cosine function | |
2109 | exp exponential function (@e sup x@). | |
2110 | log natural (base \fIe\fP) logarithm | |
2111 | log10 common (base 10) logarithm | |
2112 | sqrt square root function (@sqrt x@). | |
2113 | .R | |
2114 | .TE | |
2115 | .DE | |
2116 | In addition, the following functions accept only | |
2117 | .B real | |
2118 | or | |
2119 | .B "long real" | |
2120 | arguments: | |
2121 | .DS | |
2122 | .TS | |
2123 | center; | |
2124 | ll . | |
2125 | \fBatan\fR @atan(x) = tan sup -1 x@ | |
2126 | \fBatan2\fR @atan2(x,y) = tan sup -1 x over y@ | |
2127 | .TE | |
2128 | .DE | |
2129 | .NH 3 | |
2130 | Other Generic Functions | |
2131 | .PP | |
2132 | The | |
2133 | .B sign | |
2134 | functions takes two arguments of identical type; | |
2135 | @bold sign (x,y) ~=~ sgn(y) |x|@. | |
2136 | The | |
2137 | .B mod | |
2138 | function yields the remainder of its first argument when divided by its second. | |
2139 | These functions accept integer and real arguments. | |
2140 | .NH 1 | |
2141 | ATAVISMS | |
2142 | .PP | |
2143 | Certain facilities are included in the EFL language to ease the conversion of old | |
2144 | Fortran or Ratfor programs to EFL. | |
2145 | .NH 2 | |
2146 | Escape Lines | |
2147 | .PP | |
2148 | In order to make use of nonstandard features of the local Fortran compiler, | |
2149 | it is occasionally necessary to pass a particular line through to the EFL compiler output. | |
2150 | A line that begins with a percent sign (`\fB%\fR') | |
2151 | is copied through to the output, with the percent sign removed but no other change. | |
2152 | Inside of a procedure, each escape line is treated as an executable statement. | |
2153 | If a sequence of lines constitute a continued Fortran statement, they should be enclosed in braces. | |
2154 | .NH 2 | |
2155 | Call Statement | |
2156 | .PP | |
2157 | A subroutine call may be preceded by the keyword | |
2158 | .B call. | |
2159 | .DS B | |
2160 | .B | |
2161 | call joe | |
2162 | call work(17) | |
2163 | .R | |
2164 | .DE | |
2165 | .NH 2 | |
2166 | Obsolete Keywords | |
2167 | .PP | |
2168 | The following keywords are recognized as synonyms of EFL keywords: | |
2169 | .TS | |
2170 | center; | |
2171 | cc | |
2172 | ll. | |
2173 | Fortran EFL | |
2174 | .sp .3 | |
2175 | \fBdouble precision long real | |
2176 | \fBfunction procedure | |
2177 | \fBsubroutine procedure \fI(untyped)\fR | |
2178 | .TE | |
2179 | .NH 2 | |
2180 | Numeric Labels | |
2181 | .PP | |
2182 | Standard statement labels are identifiers. | |
2183 | A numeric (positive integer constant) label is also permitted; | |
2184 | the colon is optional following a numeric label. | |
2185 | .NH 2 | |
2186 | Implicit Declarations | |
2187 | .PP | |
2188 | If a name is used but does not appear in a declaration, | |
2189 | the EFL compiler gives a warning and assumes a declaration for it. | |
2190 | If it is used in the context of a procedure invocation, it is assumed to be a procedure name; | |
2191 | otherwise it is assumed to be a local variable defined at nesting level 1 in the current procedure. | |
2192 | The assumed type is determined by the first letter of the name. | |
2193 | The association of letters and types may be given in an | |
2194 | .B implicit | |
2195 | statement, with syntax | |
2196 | .DS C | |
2197 | \fBimplicit ( \fIletter-list\fB ) \fI type \fR | |
2198 | .DE | |
2199 | where a | |
2200 | .I letter-list | |
2201 | is a list of individual letters or ranges (pair of letters separated by a minus sign). | |
2202 | If no | |
2203 | .B implicit | |
2204 | statement appears, the following rules are assumed: | |
2205 | .DS B | |
2206 | .B | |
2207 | implicit (a\-h, o\-z) real | |
2208 | implicit (i\-n) integer | |
2209 | .R | |
2210 | .DE | |
2211 | .NH 2 | |
2212 | Computed \fBgoto\fR | |
2213 | .PP | |
2214 | Fortran contains an indexed multi-way branch; this facility may be used in EFL | |
2215 | by the computed GOTO: | |
2216 | .DS C | |
2217 | \fBgoto ( \fI\*([[ label \*(]] \fB), \fIexpression\fR | |
2218 | .DE | |
2219 | The expression must be of type integer and be positive but be no larger than the number of labels in the list. | |
2220 | Control is passed to the statement marked by the label whose position in the list is equal to the expression. | |
2221 | .NH 2 | |
2222 | Go To Statement | |
2223 | .PP | |
2224 | In unconditional and computed \fBgoto\fR | |
2225 | statements, it is permissible to separate the \fBgo\fR and \fBto\fR words, as in | |
2226 | .DS B | |
2227 | .B | |
2228 | go to xyz | |
2229 | .R | |
2230 | .DE | |
2231 | .NH 2 | |
2232 | Dot Names | |
2233 | .PP | |
2234 | Fortran uses a restricted character set, | |
2235 | and represents certain operators by multi-character sequences. | |
2236 | There is an option (\fBdots=on\fR; see Section 10.2) which forces the compiler to recognize the forms | |
2237 | in the second column below: | |
2238 | .DS | |
2239 | .B | |
2240 | .TS | |
2241 | center; | |
2242 | ll. | |
2243 | < .lt. | |
2244 | <= .le. | |
2245 | > .gt. | |
2246 | >= .ge. | |
2247 | == .eq. | |
2248 | \*~= .ne. | |
2249 | & .and. | |
2250 | | .or. | |
2251 | && .andand. | |
2252 | |\|| .oror. | |
2253 | \*~ .not. | |
2254 | true .true. | |
2255 | false .false. | |
2256 | .TE | |
2257 | .R | |
2258 | .DE | |
2259 | In this mode, no structure element may be named | |
2260 | .B lt, | |
2261 | .B le, | |
2262 | etc. | |
2263 | The readable forms in the left column are always recognized. | |
2264 | .NH 2 | |
2265 | Complex Constants | |
2266 | .PP | |
2267 | A complex constant may be written as a parenthesized list of real quantities, such as | |
2268 | .DS C | |
2269 | .B | |
2270 | (1.5, 3.0) | |
2271 | .R | |
2272 | .DE | |
2273 | The preferred notation is by a type coercion, | |
2274 | .DS C | |
2275 | .B | |
2276 | complex(1.5, 3.0) | |
2277 | .R | |
2278 | .DE | |
2279 | .NH 2 | |
2280 | Function Values | |
2281 | .PP | |
2282 | The preferred way to return a value from a function in EFL is the | |
2283 | @bold return ( value )@ | |
2284 | construct. | |
2285 | However, the name of the function acts as a variable to which values may be assigned; | |
2286 | an ordinary | |
2287 | @bold return@ | |
2288 | statement returns the last value assigned to that name as the function value. | |
2289 | .NH 2 | |
2290 | Equivalence | |
2291 | .PP | |
2292 | A statement of the form | |
2293 | .EQ C | |
2294 | bold equivalence ~ v sub 1 ,~ v sub 2 ,~ ...,~ v sub n | |
2295 | .EN | |
2296 | declares that each of the @v sub i@ starts at the same memory location. | |
2297 | Each of the @v sub i@ may be a variable name, array element name, or structure member. | |
2298 | .NH 2 | |
2299 | Minimum and Maximum Functions | |
2300 | .PP | |
2301 | There are a number of non-generic functions in this category, | |
2302 | which differ in the required types of the arguments and the type of the return value. | |
2303 | They may also have variable numbers of arguments, but all the arguments must have the same type. | |
2304 | .DS | |
2305 | .TS | |
2306 | center; | |
2307 | ccc | |
2308 | lll . | |
2309 | Function Argument Type Result Type | |
2310 | _ | |
2311 | .B | |
2312 | amin0 integer real | |
2313 | amin1 real real | |
2314 | min0 integer integer | |
2315 | min1 real integer | |
2316 | dmin1 long real long real | |
2317 | ||
2318 | amax0 integer real | |
2319 | amax1 real real | |
2320 | max0 integer integer | |
2321 | max1 real integer | |
2322 | dmax1 long real long real | |
2323 | .R | |
2324 | .TE | |
2325 | .DE | |
2326 | .NH 1 | |
2327 | COMPILER OPTIONS | |
2328 | .PP | |
2329 | A number of options can be used to control the output | |
2330 | and to tailor it for various compilers and systems. | |
2331 | The defaults chosen are conservative, but it is sometimes necessary to change the output to match peculiarities of the | |
2332 | target environment. | |
2333 | .PP | |
2334 | Options are set with statements of the form | |
2335 | .DS C | |
2336 | \fBoption \fI\*([[ \fIopt \fI\*(]]\fR | |
2337 | .DE | |
2338 | where each | |
2339 | .I opt | |
2340 | is of one of the forms | |
2341 | .DS B | |
2342 | .I | |
2343 | optionname | |
2344 | optionname \fB= \fIoptionvalue | |
2345 | .R | |
2346 | .DE | |
2347 | The | |
2348 | .I optionvalue | |
2349 | is either a constant (numeric or string) or | |
2350 | a name associated with that option. | |
2351 | The two names | |
2352 | .B yes | |
2353 | and | |
2354 | .B no | |
2355 | apply to a number of options. | |
2356 | .NH 2 | |
2357 | Default Options | |
2358 | .PP | |
2359 | Each option has a default setting. | |
2360 | It is possible to change the whole set of defaults to those appropriate | |
2361 | for a particular environment | |
2362 | by using the | |
2363 | .B system | |
2364 | option. | |
2365 | At present, the only valid values are | |
2366 | .B system=unix | |
2367 | and | |
2368 | .B system=gcos. | |
2369 | .NH 2 | |
2370 | Input Language Options | |
2371 | .PP | |
2372 | The | |
2373 | .B dots | |
2374 | option determines whether the compiler recognizes | |
2375 | .B .lt. | |
2376 | and similar forms. The default setting is | |
2377 | .B no. | |
2378 | .NH 2 | |
2379 | Input/Output Error Handling | |
2380 | .PP | |
2381 | The | |
2382 | .B ioerror | |
2383 | option can be given three values: | |
2384 | .B none | |
2385 | means that none of the I/O statements may be used in expressions, since there is no way to detect errors. | |
2386 | The implementation of the | |
2387 | .B ibm | |
2388 | form uses ERR= and END= clauses. | |
2389 | The implementation of the | |
2390 | .B fortran77 | |
2391 | form uses IOSTAT= clauses. | |
2392 | .NH 2 | |
2393 | Continuation Conventions | |
2394 | .PP | |
2395 | By default, continued Fortran statements are indicated by a character in column 6 (Standard Fortran). | |
2396 | The option | |
2397 | .B "continue=column1" | |
2398 | puts an ampersand (\fB&\fR) in the first column of the continued lines instead. | |
2399 | .NH 2 | |
2400 | Default Formats | |
2401 | .PP | |
2402 | If no format is specified for a datum in an | |
2403 | iolist | |
2404 | for a | |
2405 | .B read | |
2406 | or | |
2407 | .B write | |
2408 | statement, a default is provided. | |
2409 | The default formats can be changed by setting certain options | |
2410 | .DS | |
2411 | .TS | |
2412 | center; | |
2413 | cc | |
2414 | ll. | |
2415 | Option Type | |
2416 | _ | |
2417 | \fBiformat\fR integer | |
2418 | \fBrformat\fR real | |
2419 | \fBdformat\fR long real | |
2420 | \fBzformat\fR complex | |
2421 | \fBzdformat\fR long complex | |
2422 | \fBlformat\fR logical | |
2423 | .TE | |
2424 | .DE | |
2425 | The associated value must be a Fortran format, such as | |
2426 | .DS C | |
2427 | .B | |
2428 | option rformat=f22.6 | |
2429 | .R | |
2430 | .DE | |
2431 | .NH 2 | |
2432 | Alignments and Sizes | |
2433 | .PP | |
2434 | In order to implement | |
2435 | .B character | |
2436 | variables, structures, and the | |
2437 | .B sizeof | |
2438 | and | |
2439 | .B lengthof | |
2440 | operators, it is necessary to know how much space various Fortran data types require, | |
2441 | and what boundary alignment properties they demand. | |
2442 | The relevant options are | |
2443 | .DS | |
2444 | .B | |
2445 | .TS | |
2446 | center; | |
2447 | ccc | |
2448 | lll. | |
2449 | Fortran Type Size Option Alignment Option | |
2450 | _ | |
2451 | integer isize ialign | |
2452 | real rsize ralign | |
2453 | long real dsize dalign | |
2454 | complex zsize zalign | |
2455 | logical lsize lalign | |
2456 | .R | |
2457 | .TE | |
2458 | .DE | |
2459 | The sizes are given in terms of an arbitrary unit; | |
2460 | the alignment is given in the same units. | |
2461 | The option | |
2462 | .B charperint | |
2463 | gives the number of characters per | |
2464 | .B integer | |
2465 | variable. | |
2466 | .NH 2 | |
2467 | Default Input/Output Units | |
2468 | .PP | |
2469 | The options | |
2470 | .B ftnin | |
2471 | and | |
2472 | .B ftnout | |
2473 | are the numbers of the standard input and output units. | |
2474 | The default values are | |
2475 | .B ftnin=5 | |
2476 | and | |
2477 | .B ftnout=6. | |
2478 | .NH 2 | |
2479 | Miscellaneous Output Control Options | |
2480 | .PP | |
2481 | Each Fortran procedure generated by the compiler will be preceded by the value of the | |
2482 | .B procheader | |
2483 | option. | |
2484 | .PP | |
2485 | No Hollerith strings will be passed as subroutine arguments if | |
2486 | .B hollincall=no | |
2487 | is specified. | |
2488 | .PP | |
2489 | The Fortran statement numbers normally start at 1 and increase by 1. | |
2490 | It is possible to change the increment value by using the | |
2491 | .B deltastno | |
2492 | option. | |
2493 | .ta .5i 1i 1.5i 2i 2.5i 3.0i | |
2494 | .NH 1 | |
2495 | EXAMPLES | |
2496 | .PP | |
2497 | In order to show the flavor or programming in EFL, | |
2498 | we present a few examples. | |
2499 | They are short, but show some of the convenience of the language. | |
2500 | .NH 2 | |
2501 | File Copying | |
2502 | .PP | |
2503 | The following short program copies the standard input to the standard output, | |
2504 | provided that the input is a formatted file containing | |
2505 | lines no longer than a hundred characters. | |
2506 | .DS | |
2507 | .B | |
2508 | procedure # main program | |
2509 | character(100) line | |
2510 | ||
2511 | while( read( , line) == 0 ) | |
2512 | write( , line) | |
2513 | end | |
2514 | .R | |
2515 | .DE | |
2516 | Since | |
2517 | .B read | |
2518 | returns | |
2519 | zero | |
2520 | until the end of file (or a read error), | |
2521 | this program keeps reading and writing until the input is exhausted. | |
2522 | .NH 2 | |
2523 | Matrix Multiplication | |
2524 | .PP | |
2525 | The following procedure multiplies the | |
2526 | @m times n@ matrix a | |
2527 | by the | |
2528 | @n times p@ matrix b | |
2529 | to give the @m times p@ matrix c. | |
2530 | The calculation obeys the formula | |
2531 | @c sub ij ~=~ sum a sub ik b sub kj@. | |
2532 | .DS | |
2533 | .ta .7i 1.4i 2.1i 2.8i | |
2534 | .B | |
2535 | procedure matmul(a,b,c, m,n,p) | |
2536 | integer i, j, k, m, n, p | |
2537 | long real a(m,n), b(n,p), c(m,p) | |
2538 | .sp .3 | |
2539 | do i = 1,m | |
2540 | do j = 1,p | |
2541 | { | |
2542 | c(i,j) = 0 | |
2543 | do k = 1,n | |
2544 | c(i,j) += a(i,k) \(** b(k,j) | |
2545 | } | |
2546 | end | |
2547 | .R | |
2548 | .DE | |
2549 | .NH 2 | |
2550 | Searching a Linked List | |
2551 | .PP | |
2552 | Assume we have a list of pairs of numbers @(x,y)@. | |
2553 | The list is stored as a linked list sorted in ascending order of @x@ values. | |
2554 | The following procedure searches this list for a particular value of @x@ | |
2555 | and returns the corresponding @y@ value. | |
2556 | .DS | |
2557 | .B | |
2558 | .ta .7i 1.4i 2.1i 2.8i | |
2559 | define LAST 0 | |
2560 | define NOTFOUND \-1 | |
2561 | ||
2562 | integer procedure val(list, first, x) | |
2563 | ||
2564 | # list is an array of structures. | |
2565 | # Each structure contains a thread index value, an x, and a y value. | |
2566 | .sp .3 | |
2567 | struct | |
2568 | { | |
2569 | integer nextindex | |
2570 | integer x, y | |
2571 | } list(\(**) | |
2572 | .sp .3 | |
2573 | integer first, p, arg | |
2574 | ||
2575 | for(p = first , p\*~=LAST && list(p).x<=x , p = list(p).nextindex) | |
2576 | if(list(p).x == x) | |
2577 | return( list(p).y ) | |
2578 | ||
2579 | return(NOTFOUND) | |
2580 | end | |
2581 | .R | |
2582 | .DE | |
2583 | The search is a single | |
2584 | .B for | |
2585 | loop that begins with the head of the list | |
2586 | and examines items until either the list is exhausted | |
2587 | (p==LAST) | |
2588 | or until it is known that the specified value is not on the list | |
2589 | (list(p).x > x). | |
2590 | The two tests in the conjunction must | |
2591 | be performed in the specified order | |
2592 | to avoid using an invalid subscript in the | |
2593 | .B list(p) | |
2594 | reference. | |
2595 | Therefore, the | |
2596 | .B && | |
2597 | operator is used. | |
2598 | The next element in the chain is found by the iteration statement | |
2599 | .B "p=list(p).nextindex". | |
2600 | .NH 2 | |
2601 | Walking a Tree | |
2602 | .PP | |
2603 | As an example of a more complicated problem, let us imagine we have | |
2604 | an expression tree stored in a common area, | |
2605 | and that we want to print out an infix form of the tree. | |
2606 | Each node is either a leaf (containing a numeric value) | |
2607 | or it is a binary operator, pointing to a left and a right descendant. | |
2608 | In a recursive language, | |
2609 | such a tree walk would be implement by the following simple pseudocode: | |
2610 | .DS | |
2611 | .I | |
2612 | if this node is a leaf | |
2613 | print its value | |
2614 | otherwise | |
2615 | print a left parenthesis | |
2616 | print the left node | |
2617 | print the operator | |
2618 | print the right node | |
2619 | print a right parenthesis | |
2620 | .R | |
2621 | .DE | |
2622 | In a nonrecursive language like EFL, it is necessary to maintain an explicit stack | |
2623 | to keep track of the current state of the computation. | |
2624 | The following procedure | |
2625 | calls a procedure | |
2626 | .B outch | |
2627 | to print a single character | |
2628 | and a procedure | |
2629 | .B outval | |
2630 | to print a value. | |
2631 | .DS | |
2632 | .ta .7i 1.4i 2.1i 2.8i | |
2633 | .B | |
2634 | procedure walk(first) # print out an expression tree | |
2635 | .sp .5 | |
2636 | integer first # index of root node | |
2637 | integer currentnode | |
2638 | integer stackdepth | |
2639 | common(nodes) struct | |
2640 | { | |
2641 | character(1) op | |
2642 | integer leftp, rightp | |
2643 | real val | |
2644 | } tree(100) # array of structures | |
2645 | .sp .5 | |
2646 | struct | |
2647 | { | |
2648 | integer nextstate | |
2649 | integer nodep | |
2650 | } stackframe(100) | |
2651 | .sp .5 | |
2652 | define NODE tree(currentnode) | |
2653 | define STACK stackframe(stackdepth) | |
2654 | .sp .5 | |
2655 | # nextstate values | |
2656 | define DOWN 1 | |
2657 | define LEFT 2 | |
2658 | define RIGHT 3 | |
2659 | .DE | |
2660 | .DS | |
2661 | .B | |
2662 | # initialize stack with root node | |
2663 | stackdepth = 1 | |
2664 | STACK.nextstate = DOWN | |
2665 | STACK.nodep = first | |
2666 | .DE | |
2667 | .DS | |
2668 | .B | |
2669 | while( stackdepth > 0 ) | |
2670 | { | |
2671 | currentnode = STACK.nodep | |
2672 | select(STACK.nextstate) | |
2673 | { | |
2674 | case DOWN: | |
2675 | if(NODE.op == " ") # a leaf | |
2676 | { | |
2677 | outval( NODE.val ) | |
2678 | stackdepth \-= 1 | |
2679 | } | |
2680 | else { # a binary operator node | |
2681 | outch( "(" ) | |
2682 | STACK.nextstate = LEFT | |
2683 | stackdepth += 1 | |
2684 | STACK.nextstate = DOWN | |
2685 | STACK.nodep = NODE.leftp | |
2686 | } | |
2687 | .sp .5 | |
2688 | case LEFT: | |
2689 | outch( NODE.op ) | |
2690 | STACK.nextstate = RIGHT | |
2691 | stackdepth += 1 | |
2692 | STACK.nextstate = DOWN | |
2693 | STACK.nodep = NODE.rightp | |
2694 | .sp .5 | |
2695 | case RIGHT: | |
2696 | outch( ")" ) | |
2697 | stackdepth \-= 1 | |
2698 | } | |
2699 | } | |
2700 | end | |
2701 | .DE | |
2702 | .NH 1 | |
2703 | PORTABILITY | |
2704 | .PP | |
2705 | One of the major goals of the EFL language is to make it easy to write portable programs. | |
2706 | The output of the EFL compiler is intended to be acceptable to any Standard Fortran | |
2707 | compiler | |
2708 | (unless the | |
2709 | .B fortran77 | |
2710 | option is specified). | |
2711 | .NH 2 | |
2712 | Primitives | |
2713 | .PP | |
2714 | Certain EFL operations cannot be implemented in portable Fortran, | |
2715 | so a few machine-dependent procedures must be provided in each environment. | |
2716 | .NH 3 | |
2717 | Character String Copying | |
2718 | .PP | |
2719 | The subroutine | |
2720 | .B ef1asc | |
2721 | is called to copy one character string to another. | |
2722 | If the target string is shorter than the source, | |
2723 | the final characters are not copied. | |
2724 | If the target string is longer, its end is padded with blanks. | |
2725 | The calling sequence is | |
2726 | .DS B | |
2727 | subroutine ef1asc(a, la, b, lb) | |
2728 | integer a(\(**), la, b(\(**), lb | |
2729 | .DE | |
2730 | and it must copy the first | |
2731 | .B lb | |
2732 | characters from | |
2733 | .B b | |
2734 | to the first | |
2735 | .B la | |
2736 | characters of | |
2737 | .B a. | |
2738 | .NH 3 | |
2739 | Character String Comparisons | |
2740 | .PP | |
2741 | The function | |
2742 | .B ef1cmc | |
2743 | is invoked to determine the order of two character strings. | |
2744 | The declaration is | |
2745 | .DS B | |
2746 | integer function ef1cmc(a, la, b, lb) | |
2747 | integer a(\(**), la, b(\(**), lb | |
2748 | .DE | |
2749 | The function returns a negative value if the string | |
2750 | .B a | |
2751 | of length | |
2752 | .B la | |
2753 | precedes the string | |
2754 | .B b | |
2755 | of length | |
2756 | .B lb. | |
2757 | It returns zero if the strings are equal, and a positive value otherwise. | |
2758 | If the strings are of differing length, the comparison is carried out | |
2759 | as if the end of the shorter string were padded with blanks. | |
2760 | .NH 1 | |
2761 | ACKNOWLEDGMENTS | |
2762 | .PP | |
2763 | A. D. Hall originated the EFL language and wrote the first compiler for it; | |
2764 | he also gave inestimable aid when I took up the project. | |
2765 | B. W. Kernighan and W. S. Brown made a number of useful suggestions about the language and about this report. | |
2766 | N. L. Schryer has acted as willing, cheerful, and severe first user | |
2767 | and helpful critic of each new version and facility. | |
2768 | J. L. Blue, L. C. Kaufman, and D. D. Warner | |
2769 | made very useful contributions by making serious use of the compiler, | |
2770 | and noting and tolerating its misbehaviors. | |
2771 | .NH 1 | |
2772 | REFERENCE | |
2773 | .IP 1. | |
2774 | B. W. Kernighan, | |
2775 | ``Ratfor \(em A Preprocessor for a Rational Fortran'', | |
2776 | Bell Laboratories Computing Science Technical Report #55 | |
2777 | .bp | |
2778 | .SH | |
2779 | APPENDIX A. Relation Between EFL and Ratfor | |
2780 | .PP | |
2781 | There are a number of differences between Ratfor and EFL, | |
2782 | since EFL is a defined language while Ratfor is | |
2783 | the union of the special control structures and the language accepted by the underlying Fortran compiler. | |
2784 | Ratfor running over Standard Fortran is almost a subset of EFL. | |
2785 | Most of the features described in the Atavisms section are present to ease | |
2786 | the conversion of Ratfor programs to EFL. | |
2787 | .PP | |
2788 | There are a few incompatibilities: | |
2789 | The syntax of the | |
2790 | .B for | |
2791 | statement is slightly different in the two languages: | |
2792 | the three clauses are separated by semicolons in Ratfor, | |
2793 | but by commas in EFL. | |
2794 | (The initial and iteration statements may be compound statements in EFL because of this change). | |
2795 | The input/output syntax is quite different in the two languages, | |
2796 | and there is no FORMAT statement in EFL. | |
2797 | There are no ASSIGN or assigned GOTO statements in EFL. | |
2798 | .PP | |
2799 | The major linguistic additions are | |
2800 | character data, | |
2801 | factored declaration syntax, | |
2802 | block structure, | |
2803 | assignment and sequential test operators, | |
2804 | generic functions, | |
2805 | and | |
2806 | data structures. | |
2807 | EFL permits more general forms for expressions, | |
2808 | and provides a more uniform syntax. | |
2809 | (One need not worry about the Fortran/Ratfor restrictions | |
2810 | on subscript or DO expression forms, for example.) | |
2811 | .SH | |
2812 | APPENDIX B. COMPILER | |
2813 | .SH | |
2814 | B.1. Current Version | |
2815 | .PP | |
2816 | The current version of the EFL compiler is a two-pass translator written in | |
2817 | portable C. | |
2818 | It implements all of the features of the language described above except for | |
2819 | .B "long complex" | |
2820 | numbers. | |
2821 | Versions of this compiler run under the | |
2822 | .SM GCOS | |
2823 | and | |
2824 | .UX | |
2825 | operating systems. | |
2826 | .SH | |
2827 | B.2. Diagnostics | |
2828 | .PP | |
2829 | The EFL compiler diagnoses all syntax errors. | |
2830 | It gives the line and file name (if known) on which the error was detected. | |
2831 | Warnings are given for variables that are used but not explicitly declared. | |
2832 | .SH | |
2833 | B.3. Quality of Fortran Produced | |
2834 | .PP | |
2835 | The Fortran produced by EFL is quite clean and readable. | |
2836 | To the extent possible, the variable names that appear in the EFL program are used in the Fortran code. | |
2837 | The bodies of loops and test constructs are indented. | |
2838 | Statement numbers are consecutive. | |
2839 | Few unneeded GOTO and CONTINUE statements are used. | |
2840 | It is considered a compiler bug if incorrect Fortran is produced | |
2841 | (except for escaped lines). | |
2842 | The following is the Fortran procedure produced by the EFL compiler for | |
2843 | the matrix multiplication example (Section 11.2): | |
2844 | .DS B | |
2845 | .B | |
2846 | \0\0\0\0\0\0subroutine\0matmul(a,\0b,\0c,\0m,\0n,\0p) | |
2847 | \0\0\0\0\0\0integer\0m,\0n,\0p | |
2848 | \0\0\0\0\0\0double\0precision\0a(m,\0n),\0b(n,\0p),\0c(m,\0p) | |
2849 | \0\0\0\0\0\0integer\0i,\0j,\0k | |
2850 | \0\0\0\0\0\0do\0\03\0i\0=\01,\0m | |
2851 | \0\0\0\0\0\0\0\0\0do\0\02\0j\0=\01,\0p | |
2852 | \0\0\0\0\0\0\0\0\0\0\0\0c(i,\0j)\0=\00 | |
2853 | \0\0\0\0\0\0\0\0\0\0\0\0do\0\01\0k\0=\01,\0n | |
2854 | \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0c(i,\0j)\0=\0c(i,\0j)+a(i,\0k)*b(k,\0j) | |
2855 | \0\0\01\0\0\0\0\0\0\0\0\0\0\0continue | |
2856 | \0\0\02\0\0\0\0\0\0\0\0continue | |
2857 | \0\0\03\0\0\0\0\0continue | |
2858 | \0\0\0\0\0\0end | |
2859 | .R | |
2860 | .DE | |
2861 | The following is the procedure for the tree walk (Section 11.4): | |
2862 | .DS B | |
2863 | .B | |
2864 | \0\0\0\0\0\0subroutine\0walk(first) | |
2865 | \0\0\0\0\0\0integer\0first | |
2866 | \0\0\0\0\0\0common\0/nodes/\0tree | |
2867 | \0\0\0\0\0\0integer\0tree(4,\0100) | |
2868 | \0\0\0\0\0\0real\0tree1(4,\0100) | |
2869 | \0\0\0\0\0\0integer\0staame(2,\0100),\0stapth,\0curode | |
2870 | \0\0\0\0\0\0integer\0const1(1) | |
2871 | \0\0\0\0\0\0equivalence\0(tree(1,1),\0tree1(1,1)) | |
2872 | \0\0\0\0\0\0data\0const1(1)/4h\0\0\0\0/ | |
2873 | c\0print\0out\0an\0expression\0tree | |
2874 | c\0index\0of\0root\0node | |
2875 | c\0array\0of\0structures | |
2876 | c\0\0\0nextstate\0values | |
2877 | c\0\0\0initialize\0stack\0with\0root\0node | |
2878 | \0\0\0\0\0\0stapth\0=\01 | |
2879 | \0\0\0\0\0\0staame(1,\0stapth)\0=\01 | |
2880 | \0\0\0\0\0\0staame(2,\0stapth)\0=\0first | |
2881 | \0\0\01\0\0if\0(stapth\0.le.\00)\0goto\0\09 | |
2882 | \0\0\0\0\0\0\0\0\0curode\0=\0staame(2,\0stapth) | |
2883 | \0\0\0\0\0\0\0\0\0goto\0\07 | |
2884 | \0\0\02\0\0\0\0\0\0\0\0if\0(tree(1,\0curode)\0.ne.\0const1(1))\0goto\03 | |
2885 | \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0call\0outval(tree1(4,\0curode)) | |
2886 | c\0a\0leaf | |
2887 | \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0stapth\0=\0stapth-1 | |
2888 | \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0goto\0\04 | |
2889 | \0\0\03\0\0\0\0\0\0\0\0\0\0\0call\0outch(1h() | |
2890 | c\0a\0binary\0operator\0node | |
2891 | \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0staame(1,\0stapth)\0=\02 | |
2892 | \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0stapth\0=\0stapth+1 | |
2893 | \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0staame(1,\0stapth)\0=\01 | |
2894 | \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0staame(2,\0stapth)\0=\0tree(2,\0curode) | |
2895 | \0\0\04\0\0\0\0\0\0\0\0goto\0\08 | |
2896 | \0\0\05\0\0\0\0\0\0\0\0call\0outch(tree(1,\0curode)) | |
2897 | \0\0\0\0\0\0\0\0\0\0\0\0staame(1,\0stapth)\0=\03 | |
2898 | \0\0\0\0\0\0\0\0\0\0\0\0stapth\0=\0stapth+1 | |
2899 | \0\0\0\0\0\0\0\0\0\0\0\0staame(1,\0stapth)\0=\01 | |
2900 | \0\0\0\0\0\0\0\0\0\0\0\0staame(2,\0stapth)\0=\0tree(3,\0curode) | |
2901 | \0\0\0\0\0\0\0\0\0\0\0\0goto\0\08 | |
2902 | \0\0\06\0\0\0\0\0\0\0\0call\0outch(1h)) | |
2903 | \0\0\0\0\0\0\0\0\0\0\0\0stapth\0=\0stapth-1 | |
2904 | \0\0\0\0\0\0\0\0\0\0\0\0goto\0\08 | |
2905 | \0\0\07\0\0\0\0\0\0\0\0if\0(staame(1,\0stapth)\0.eq.\03)\0goto\0\06 | |
2906 | \0\0\0\0\0\0\0\0\0\0\0\0if\0(staame(1,\0stapth)\0.eq.\02)\0goto\0\05 | |
2907 | \0\0\0\0\0\0\0\0\0\0\0\0if\0(staame(1,\0stapth)\0.eq.\01)\0goto\0\02 | |
2908 | \0\0\08\0\0\0\0\0continue | |
2909 | \0\0\0\0\0\0\0\0\0goto\0\01 | |
2910 | \0\0\09\0\0continue | |
2911 | \0\0\0\0\0\0end | |
2912 | .R | |
2913 | .DE | |
2914 | .SH | |
2915 | APPENDIX C. CONSTRAINTS ON THE DESIGN OF THE EFL LANGUAGE | |
2916 | .PP | |
2917 | Although Fortran can be used to simulate any finite computation, | |
2918 | there are realistic limits on the generality of a language that can be | |
2919 | translated into Fortran. | |
2920 | The design of EFL was constrained by the implementation strategy. | |
2921 | Certain of the restrictions are petty (six character external names), | |
2922 | but others are sweeping (lack of pointer variables). | |
2923 | The following paragraphs describe the major limitations imposed by Fortran. | |
2924 | .SH | |
2925 | C.1. External Names | |
2926 | .PP | |
2927 | External names (procedure and COMMON block names) | |
2928 | must be no longer than six characters in Fortran. | |
2929 | Further, an external name is global to the entire program. | |
2930 | Therefore, EFL can support block structure within a procedure, | |
2931 | but it can have only one level of external name if the | |
2932 | EFL procedures are to be compilable separately, | |
2933 | as are Fortran procedures. | |
2934 | .SH | |
2935 | C.2. Procedure Interface | |
2936 | .PP | |
2937 | The Fortran standards, in effect, permit arguments to be passed between | |
2938 | Fortran procedures either by reference or by copy-in/copy-out. | |
2939 | This indeterminacy of specification shows through into EFL. | |
2940 | A program that depends on the method of argument transmission is | |
2941 | illegal in either language. | |
2942 | .PP | |
2943 | There are no procedure-valued variables in Fortran: a procedure name may | |
2944 | only be passed as an argument or be invoked; it cannot be stored. | |
2945 | Fortran (and EFL) would be noticeably simpler if a procedure variable mechanism | |
2946 | were available. | |
2947 | .SH | |
2948 | C.3. Pointers | |
2949 | .PP | |
2950 | The most grievous problem with Fortran is its lack of a pointer-like | |
2951 | data type. | |
2952 | The implementation of the compiler would have been far easier if certain hard | |
2953 | cases could have been handled by pointers. | |
2954 | Further, the language could have been simplified considerably if pointers were | |
2955 | accessible in Fortran. | |
2956 | (There are several ways of simulating pointers by using subscripts, | |
2957 | but they founder on the problems of external variables and initialization.) | |
2958 | .SH | |
2959 | C.4. Recursion | |
2960 | .PP | |
2961 | Fortran procedures are not recursive, | |
2962 | so it was not practical to permit EFL procedures to be recursive. | |
2963 | (Recursive procedures with arguments can be simulated only with great pain.) | |
2964 | .SH | |
2965 | C.5. Storage Allocation | |
2966 | .PP | |
2967 | The definition of Fortran does not specify the lifetime of variables. | |
2968 | It would be possible but cumbersome to implement stack or heap | |
2969 | storage disciplines by using COMMON blocks. |