Lines and source formats

A line is a horizontal arrangement of characters. A column is a vertical arrangement of characters, where each character, or each byte of a multibyte character, in a given column shares the same horizontal line position.

IBM Extension

Because XL Fortran measures lines in bytes, these definitions apply only to lines containing single-byte characters. Each byte of a multibyte character occupies one column.

End of IBM Extension

The kinds of lines are:

Initial line Is the first line of a statement.
Continuation line Continues a statement beyond its initial line.
Comment line Does not affect the executable program and can be used for documentation. The comment text continues to the end of a line. Although comment lines can follow one another, a comment line cannot be continued. A line of all white space or a zero-length line is a comment line without any text. Comment text can contain any characters allowed in a character context.

If an initial line or continuation line is not continued, or if it is continued but not in a character context, an inline comment can be placed on the same line, to the right of any statement label, statement text, and continuation character that may be present. An exclamation mark (!) begins an inline comment.

Conditional compilation line Indicates that the line should only be compiled if recognition of conditional compilation lines is enabled. A conditional compilation sentinel should appear on a conditional compilation line. For more information, see Conditional compilation.
Debug Line Indicates that the line is for debugging code (for fixed source form only). In XL Fortran the letter D or X must be specified in column 1. For more information, see Debug lines.
Directive line Provides instructions or information to the compiler in XL Fortran. For more information, see Comment form directives.
IBM Extension

In XL Fortran, source lines can be in fixed source form or free source form format. Use the SOURCEFORM directive to mix source formats within the same program unit. Fixed source form is the default when using the f77, fort77, xlf, xlf_r invocation commands.

Fortran 90 free source form is the default when using the xlf90, xlf90_r, xlf95, xlf95_r, xlf2003, or xlf2003_r invocation commands.

See Compiling XL Fortran Programs in the XL Fortran Compiler Reference for details on invocation commands.

End of IBM Extension

Fixed source form

IBM Extension

A fixed source form line is a sequence of 1 to 132 characters. The default line size is 72 characters. This is also the Fortran standard line size. You can change the default using the -qfixed=right_margin compiler option. In XL Fortran there is no limit to the number of continuation lines for a statement , but the statement cannot be longer than 34 000 characters. Fortran 2003 limits the number of continuation lines to 255, while Fortran 95 limits the number of continuation lines to 19.

In fixed source form, columns beyond the right margin are not part of the line and you can use these columns for identification, sequencing, or any other purpose.

End of IBM Extension

Except within a character context, white space is insignificant. You can embed white space between and within lexical tokens, without affecting the way the compiler treats them.

IBM Extension

Tab formatting means that there is a tab character in columns 1 through 6 of an initial line in XL Fortran, which directs the compiler to interpret the next character as being in column 7.

End of IBM Extension

Requirements for lines and for items on those lines are:

A semicolon separates statements on a single source line, except when appearing in a character context, in a comment, or in columns 1 through 6. Two or more semicolon separators that are on the same line and are themselves separated by only white space or other semicolons are considered to be a single separator. A separator that is the last character on a line or before an inline comment is ignored. Statements following a semicolon on the same line cannot be labeled. Additional statements cannot follow a program unit END statement on the same line.

Debug lines

IBM Extension

A debug line, allowed only for fixed source form, contains source code used for debugging and is specified in XL Fortran by the letter D, or the letter X in column 1. The handling of debug lines depends on the -qdlines or the -qxlines compiler options:

If you continue a debugging statement on more than one line, every continuation line must have a continuation character as well as a D or an X in column 1. If the initial line is not a debugging line, you can designate any continuation lines as debug lines provided that the statement is syntactically correct, whether or not you specify the -qdlines or -qxlines compiler option.

End of IBM Extension

Example of fixed source form

C Column Numbers:
C        1         2         3         4         5         6         7
C23456789012345678901234567890123456789012345678901234567890123456789012

!IBM* SOURCEFORM (FIXED)
      CHARACTER CHARSTR ; LOGICAL X          ! 2 statements on 1 line
      DO 10 I=1,10
        PRINT *,'this is the index',I  ! with an inline comment
10    CONTINUE
C
       CHARSTR="THIS IS A CONTINUED
     X CHARACTER STRING"
       ! There will be 38 blanks in the string between "CONTINUED"
       ! and "CHARACTER". You cannot have an inline comment on
       ! the initial line because it would be interpreted as part
       ! of CHARSTR (character context).
  100 PRINT *, IERROR
! The following debug lines are compiled as source lines if
! you use -qdlines
D     IF (I.EQ.IDEBUG.AND.
D    +    J.EQ.IDEBUG)     WRITE(6,*) IERROR
D     IF (I.EQ.
D    +  IDEBUG )
D    +  WRITE(6,*) INFO
       END

