X3J3/96-067 Date: April 5, 1996 To: X3J3 From: David Epstein Subject: CoCo "Short Version" *** THE COCO LANGUAGE DEFINITION ***************** #1 Here is a list of all the conditional compilation directives. INCLUDE char-literal-constant ?? INTEGER [,PARAMETER] :: name [=expr] [,name [=expr]] ... ?? LOGICAL [,PARAMETER] :: name [=expr] [,name [=expr]] ... ?? name = expr ?? IF (expr) THEN ?? ELSEIF (expr) THEN ?? ELSE ?? ENDIF ?? ERROR *, [output-item-list] #2 The lexical rules are as follows: r1. The "??" shall appear in character positions one and two. r2. Starting in character position three, the free source form rules apply. r3. A CoCo directive can be continued. For example, ! the "!" is column 1 ?? IF (sys == sysA .OR. & ?? sys == sysE .OR. & ?? sys == sysF) THEN r4. There are three sorts of CoCo comment lines. (1) A blank line and "!" as the first token (as in Fortran). For example, ?? ?? ! above is the blank line example and this is the "!" example (2) ?* in character positions one and two. (3) ?> in character positions one and two. The later two are further explained in #11. r5. The trailing "!" comment is available in CoCo directives #3 Here are the directive order rules. r1. The ??INTEGER and ??LOGICAL directives can appear anywhere. r2. A CoCo ??IF construct starts with a ??IF and ends with a ??ENDIF. Optional ??ELSEIF directives can preceed an optional ??ELSE in the body of a CoCo ??IF construct (as with the Fortran IF construct.) r3. An assignment directive shall be preceded by a ??INTEGER or ??LOGICAL, so that the name on the left of the '=' is available. The same holds for any name appearing in a ??IF, ??ELSEIF or ??PRINT. r4. A name shall be given a value before it is referenced. r5. The scope of a name is the input source. #4 INCLUDE char-literal-constant An INCLUDE in a false CoCo branch is not expanded. A CoCo ??IF construct cannot be split across INCLUDEd source text. #5 ?? INTEGER [,PARAMETER] :: name [=init-expr] [,name [=init-expr]] ... ?? LOGICAL [,PARAMETER] :: name [=init-expr] [,name [=init-expr]] ... NOTE: The only names allowed in expr are previously seen CoCo PARAMETERs. NOTE: Every name shall be unique, so the following shows two errors: ?? INTEGER :: name1, name1 ! the second name1 is erroneous ?? INTEGER :: name1 ! given the above directive, name1 is erroneous NOTE: If a name is given a value on the command line (see #11 below), the command line value overrides the value supplied in the ??INTEGER or ??LOGICAL directive. NOTE: If a name with the PARAMETER attribute is given a value on the command line (see #11 below), the command line value shall match the PARAMETER value. NOTE: A name need not be given a value in the ??INTEGER or ??LOGICAL directive in order to be given a value on the command line. #6 ?? name = expr NOTE: The value assigned in the CoCo assignment directive is not overridden by a value supplied on the command line. NOTE: It is possible that the value supplied for a name in the CoCo assignment directive is the initial (the first) value supplied for that name. #7 ?? IF (expr) THEN ?? ELSEIF (expr) THEN ?? ELSE ?? ENDIF NOTE: CoCo ??IF constructs can be nested. #8 ?? ERROR *, [output-item-list] where output-item is expr or char-literal-constant (not a substring) Execution of a CoCo ??ERROR informs the processor that an error has occurred during CoCo processing. #9 Here is a list of what is allowed in a CoCo expr: o ( expr ) o integer constants o .true., .false. o name o +, -, *, / (not **) o ==, /=, <, >, <=, >= (not .eq., .ne., .gt., etc.) o .not., .and., .or., .eqv., .neqv. #10 Except for a reference on the left of the "=" in a CoCo assignment directive, a name shall be given a value before it is referenced. This can be done three ways, (1) on the ??INTEGER or ??LOGICAL directive (2) on the ??assignment directive (3) on the command line #11 There are three CoCo options. The exact syntax of these options is processor defined. (1) CoCoON or CoCoOFF. (2) CoCoSET. This is for supplying initial values and override values. The supplied value shall be a literal constant. (3) CoCoFILE. There are four values for this option-- (a) SHORT, (b) EXPAND, (c) SHIFT, and (d) REPLACE. (a) SHORT removes the CoCo directives, except the INCLUDE lines, and removes the lines in any false blocks. INCLUDE lines are not expanded. (b) EXPAND is the same as SHORT except the INCLUDE lines are expanded. (c) SHIFT modifies lines in any false block by shifting right two and placing "?>" in character positions one and two. INCLUDE lines are not expanded. (d) REPLACE modifies lines in any false block by replacing the characters in character positions one and two with "?*". INCLUDE lines are not expanded. NOTE that the SHIFT and REPLACE files have the same number of lines as the input source. Also, these files can be used as input source since the "?>" and "?*" CoCo comments can be recoginized as such.