In fixed-form Fortran, which token sequence is produced from the statement DO…

1999

In fixed-form Fortran, which token sequence is produced from the statement DO 10 I = 1.25?

Answer: A. DO10I, =, 1.25ConceptIn fixed-form Fortran, blanks outside character strings are insignificant. Lexical analysis first applies this source-form rule, then identifies…

  1. A.

    DO10I, =, 1.25

  2. B.

    DO, 10I, =, 1.25

  3. C.

    DO, 10, I, =, 1.25

  4. D.

    DO, 10, I, =, 1, ., 25

Attempted by 120 students.

Show answer & explanation

Correct answer: A

Concept

In fixed-form Fortran, blanks outside character strings are insignificant. Lexical analysis first applies this source-form rule, then identifies maximal lexemes such as identifiers, operators, and numeric literals.

Application

  1. Remove the insignificant blanks from DO 10 I = 1.25 to obtain DO10I=1.25.

  2. DO10I is one identifier, = is the assignment symbol, and 1.25 is one real literal.

  3. The resulting token sequence is DO10I, =, 1.25; it contains three tokens.

Cross-check and contrast

If the period were a comma, DO 10 I = 1,25 would be a DO-loop form and would tokenize differently. The period in the given line makes 1.25 a real literal and leaves DO10I as an identifier.

  • The sequence DO, 10I, =, 1.25 inserts a boundary at the first visible blank, although fixed-form blanks do not create such a boundary.

  • The sequence DO, 10, I, =, 1.25 uses every visible blank as a mandatory boundary; this is the five-token interpretation.

  • The sequence DO, 10, I, =, 1, ., 25 additionally splits the real literal at its decimal point.

Result

Therefore, the produced token sequence is DO10I, =, 1.25, containing three tokens.

Explore the full course: Iocl Engineers Officers Grade A Paper 2

Loading lesson…