Free source form

A free source form line can specify up to 132 characters on each line. In XL Fortran, there is no limit to the number of continuation lines for a statement , but the statement cannot be longer than 34 000 characters. Fortran 2003 limits the number of continuation lines to 255, while Fortran 95 limits the number of continuation lines to 39.

Items can begin in any column of a line, subject to the following requirements for lines and items on those lines:

A semicolon separates statements on a single source line, except when the semicolon appears in a character context or in a comment. Two or more separators that are on the same line and are themselves separated by only white space or other semicolons are considered to be a single separator. A separator that is the last character on a line or before an inline comment is ignored. Additional statements cannot follow a program unit END statement on the same line.

White space

White space must not appear within lexical tokens, except in a character context or in a format specification. You can freely insert white space between tokens to improve readability, and white space must separate names, constants, and labels from adjacent keywords, names, constants, and labels.

Certain adjacent keywords can require white space. The following table lists keywords where white space is optional..

Table 5. Keywords where white space is optional
BLOCK DATA END FILE END STRUCTURE
DOUBLE COMPLEX END FORALL END SUBROUTINE
DOUBLE PRECISION END FUNCTION END TYPE
ELSE IF END IF END UNION
ELSE WHERE END INTERFACE END WHERE
END ASSOCIATE END MAP GO TO
END BLOCK DATA END MODULE IN OUT
END DO END PROGRAM SELECT CASE
END ENUM END SELECT SELECT TYPE

Example of free source form

!IBM* SOURCEFORM (FREE(F90))
!
! Column Numbers:
!        1         2         3         4         5         6         7
!23456789012345678901234567890123456789012345678901234567890123456789012
 DO I=1,20
   PRINT *,'this statement&
   & is continued' ; IF (I.LT.5) PRINT *, I

 ENDDO
 EN&
         &D              ! A lexical token can be continued
IBM Extension

IBM free source form

An IBM® free source form line or statement is a sequence of up to 34000 characters. Items can begin in any column of a line, subject to the following requirements:

If statement text on an initial line or continuation line is to continue, a minus sign indicates continuation of the statement text on the next line. In a character context, if the rightmost character of the statement text to continue is a minus sign, a second minus sign must be entered as a continuation character.

Except within a character context, white space is insignificant. You can embed white space between and within lexical tokens, without affecting how the compiler treats those tokens.

Example of IBM free source form

!IBM* SOURCEFORM (FREE(IBM))
"
" Column Numbers:
"        1         2         3         4         5         6         7
"23456789012345678901234567890123456789012345678901234567890123456789012
 DO I=1,10
  PRINT *,'this is -
             the index',I   ! There will be 14 blanks in the string
                            ! between "is" and "the"
 END DO
 END
End of IBM Extension
IBM Extension

Conditional compilation

You can use sentinels to mark specific lines of an XL Fortran program for conditional compilation. This allows you to port code that contains statements that are only valid or applicable in an SMP environment to a non-SMP environment.

Syntax for conditional compilation

Read syntax diagramSkip visual syntax diagram>>-cond_comp_sentinel--fortran_source_line---------------------><
 

cond_comp_sentinel
is a conditional compilation sentinel defined by the current source form and is either:
fortran_source_line
is an XL Fortran source line

Conditional compilation rules

General rules

A valid XL Fortran source line must follow the conditional compilation sentinel.

A conditional compilation line can contain the EJECT, INCLUDE or noncomment directives.

A conditional compilation sentinel must not contain embedded white space.

A conditional compilation sentinel must not follow a source statement or directive on the same line.

If you are continuing a conditional compilation line, the conditional compilation sentinel must appear on at least one of the continuation lines or on the initial line.

You must specify the -qcclines compiler option for conditional compilation lines to be recognized. To disable recognition of conditional compilation lines, specify the -qnocclines compiler option.

Trigger directives take precedence over conditional compilation sentinels. For example, if you specify the -qdirective='$' option, then lines that start with the trigger, such as !$, will be treated as comment directives, rather than conditional compilation lines.

Fixed source form rules

Conditional compilation sentinels must start in column 1.

All rules for fixed source form line length, case sensitivity, white space, continuation, tab formatting, and columns apply.

Free source form rules

Conditional compilation sentinels can start in any column.

All rules for free source form line length, case sensitivity, white space, and continuation apply. When you enable recognition of conditional compilation lines, the conditional compilation sentinel two white spaces replace the conditional compilation sentinel.

End of IBM Extension