• Aucun résultat trouvé

Lexical Tokens

Dans le document The Fortran 2003 Handbook (Page 55-58)

A statement is constructed from low-level syntax. The low-level syntax describes the basic language elements, called lexical tokens, in a Fortran statement. A lexical token is the smallest meaningful unit of a Fortran statement and may consist of one or more characters. Tokens are names, keywords, literal constants (except for complex literal constants), labels, operator symbols, comma, =, =>, :, ::, ;, %, and delimiters. A complex literal (4.3.3) consists of several tokens. Examples of operator symbols are + and //.

Delimiters in Fortran are pairs of symbols that enclose parts of a Fortran statement.

The delimiters are slashes (in pairs), left and right parentheses, left and right brackets, and the symbol pairs (/ and /).

/ ... / ( ... ) (/ ... /) [ ... ]

In the statements:

DATA X, Y/ 1.0, -10.2/

CALL PRINT_LIST (LIST, SIZE) VECTOR = (/ 10, 20, 30, 40 /)

the slashes distinguish the value list from the object list in a DATA statement, the pa-rentheses are delimiters marking the beginning and end of the argument list in the CALL statement, and the pairs (/ and /) and [ and ] mark the beginning and end of the elements of an array constructor.

3.2.1 Statement Keywords

Statement keywords appear in uppercase letters in the syntax rules. Some statement keywords also identify the statement, such as in the DO statement:

DO I = 1, 10

where DO is a statement keyword identifying the DO statement. Other keywords de-limit parts of a statement such as ONLY in a USE statement, or WHILE in one of the forms of a DO construct, as, for example:

DO WHILE( .NOT. FOUND )

Others specify options in the statement such as IN, OUT, or INOUT in the INTENT statement.

There are two statements in Fortran that have no statement keyword. They are the assignment statement (7.5.1) and the statement function (12.4.4).

48 Chapter 3 Some sequences of capital letters in the formal syntax rules are not statement key-words. For example, EQ in the lexical token

.

EQ

.

and EN as an edit descriptor are not statement keywords.

A dummy argument keyword, a different sort of keyword, is discussed in 12.1.2.

3.2.2 Names

Variables, named constants, program units, common blocks, procedures, arguments, constructs, derived types (types for structures), namelist groups, structure components, dummy arguments, and function results are among the elements in a program that have a name.

Rules and restrictions:

1. A name must begin with a letter and consist of letters, digits, and underscores.

Note that an underscore must not be the first character of a name.

2. Fortran permits up to 63 characters in a name.

Examples of names:

A

CAR_STOCK_NUMBER A__BUTTERFLY Z_28

TEMP_

3.2.3 Constants

A constant is a syntactic notation for a value. The value may be of any intrinsic type, that is, a numeric (integer, real, or complex) value, a character value, or a logical value.

A value that does not have a name is a literal constant. Examples of literal con-stants are:

1.23 400

( 0.0, 1.0 )

"ABC"

B’0110110’

.TRUE.

No literal constant can be array-valued or of derived type. The forms of literal con-stants are given in more detail in 4.2.6.

A value that has a name is called a named constant and may be of any type, in-cluding a derived type. A named constant may also be array-valued. Examples of named constants are:

X_AXIS MY_SPOUSE

where these names have been specified in a declaration statement as follows:

Language Elements and Source Form 49 REAL, DIMENSION(2), PARAMETER :: X_AXIS = (/0.0, 1.0/)

TYPE(PERSON), PARAMETER :: MY_SPOUSE = PERSON( 39, ’PAT’ )

Note, however, that the entity on the right of the equal sign is not itself a constant but an initialization expression (7.4.1). The forms for defining named constants are de-scribed in more detail in 5.7.1.

3.2.4 Operators

Operators are used with operands in expressions to produce other values. Examples of language-supplied operators are:

The complete set of the intrinsic operators is given in 7.1.1.1.

Users may define operators (12.5.4.2) in addition to the intrinsic operators. User-defined operators begin with a period (

.

), followed by a sequence of up to 63 letters, and end with a period (

.

), except that the letter sequence must not be the same as any intrinsic operator or either logical constant. Note that, unlike names, underscores and digits are not allowed.

3.2.5 Statement Labels

A label may be used to identify a statement. A label consists of one to five decimal dig-its, one of which must be nonzero. If a Fortran statement has a label, it is uniquely identified and the label can be used in DO constructs, CALL statements, branching statements, and input/output statements. In most cases, two statements in the same program unit must not have the same label (there are exceptions because a program unit may contain more than one scoping unit, for example, several internal proce-dures). Leading zeros in a label are not significant so that the labels 020 and 20 are the same label. This means that there are 99999 different labels and the processor must ac-cept any of them, but may limit the total number of labels allowed in a program unit.

Any statement may have a label, but a label is used only:

1. to designate to target of a branch 2. to specify a FORMAT statement

3. to indicate the termination of some DO loops

* representing multiplication of numeric values // representing concatenation of character values

== representing comparison for equality (same as

.

EQ

.

)

.

OR

.

representing logical disjunction

.

NOT

.

representing logical negation

50 Chapter 3 The cases in which duplicate labels can be used in the same program unit are ex-plained in 16 as part of the general treatment of the scope of entities. Examples of state-ments with labels are:

100 CONTINUE 21 X = X + 1.2

101 FORMAT (1X, 2F10.2)

The Fortran syntax does not permit a statement with no content, sometimes re-ferred to as a blank statement in other programming languages. A label must have a statement so each of the following lines is nonstandard Fortran:

10

X=0;101;

Dans le document The Fortran 2003 Handbook (Page 55-58)