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