1 //===-- lib/Parser/Fortran-parsers.cpp ------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // Top-level grammar specification for Fortran.  These parsers drive
10 // the tokenization parsers in cooked-tokens.h to consume characters,
11 // recognize the productions of Fortran, and to construct a parse tree.
12 // See ParserCombinators.md for documentation on the parser combinator
13 // library used here to implement an LL recursive descent recognizer.
14 
15 // The productions that follow are derived from the draft Fortran 2018
16 // standard, with some necessary modifications to remove left recursion
17 // and some generalization in order to defer cases where parses depend
18 // on the definitions of symbols.  The "Rxxx" numbers that appear in
19 // comments refer to these numbered requirements in the Fortran standard.
20 
21 // The whole Fortran grammar originally constituted one header file,
22 // but that turned out to require more memory to compile with current
23 // C++ compilers than some people were willing to accept, so now the
24 // various per-type parsers are partitioned into several C++ source
25 // files.  This file contains parsers for constants, types, declarations,
26 // and misfits (mostly clauses 7, 8, & 9 of Fortran 2018).  The others:
27 //  executable-parsers.cpp  Executable statements
28 //  expr-parsers.cpp        Expressions
29 //  io-parsers.cpp          I/O statements and FORMAT
30 //  openmp-parsers.cpp      OpenMP directives
31 //  program-parsers.cpp     Program units
32 
33 #include "basic-parsers.h"
34 #include "expr-parsers.h"
35 #include "misc-parsers.h"
36 #include "stmt-parser.h"
37 #include "token-parsers.h"
38 #include "type-parser-implementation.h"
39 #include "flang/Parser/parse-tree.h"
40 #include "flang/Parser/user-state.h"
41 
42 namespace Fortran::parser {
43 
44 // R601 alphanumeric-character -> letter | digit | underscore
45 // R603 name -> letter [alphanumeric-character]...
46 constexpr auto nonDigitIdChar{letter || otherIdChar};
47 constexpr auto rawName{nonDigitIdChar >> many(nonDigitIdChar || digit)};
48 TYPE_PARSER(space >> sourced(rawName >> construct<Name>()))
49 
50 // R608 intrinsic-operator ->
51 //        power-op | mult-op | add-op | concat-op | rel-op |
52 //        not-op | and-op | or-op | equiv-op
53 // R610 extended-intrinsic-op -> intrinsic-operator
54 // These parsers must be ordered carefully to avoid misrecognition.
55 constexpr auto namedIntrinsicOperator{
56     ".LT." >> pure(DefinedOperator::IntrinsicOperator::LT) ||
57     ".LE." >> pure(DefinedOperator::IntrinsicOperator::LE) ||
58     ".EQ." >> pure(DefinedOperator::IntrinsicOperator::EQ) ||
59     ".NE." >> pure(DefinedOperator::IntrinsicOperator::NE) ||
60     ".GE." >> pure(DefinedOperator::IntrinsicOperator::GE) ||
61     ".GT." >> pure(DefinedOperator::IntrinsicOperator::GT) ||
62     ".NOT." >> pure(DefinedOperator::IntrinsicOperator::NOT) ||
63     ".AND." >> pure(DefinedOperator::IntrinsicOperator::AND) ||
64     ".OR." >> pure(DefinedOperator::IntrinsicOperator::OR) ||
65     ".EQV." >> pure(DefinedOperator::IntrinsicOperator::EQV) ||
66     ".NEQV." >> pure(DefinedOperator::IntrinsicOperator::NEQV) ||
67     extension<LanguageFeature::XOROperator>(
68         ".XOR." >> pure(DefinedOperator::IntrinsicOperator::NEQV)) ||
69     extension<LanguageFeature::LogicalAbbreviations>(
70         ".N." >> pure(DefinedOperator::IntrinsicOperator::NOT) ||
71         ".A." >> pure(DefinedOperator::IntrinsicOperator::AND) ||
72         ".O." >> pure(DefinedOperator::IntrinsicOperator::OR) ||
73         extension<LanguageFeature::XOROperator>(
74             ".X." >> pure(DefinedOperator::IntrinsicOperator::NEQV)))};
75 
76 constexpr auto intrinsicOperator{
77     "**" >> pure(DefinedOperator::IntrinsicOperator::Power) ||
78     "*" >> pure(DefinedOperator::IntrinsicOperator::Multiply) ||
79     "//" >> pure(DefinedOperator::IntrinsicOperator::Concat) ||
80     "/=" >> pure(DefinedOperator::IntrinsicOperator::NE) ||
81     "/" >> pure(DefinedOperator::IntrinsicOperator::Divide) ||
82     "+" >> pure(DefinedOperator::IntrinsicOperator::Add) ||
83     "-" >> pure(DefinedOperator::IntrinsicOperator::Subtract) ||
84     "<=" >> pure(DefinedOperator::IntrinsicOperator::LE) ||
85     extension<LanguageFeature::AlternativeNE>(
86         "<>" >> pure(DefinedOperator::IntrinsicOperator::NE)) ||
87     "<" >> pure(DefinedOperator::IntrinsicOperator::LT) ||
88     "==" >> pure(DefinedOperator::IntrinsicOperator::EQ) ||
89     ">=" >> pure(DefinedOperator::IntrinsicOperator::GE) ||
90     ">" >> pure(DefinedOperator::IntrinsicOperator::GT) ||
91     namedIntrinsicOperator};
92 
93 // R609 defined-operator ->
94 //        defined-unary-op | defined-binary-op | extended-intrinsic-op
95 TYPE_PARSER(construct<DefinedOperator>(intrinsicOperator) ||
96     construct<DefinedOperator>(definedOpName))
97 
98 // R505 implicit-part -> [implicit-part-stmt]... implicit-stmt
99 // N.B. PARAMETER, FORMAT, & ENTRY statements that appear before any
100 // other kind of declaration-construct will be parsed into the
101 // implicit-part.
102 TYPE_CONTEXT_PARSER("implicit part"_en_US,
103     construct<ImplicitPart>(many(Parser<ImplicitPartStmt>{})))
104 
105 // R506 implicit-part-stmt ->
106 //         implicit-stmt | parameter-stmt | format-stmt | entry-stmt
107 TYPE_PARSER(first(
108     construct<ImplicitPartStmt>(statement(indirect(Parser<ImplicitStmt>{}))),
109     construct<ImplicitPartStmt>(statement(indirect(parameterStmt))),
110     construct<ImplicitPartStmt>(statement(indirect(oldParameterStmt))),
111     construct<ImplicitPartStmt>(statement(indirect(formatStmt))),
112     construct<ImplicitPartStmt>(statement(indirect(entryStmt))),
113     construct<ImplicitPartStmt>(indirect(compilerDirective))))
114 
115 // R512 internal-subprogram -> function-subprogram | subroutine-subprogram
116 // Internal subprograms are not program units, so their END statements
117 // can be followed by ';' and another statement on the same line.
118 TYPE_CONTEXT_PARSER("internal subprogram"_en_US,
119     (construct<InternalSubprogram>(indirect(functionSubprogram)) ||
120         construct<InternalSubprogram>(indirect(subroutineSubprogram))) /
121         forceEndOfStmt)
122 
123 // R511 internal-subprogram-part -> contains-stmt [internal-subprogram]...
124 TYPE_CONTEXT_PARSER("internal subprogram part"_en_US,
125     construct<InternalSubprogramPart>(statement(containsStmt),
126         many(StartNewSubprogram{} >> Parser<InternalSubprogram>{})))
127 
128 // R605 literal-constant ->
129 //        int-literal-constant | real-literal-constant |
130 //        complex-literal-constant | logical-literal-constant |
131 //        char-literal-constant | boz-literal-constant
132 TYPE_PARSER(
133     first(construct<LiteralConstant>(Parser<HollerithLiteralConstant>{}),
134         construct<LiteralConstant>(realLiteralConstant),
135         construct<LiteralConstant>(intLiteralConstant),
136         construct<LiteralConstant>(Parser<ComplexLiteralConstant>{}),
137         construct<LiteralConstant>(Parser<BOZLiteralConstant>{}),
138         construct<LiteralConstant>(charLiteralConstant),
139         construct<LiteralConstant>(Parser<LogicalLiteralConstant>{})))
140 
141 // R606 named-constant -> name
142 TYPE_PARSER(construct<NamedConstant>(name))
143 
144 // R701 type-param-value -> scalar-int-expr | * | :
145 TYPE_PARSER(construct<TypeParamValue>(scalarIntExpr) ||
146     construct<TypeParamValue>(star) ||
147     construct<TypeParamValue>(construct<TypeParamValue::Deferred>(":"_tok)))
148 
149 // R702 type-spec -> intrinsic-type-spec | derived-type-spec
150 // N.B. This type-spec production is one of two instances in the Fortran
151 // grammar where intrinsic types and bare derived type names can clash;
152 // the other is below in R703 declaration-type-spec.  Look-ahead is required
153 // to disambiguate the cases where a derived type name begins with the name
154 // of an intrinsic type, e.g., REALITY.
155 TYPE_CONTEXT_PARSER("type spec"_en_US,
156     construct<TypeSpec>(intrinsicTypeSpec / lookAhead("::"_tok || ")"_tok)) ||
157         construct<TypeSpec>(derivedTypeSpec))
158 
159 // R703 declaration-type-spec ->
160 //        intrinsic-type-spec | TYPE ( intrinsic-type-spec ) |
161 //        TYPE ( derived-type-spec ) | CLASS ( derived-type-spec ) |
162 //        CLASS ( * ) | TYPE ( * )
163 // N.B. It is critical to distribute "parenthesized()" over the alternatives
164 // for TYPE (...), rather than putting the alternatives within it, which
165 // would fail on "TYPE(real_derived)" with a misrecognition of "real" as an
166 // intrinsic-type-spec.
167 TYPE_CONTEXT_PARSER("declaration type spec"_en_US,
168     construct<DeclarationTypeSpec>(intrinsicTypeSpec) ||
169         "TYPE" >>
170             (parenthesized(construct<DeclarationTypeSpec>(intrinsicTypeSpec)) ||
171                 parenthesized(construct<DeclarationTypeSpec>(
172                     construct<DeclarationTypeSpec::Type>(derivedTypeSpec))) ||
173                 construct<DeclarationTypeSpec>(
174                     "( * )" >> construct<DeclarationTypeSpec::TypeStar>())) ||
175         "CLASS" >> parenthesized(construct<DeclarationTypeSpec>(
176                                      construct<DeclarationTypeSpec::Class>(
177                                          derivedTypeSpec)) ||
178                        construct<DeclarationTypeSpec>("*" >>
179                            construct<DeclarationTypeSpec::ClassStar>())) ||
180         extension<LanguageFeature::DECStructures>(
181             construct<DeclarationTypeSpec>(
182                 // As is also done for the STRUCTURE statement, the name of
183                 // the structure includes the surrounding slashes to avoid
184                 // name clashes.
185                 construct<DeclarationTypeSpec::Record>(
186                     "RECORD" >> sourced("/" >> name / "/")))))
187 
188 // R704 intrinsic-type-spec ->
189 //        integer-type-spec | REAL [kind-selector] | DOUBLE PRECISION |
190 //        COMPLEX [kind-selector] | CHARACTER [char-selector] |
191 //        LOGICAL [kind-selector]
192 // Extensions: DOUBLE COMPLEX, BYTE
193 TYPE_CONTEXT_PARSER("intrinsic type spec"_en_US,
194     first(construct<IntrinsicTypeSpec>(integerTypeSpec),
195         construct<IntrinsicTypeSpec>(
196             construct<IntrinsicTypeSpec::Real>("REAL" >> maybe(kindSelector))),
197         construct<IntrinsicTypeSpec>("DOUBLE PRECISION" >>
198             construct<IntrinsicTypeSpec::DoublePrecision>()),
199         construct<IntrinsicTypeSpec>(construct<IntrinsicTypeSpec::Complex>(
200             "COMPLEX" >> maybe(kindSelector))),
201         construct<IntrinsicTypeSpec>(construct<IntrinsicTypeSpec::Character>(
202             "CHARACTER" >> maybe(Parser<CharSelector>{}))),
203         construct<IntrinsicTypeSpec>(construct<IntrinsicTypeSpec::Logical>(
204             "LOGICAL" >> maybe(kindSelector))),
205         extension<LanguageFeature::DoubleComplex>(construct<IntrinsicTypeSpec>(
206             "DOUBLE COMPLEX" >> construct<IntrinsicTypeSpec::DoubleComplex>())),
207         extension<LanguageFeature::Byte>(
208             construct<IntrinsicTypeSpec>(construct<IntegerTypeSpec>(
209                 "BYTE" >> construct<std::optional<KindSelector>>(pure(1)))))))
210 
211 // R705 integer-type-spec -> INTEGER [kind-selector]
212 TYPE_PARSER(construct<IntegerTypeSpec>("INTEGER" >> maybe(kindSelector)))
213 
214 // R706 kind-selector -> ( [KIND =] scalar-int-constant-expr )
215 // Legacy extension: kind-selector -> * digit-string
216 TYPE_PARSER(construct<KindSelector>(
217                 parenthesized(maybe("KIND ="_tok) >> scalarIntConstantExpr)) ||
218     extension<LanguageFeature::StarKind>(construct<KindSelector>(
219         construct<KindSelector::StarSize>("*" >> digitString64 / spaceCheck))))
220 
221 // R707 signed-int-literal-constant -> [sign] int-literal-constant
222 TYPE_PARSER(sourced(construct<SignedIntLiteralConstant>(
223     SignedIntLiteralConstantWithoutKind{}, maybe(underscore >> kindParam))))
224 
225 // R708 int-literal-constant -> digit-string [_ kind-param]
226 // The negated look-ahead for a trailing underscore prevents misrecognition
227 // when the digit string is a numeric kind parameter of a character literal.
228 TYPE_PARSER(construct<IntLiteralConstant>(
229     space >> digitString, maybe(underscore >> kindParam) / !underscore))
230 
231 // R709 kind-param -> digit-string | scalar-int-constant-name
232 TYPE_PARSER(construct<KindParam>(digitString64) ||
233     construct<KindParam>(scalar(integer(constant(name)))))
234 
235 // R712 sign -> + | -
236 // N.B. A sign constitutes a whole token, so a space is allowed in free form
237 // after the sign and before a real-literal-constant or
238 // complex-literal-constant.  A sign is not a unary operator in these contexts.
239 constexpr auto sign{
240     "+"_tok >> pure(Sign::Positive) || "-"_tok >> pure(Sign::Negative)};
241 
242 // R713 signed-real-literal-constant -> [sign] real-literal-constant
243 constexpr auto signedRealLiteralConstant{
244     construct<SignedRealLiteralConstant>(maybe(sign), realLiteralConstant)};
245 
246 // R714 real-literal-constant ->
247 //        significand [exponent-letter exponent] [_ kind-param] |
248 //        digit-string exponent-letter exponent [_ kind-param]
249 // R715 significand -> digit-string . [digit-string] | . digit-string
250 // R716 exponent-letter -> E | D
251 // Extension: Q
252 // R717 exponent -> signed-digit-string
253 constexpr auto exponentPart{
254     ("ed"_ch || extension<LanguageFeature::QuadPrecision>("q"_ch)) >>
255     SignedDigitString{}};
256 
257 TYPE_CONTEXT_PARSER("REAL literal constant"_en_US,
258     space >>
259         construct<RealLiteralConstant>(
260             sourced((digitString >> "."_ch >>
261                             !(some(letter) >>
262                                 "."_ch /* don't misinterpret 1.AND. */) >>
263                             maybe(digitString) >> maybe(exponentPart) >> ok ||
264                         "."_ch >> digitString >> maybe(exponentPart) >> ok ||
265                         digitString >> exponentPart >> ok) >>
266                 construct<RealLiteralConstant::Real>()),
267             maybe(underscore >> kindParam)))
268 
269 // R718 complex-literal-constant -> ( real-part , imag-part )
270 TYPE_CONTEXT_PARSER("COMPLEX literal constant"_en_US,
271     parenthesized(construct<ComplexLiteralConstant>(
272         Parser<ComplexPart>{} / ",", Parser<ComplexPart>{})))
273 
274 // PGI/Intel extension: signed complex literal constant
275 TYPE_PARSER(construct<SignedComplexLiteralConstant>(
276     sign, Parser<ComplexLiteralConstant>{}))
277 
278 // R719 real-part ->
279 //        signed-int-literal-constant | signed-real-literal-constant |
280 //        named-constant
281 // R720 imag-part ->
282 //        signed-int-literal-constant | signed-real-literal-constant |
283 //        named-constant
284 TYPE_PARSER(construct<ComplexPart>(signedRealLiteralConstant) ||
285     construct<ComplexPart>(signedIntLiteralConstant) ||
286     construct<ComplexPart>(namedConstant))
287 
288 // R721 char-selector ->
289 //        length-selector |
290 //        ( LEN = type-param-value , KIND = scalar-int-constant-expr ) |
291 //        ( type-param-value , [KIND =] scalar-int-constant-expr ) |
292 //        ( KIND = scalar-int-constant-expr [, LEN = type-param-value] )
293 TYPE_PARSER(construct<CharSelector>(Parser<LengthSelector>{}) ||
294     parenthesized(construct<CharSelector>(
295         "LEN =" >> typeParamValue, ", KIND =" >> scalarIntConstantExpr)) ||
296     parenthesized(construct<CharSelector>(
297         typeParamValue / ",", maybe("KIND ="_tok) >> scalarIntConstantExpr)) ||
298     parenthesized(construct<CharSelector>(
299         "KIND =" >> scalarIntConstantExpr, maybe(", LEN =" >> typeParamValue))))
300 
301 // R722 length-selector -> ( [LEN =] type-param-value ) | * char-length [,]
302 // N.B. The trailing [,] in the production is permitted by the Standard
303 // only in the context of a type-declaration-stmt, but even with that
304 // limitation, it would seem to be unnecessary and buggy to consume the comma
305 // here.
306 TYPE_PARSER(construct<LengthSelector>(
307                 parenthesized(maybe("LEN ="_tok) >> typeParamValue)) ||
308     construct<LengthSelector>("*" >> charLength /* / maybe(","_tok) */))
309 
310 // R723 char-length -> ( type-param-value ) | digit-string
311 TYPE_PARSER(construct<CharLength>(parenthesized(typeParamValue)) ||
312     construct<CharLength>(space >> digitString64 / spaceCheck))
313 
314 // R724 char-literal-constant ->
315 //        [kind-param _] ' [rep-char]... ' |
316 //        [kind-param _] " [rep-char]... "
317 // "rep-char" is any non-control character.  Doubled interior quotes are
318 // combined.  Backslash escapes can be enabled.
319 // N.B. the parsing of "kind-param" takes care to not consume the '_'.
320 TYPE_CONTEXT_PARSER("CHARACTER literal constant"_en_US,
321     construct<CharLiteralConstant>(
322         kindParam / underscore, charLiteralConstantWithoutKind) ||
323         construct<CharLiteralConstant>(construct<std::optional<KindParam>>(),
324             space >> charLiteralConstantWithoutKind))
325 
326 TYPE_CONTEXT_PARSER(
327     "Hollerith"_en_US, construct<HollerithLiteralConstant>(rawHollerithLiteral))
328 
329 // R725 logical-literal-constant ->
330 //        .TRUE. [_ kind-param] | .FALSE. [_ kind-param]
331 // Also accept .T. and .F. as extensions.
332 TYPE_PARSER(construct<LogicalLiteralConstant>(
333                 logicalTRUE, maybe(underscore >> kindParam)) ||
334     construct<LogicalLiteralConstant>(
335         logicalFALSE, maybe(underscore >> kindParam)))
336 
337 // R726 derived-type-def ->
338 //        derived-type-stmt [type-param-def-stmt]...
339 //        [private-or-sequence]... [component-part]
340 //        [type-bound-procedure-part] end-type-stmt
341 // R735 component-part -> [component-def-stmt]...
342 TYPE_CONTEXT_PARSER("derived type definition"_en_US,
343     construct<DerivedTypeDef>(statement(Parser<DerivedTypeStmt>{}),
344         many(unambiguousStatement(Parser<TypeParamDefStmt>{})),
345         many(statement(Parser<PrivateOrSequence>{})),
346         many(inContext("component"_en_US,
347             unambiguousStatement(Parser<ComponentDefStmt>{}))),
348         maybe(Parser<TypeBoundProcedurePart>{}),
349         statement(Parser<EndTypeStmt>{})))
350 
351 // R727 derived-type-stmt ->
352 //        TYPE [[, type-attr-spec-list] ::] type-name [(
353 //        type-param-name-list )]
354 TYPE_CONTEXT_PARSER("TYPE statement"_en_US,
355     construct<DerivedTypeStmt>(
356         "TYPE" >> optionalListBeforeColons(Parser<TypeAttrSpec>{}), name,
357         defaulted(parenthesized(nonemptyList(name)))))
358 
359 // R728 type-attr-spec ->
360 //        ABSTRACT | access-spec | BIND(C) | EXTENDS ( parent-type-name )
361 TYPE_PARSER(construct<TypeAttrSpec>(construct<Abstract>("ABSTRACT"_tok)) ||
362     construct<TypeAttrSpec>(construct<TypeAttrSpec::BindC>("BIND ( C )"_tok)) ||
363     construct<TypeAttrSpec>(
364         construct<TypeAttrSpec::Extends>("EXTENDS" >> parenthesized(name))) ||
365     construct<TypeAttrSpec>(accessSpec))
366 
367 // R729 private-or-sequence -> private-components-stmt | sequence-stmt
368 TYPE_PARSER(construct<PrivateOrSequence>(Parser<PrivateStmt>{}) ||
369     construct<PrivateOrSequence>(Parser<SequenceStmt>{}))
370 
371 // R730 end-type-stmt -> END TYPE [type-name]
372 TYPE_PARSER(construct<EndTypeStmt>(
373     recovery("END TYPE" >> maybe(name), endStmtErrorRecovery)))
374 
375 // R731 sequence-stmt -> SEQUENCE
376 TYPE_PARSER(construct<SequenceStmt>("SEQUENCE"_tok))
377 
378 // R732 type-param-def-stmt ->
379 //        integer-type-spec , type-param-attr-spec :: type-param-decl-list
380 // R734 type-param-attr-spec -> KIND | LEN
381 constexpr auto kindOrLen{"KIND" >> pure(common::TypeParamAttr::Kind) ||
382     "LEN" >> pure(common::TypeParamAttr::Len)};
383 TYPE_PARSER(construct<TypeParamDefStmt>(integerTypeSpec / ",", kindOrLen,
384     "::" >> nonemptyList("expected type parameter declarations"_err_en_US,
385                 Parser<TypeParamDecl>{})))
386 
387 // R733 type-param-decl -> type-param-name [= scalar-int-constant-expr]
388 TYPE_PARSER(construct<TypeParamDecl>(name, maybe("=" >> scalarIntConstantExpr)))
389 
390 // R736 component-def-stmt -> data-component-def-stmt |
391 //        proc-component-def-stmt
392 // Accidental extension not enabled here: PGI accepts type-param-def-stmt in
393 // component-part of derived-type-def.
394 TYPE_PARSER(recovery(
395     withMessage("expected component definition"_err_en_US,
396         first(construct<ComponentDefStmt>(Parser<DataComponentDefStmt>{}),
397             construct<ComponentDefStmt>(Parser<ProcComponentDefStmt>{}))),
398     construct<ComponentDefStmt>(inStmtErrorRecovery)))
399 
400 // R737 data-component-def-stmt ->
401 //        declaration-type-spec [[, component-attr-spec-list] ::]
402 //        component-decl-list
403 // N.B. The standard requires double colons if there's an initializer.
404 TYPE_PARSER(construct<DataComponentDefStmt>(declarationTypeSpec,
405     optionalListBeforeColons(Parser<ComponentAttrSpec>{}),
406     nonemptyList("expected component declarations"_err_en_US,
407         Parser<ComponentOrFill>{})))
408 
409 // R738 component-attr-spec ->
410 //        access-spec | ALLOCATABLE |
411 //        CODIMENSION lbracket coarray-spec rbracket |
412 //        CONTIGUOUS | DIMENSION ( component-array-spec ) | POINTER
413 TYPE_PARSER(construct<ComponentAttrSpec>(accessSpec) ||
414     construct<ComponentAttrSpec>(allocatable) ||
415     construct<ComponentAttrSpec>("CODIMENSION" >> coarraySpec) ||
416     construct<ComponentAttrSpec>(contiguous) ||
417     construct<ComponentAttrSpec>("DIMENSION" >> Parser<ComponentArraySpec>{}) ||
418     construct<ComponentAttrSpec>(pointer) ||
419     construct<ComponentAttrSpec>(recovery(
420         fail<ErrorRecovery>(
421             "type parameter definitions must appear before component declarations"_err_en_US),
422         kindOrLen >> construct<ErrorRecovery>())))
423 
424 // R739 component-decl ->
425 //        component-name [( component-array-spec )]
426 //        [lbracket coarray-spec rbracket] [* char-length]
427 //        [component-initialization]
428 TYPE_CONTEXT_PARSER("component declaration"_en_US,
429     construct<ComponentDecl>(name, maybe(Parser<ComponentArraySpec>{}),
430         maybe(coarraySpec), maybe("*" >> charLength), maybe(initialization)))
431 // The source field of the Name will be replaced with a distinct generated name.
432 TYPE_CONTEXT_PARSER("%FILL item"_en_US,
433     extension<LanguageFeature::DECStructures>(
434         construct<FillDecl>(space >> sourced("%FILL" >> construct<Name>()),
435             maybe(Parser<ComponentArraySpec>{}), maybe("*" >> charLength))))
436 TYPE_PARSER(construct<ComponentOrFill>(Parser<ComponentDecl>{}) ||
437     construct<ComponentOrFill>(Parser<FillDecl>{}))
438 
439 // R740 component-array-spec ->
440 //        explicit-shape-spec-list | deferred-shape-spec-list
441 // N.B. Parenthesized here rather than around references to this production.
442 TYPE_PARSER(construct<ComponentArraySpec>(parenthesized(
443                 nonemptyList("expected explicit shape specifications"_err_en_US,
444                     explicitShapeSpec))) ||
445     construct<ComponentArraySpec>(parenthesized(deferredShapeSpecList)))
446 
447 // R741 proc-component-def-stmt ->
448 //        PROCEDURE ( [proc-interface] ) , proc-component-attr-spec-list
449 //          :: proc-decl-list
450 TYPE_CONTEXT_PARSER("PROCEDURE component definition statement"_en_US,
451     construct<ProcComponentDefStmt>(
452         "PROCEDURE" >> parenthesized(maybe(procInterface)),
453         localRecovery("expected PROCEDURE component attributes"_err_en_US,
454             "," >> nonemptyList(Parser<ProcComponentAttrSpec>{}), ok),
455         localRecovery("expected PROCEDURE declarations"_err_en_US,
456             "::" >> nonemptyList(procDecl), SkipTo<'\n'>{})))
457 
458 // R742 proc-component-attr-spec ->
459 //        access-spec | NOPASS | PASS [(arg-name)] | POINTER
460 constexpr auto noPass{construct<NoPass>("NOPASS"_tok)};
461 constexpr auto pass{construct<Pass>("PASS" >> maybe(parenthesized(name)))};
462 TYPE_PARSER(construct<ProcComponentAttrSpec>(accessSpec) ||
463     construct<ProcComponentAttrSpec>(noPass) ||
464     construct<ProcComponentAttrSpec>(pass) ||
465     construct<ProcComponentAttrSpec>(pointer))
466 
467 // R744 initial-data-target -> designator
468 constexpr auto initialDataTarget{indirect(designator)};
469 
470 // R743 component-initialization ->
471 //        = constant-expr | => null-init | => initial-data-target
472 // R805 initialization ->
473 //        = constant-expr | => null-init | => initial-data-target
474 // Universal extension: initialization -> / data-stmt-value-list /
475 TYPE_PARSER(construct<Initialization>("=>" >> nullInit) ||
476     construct<Initialization>("=>" >> initialDataTarget) ||
477     construct<Initialization>("=" >> constantExpr) ||
478     extension<LanguageFeature::SlashInitialization>(construct<Initialization>(
479         "/" >> nonemptyList("expected values"_err_en_US,
480                    indirect(Parser<DataStmtValue>{})) /
481             "/")))
482 
483 // R745 private-components-stmt -> PRIVATE
484 // R747 binding-private-stmt -> PRIVATE
485 TYPE_PARSER(construct<PrivateStmt>("PRIVATE"_tok))
486 
487 // R746 type-bound-procedure-part ->
488 //        contains-stmt [binding-private-stmt] [type-bound-proc-binding]...
489 TYPE_CONTEXT_PARSER("type bound procedure part"_en_US,
490     construct<TypeBoundProcedurePart>(statement(containsStmt),
491         maybe(statement(Parser<PrivateStmt>{})),
492         many(statement(Parser<TypeBoundProcBinding>{}))))
493 
494 // R748 type-bound-proc-binding ->
495 //        type-bound-procedure-stmt | type-bound-generic-stmt |
496 //        final-procedure-stmt
497 TYPE_CONTEXT_PARSER("type bound procedure binding"_en_US,
498     recovery(
499         first(construct<TypeBoundProcBinding>(Parser<TypeBoundProcedureStmt>{}),
500             construct<TypeBoundProcBinding>(Parser<TypeBoundGenericStmt>{}),
501             construct<TypeBoundProcBinding>(Parser<FinalProcedureStmt>{})),
502         construct<TypeBoundProcBinding>(
503             !"END"_tok >> SkipTo<'\n'>{} >> construct<ErrorRecovery>())))
504 
505 // R749 type-bound-procedure-stmt ->
506 //        PROCEDURE [[, bind-attr-list] ::] type-bound-proc-decl-list |
507 //        PROCEDURE ( interface-name ) , bind-attr-list :: binding-name-list
508 TYPE_CONTEXT_PARSER("type bound PROCEDURE statement"_en_US,
509     "PROCEDURE" >>
510         (construct<TypeBoundProcedureStmt>(
511              construct<TypeBoundProcedureStmt::WithInterface>(
512                  parenthesized(name),
513                  localRecovery("expected list of binding attributes"_err_en_US,
514                      "," >> nonemptyList(Parser<BindAttr>{}), ok),
515                  localRecovery("expected list of binding names"_err_en_US,
516                      "::" >> listOfNames, SkipTo<'\n'>{}))) ||
517             construct<TypeBoundProcedureStmt>(
518                 construct<TypeBoundProcedureStmt::WithoutInterface>(
519                     optionalListBeforeColons(Parser<BindAttr>{}),
520                     nonemptyList(
521                         "expected type bound procedure declarations"_err_en_US,
522                         Parser<TypeBoundProcDecl>{})))))
523 
524 // R750 type-bound-proc-decl -> binding-name [=> procedure-name]
525 TYPE_PARSER(construct<TypeBoundProcDecl>(name, maybe("=>" >> name)))
526 
527 // R751 type-bound-generic-stmt ->
528 //        GENERIC [, access-spec] :: generic-spec => binding-name-list
529 TYPE_CONTEXT_PARSER("type bound GENERIC statement"_en_US,
530     construct<TypeBoundGenericStmt>("GENERIC" >> maybe("," >> accessSpec),
531         "::" >> indirect(genericSpec), "=>" >> listOfNames))
532 
533 // R752 bind-attr ->
534 //        access-spec | DEFERRED | NON_OVERRIDABLE | NOPASS | PASS [(arg-name)]
535 TYPE_PARSER(construct<BindAttr>(accessSpec) ||
536     construct<BindAttr>(construct<BindAttr::Deferred>("DEFERRED"_tok)) ||
537     construct<BindAttr>(
538         construct<BindAttr::Non_Overridable>("NON_OVERRIDABLE"_tok)) ||
539     construct<BindAttr>(noPass) || construct<BindAttr>(pass))
540 
541 // R753 final-procedure-stmt -> FINAL [::] final-subroutine-name-list
542 TYPE_CONTEXT_PARSER("FINAL statement"_en_US,
543     construct<FinalProcedureStmt>("FINAL" >> maybe("::"_tok) >> listOfNames))
544 
545 // R754 derived-type-spec -> type-name [(type-param-spec-list)]
546 TYPE_PARSER(construct<DerivedTypeSpec>(name,
547     defaulted(parenthesized(nonemptyList(
548         "expected type parameters"_err_en_US, Parser<TypeParamSpec>{})))))
549 
550 // R755 type-param-spec -> [keyword =] type-param-value
551 TYPE_PARSER(construct<TypeParamSpec>(maybe(keyword / "="), typeParamValue))
552 
553 // R756 structure-constructor -> derived-type-spec ( [component-spec-list] )
554 TYPE_PARSER((construct<StructureConstructor>(derivedTypeSpec,
555                  parenthesized(optionalList(Parser<ComponentSpec>{}))) ||
556                 // This alternative corrects misrecognition of the
557                 // component-spec-list as the type-param-spec-list in
558                 // derived-type-spec.
559                 construct<StructureConstructor>(
560                     construct<DerivedTypeSpec>(
561                         name, construct<std::list<TypeParamSpec>>()),
562                     parenthesized(optionalList(Parser<ComponentSpec>{})))) /
563     !"("_tok)
564 
565 // R757 component-spec -> [keyword =] component-data-source
566 TYPE_PARSER(construct<ComponentSpec>(
567     maybe(keyword / "="), Parser<ComponentDataSource>{}))
568 
569 // R758 component-data-source -> expr | data-target | proc-target
570 TYPE_PARSER(construct<ComponentDataSource>(indirect(expr)))
571 
572 // R759 enum-def ->
573 //        enum-def-stmt enumerator-def-stmt [enumerator-def-stmt]...
574 //        end-enum-stmt
575 TYPE_CONTEXT_PARSER("enum definition"_en_US,
576     construct<EnumDef>(statement(Parser<EnumDefStmt>{}),
577         some(unambiguousStatement(Parser<EnumeratorDefStmt>{})),
578         statement(Parser<EndEnumStmt>{})))
579 
580 // R760 enum-def-stmt -> ENUM, BIND(C)
581 TYPE_PARSER(construct<EnumDefStmt>("ENUM , BIND ( C )"_tok))
582 
583 // R761 enumerator-def-stmt -> ENUMERATOR [::] enumerator-list
584 TYPE_CONTEXT_PARSER("ENUMERATOR statement"_en_US,
585     construct<EnumeratorDefStmt>("ENUMERATOR" >> maybe("::"_tok) >>
586         nonemptyList("expected enumerators"_err_en_US, Parser<Enumerator>{})))
587 
588 // R762 enumerator -> named-constant [= scalar-int-constant-expr]
589 TYPE_PARSER(
590     construct<Enumerator>(namedConstant, maybe("=" >> scalarIntConstantExpr)))
591 
592 // R763 end-enum-stmt -> END ENUM
593 TYPE_PARSER(recovery("END ENUM"_tok, "END" >> SkipPast<'\n'>{}) >>
594     construct<EndEnumStmt>())
595 
596 // R801 type-declaration-stmt ->
597 //        declaration-type-spec [[, attr-spec]... ::] entity-decl-list
598 constexpr auto entityDeclWithoutEqInit{construct<EntityDecl>(name,
599     maybe(arraySpec), maybe(coarraySpec), maybe("*" >> charLength),
600     !"="_tok >> maybe(initialization))}; // old-style REAL A/0/ still works
601 TYPE_PARSER(
602     construct<TypeDeclarationStmt>(declarationTypeSpec,
603         defaulted("," >> nonemptyList(Parser<AttrSpec>{})) / "::",
604         nonemptyList("expected entity declarations"_err_en_US, entityDecl)) ||
605     // C806: no initializers allowed without colons ("REALA=1" is ambiguous)
606     construct<TypeDeclarationStmt>(declarationTypeSpec,
607         construct<std::list<AttrSpec>>(),
608         nonemptyList("expected entity declarations"_err_en_US,
609             entityDeclWithoutEqInit)) ||
610     // PGI-only extension: comma in place of doubled colons
611     extension<LanguageFeature::MissingColons>(construct<TypeDeclarationStmt>(
612         declarationTypeSpec, defaulted("," >> nonemptyList(Parser<AttrSpec>{})),
613         withMessage("expected entity declarations"_err_en_US,
614             "," >> nonemptyList(entityDecl)))))
615 
616 // R802 attr-spec ->
617 //        access-spec | ALLOCATABLE | ASYNCHRONOUS |
618 //        CODIMENSION lbracket coarray-spec rbracket | CONTIGUOUS |
619 //        DIMENSION ( array-spec ) | EXTERNAL | INTENT ( intent-spec ) |
620 //        INTRINSIC | language-binding-spec | OPTIONAL | PARAMETER | POINTER |
621 //        PROTECTED | SAVE | TARGET | VALUE | VOLATILE
622 TYPE_PARSER(construct<AttrSpec>(accessSpec) ||
623     construct<AttrSpec>(allocatable) ||
624     construct<AttrSpec>(construct<Asynchronous>("ASYNCHRONOUS"_tok)) ||
625     construct<AttrSpec>("CODIMENSION" >> coarraySpec) ||
626     construct<AttrSpec>(contiguous) ||
627     construct<AttrSpec>("DIMENSION" >> arraySpec) ||
628     construct<AttrSpec>(construct<External>("EXTERNAL"_tok)) ||
629     construct<AttrSpec>("INTENT" >> parenthesized(intentSpec)) ||
630     construct<AttrSpec>(construct<Intrinsic>("INTRINSIC"_tok)) ||
631     construct<AttrSpec>(languageBindingSpec) || construct<AttrSpec>(optional) ||
632     construct<AttrSpec>(construct<Parameter>("PARAMETER"_tok)) ||
633     construct<AttrSpec>(pointer) || construct<AttrSpec>(protectedAttr) ||
634     construct<AttrSpec>(save) ||
635     construct<AttrSpec>(construct<Target>("TARGET"_tok)) ||
636     construct<AttrSpec>(construct<Value>("VALUE"_tok)) ||
637     construct<AttrSpec>(construct<Volatile>("VOLATILE"_tok)))
638 
639 // R804 object-name -> name
640 constexpr auto objectName{name};
641 
642 // R803 entity-decl ->
643 //        object-name [( array-spec )] [lbracket coarray-spec rbracket]
644 //          [* char-length] [initialization] |
645 //        function-name [* char-length]
646 TYPE_PARSER(construct<EntityDecl>(objectName, maybe(arraySpec),
647     maybe(coarraySpec), maybe("*" >> charLength), maybe(initialization)))
648 
649 // R806 null-init -> function-reference   ... which must resolve to NULL()
650 TYPE_PARSER(lookAhead(name / "( )") >> construct<NullInit>(expr))
651 
652 // R807 access-spec -> PUBLIC | PRIVATE
653 TYPE_PARSER(construct<AccessSpec>("PUBLIC" >> pure(AccessSpec::Kind::Public)) ||
654     construct<AccessSpec>("PRIVATE" >> pure(AccessSpec::Kind::Private)))
655 
656 // R808 language-binding-spec ->
657 //        BIND ( C [, NAME = scalar-default-char-constant-expr] )
658 // R1528 proc-language-binding-spec -> language-binding-spec
659 TYPE_PARSER(construct<LanguageBindingSpec>(
660     "BIND ( C" >> maybe(", NAME =" >> scalarDefaultCharConstantExpr) / ")"))
661 
662 // R809 coarray-spec -> deferred-coshape-spec-list | explicit-coshape-spec
663 // N.B. Bracketed here rather than around references, for consistency with
664 // array-spec.
665 TYPE_PARSER(
666     construct<CoarraySpec>(bracketed(Parser<DeferredCoshapeSpecList>{})) ||
667     construct<CoarraySpec>(bracketed(Parser<ExplicitCoshapeSpec>{})))
668 
669 // R810 deferred-coshape-spec -> :
670 // deferred-coshape-spec-list - just a list of colons
671 inline int listLength(std::list<Success> &&xs) { return xs.size(); }
672 
673 TYPE_PARSER(construct<DeferredCoshapeSpecList>(
674     applyFunction(listLength, nonemptyList(":"_tok))))
675 
676 // R811 explicit-coshape-spec ->
677 //        [[lower-cobound :] upper-cobound ,]... [lower-cobound :] *
678 // R812 lower-cobound -> specification-expr
679 // R813 upper-cobound -> specification-expr
680 TYPE_PARSER(construct<ExplicitCoshapeSpec>(
681     many(explicitShapeSpec / ","), maybe(specificationExpr / ":") / "*"))
682 
683 // R815 array-spec ->
684 //        explicit-shape-spec-list | assumed-shape-spec-list |
685 //        deferred-shape-spec-list | assumed-size-spec | implied-shape-spec |
686 //        implied-shape-or-assumed-size-spec | assumed-rank-spec
687 // N.B. Parenthesized here rather than around references to avoid
688 // a need for forced look-ahead.
689 // Shape specs that could be deferred-shape-spec or assumed-shape-spec
690 // (e.g. '(:,:)') are parsed as the former.
691 TYPE_PARSER(
692     construct<ArraySpec>(parenthesized(nonemptyList(explicitShapeSpec))) ||
693     construct<ArraySpec>(parenthesized(deferredShapeSpecList)) ||
694     construct<ArraySpec>(
695         parenthesized(nonemptyList(Parser<AssumedShapeSpec>{}))) ||
696     construct<ArraySpec>(parenthesized(Parser<AssumedSizeSpec>{})) ||
697     construct<ArraySpec>(parenthesized(Parser<ImpliedShapeSpec>{})) ||
698     construct<ArraySpec>(parenthesized(Parser<AssumedRankSpec>{})))
699 
700 // R816 explicit-shape-spec -> [lower-bound :] upper-bound
701 // R817 lower-bound -> specification-expr
702 // R818 upper-bound -> specification-expr
703 TYPE_PARSER(construct<ExplicitShapeSpec>(
704     maybe(specificationExpr / ":"), specificationExpr))
705 
706 // R819 assumed-shape-spec -> [lower-bound] :
707 TYPE_PARSER(construct<AssumedShapeSpec>(maybe(specificationExpr) / ":"))
708 
709 // R820 deferred-shape-spec -> :
710 // deferred-shape-spec-list - just a list of colons
711 TYPE_PARSER(construct<DeferredShapeSpecList>(
712     applyFunction(listLength, nonemptyList(":"_tok))))
713 
714 // R821 assumed-implied-spec -> [lower-bound :] *
715 TYPE_PARSER(construct<AssumedImpliedSpec>(maybe(specificationExpr / ":") / "*"))
716 
717 // R822 assumed-size-spec -> explicit-shape-spec-list , assumed-implied-spec
718 TYPE_PARSER(construct<AssumedSizeSpec>(
719     nonemptyList(explicitShapeSpec) / ",", assumedImpliedSpec))
720 
721 // R823 implied-shape-or-assumed-size-spec -> assumed-implied-spec
722 // R824 implied-shape-spec -> assumed-implied-spec , assumed-implied-spec-list
723 // I.e., when the assumed-implied-spec-list has a single item, it constitutes an
724 // implied-shape-or-assumed-size-spec; otherwise, an implied-shape-spec.
725 TYPE_PARSER(construct<ImpliedShapeSpec>(nonemptyList(assumedImpliedSpec)))
726 
727 // R825 assumed-rank-spec -> ..
728 TYPE_PARSER(construct<AssumedRankSpec>(".."_tok))
729 
730 // R826 intent-spec -> IN | OUT | INOUT
731 TYPE_PARSER(construct<IntentSpec>("IN OUT" >> pure(IntentSpec::Intent::InOut) ||
732     "IN" >> pure(IntentSpec::Intent::In) ||
733     "OUT" >> pure(IntentSpec::Intent::Out)))
734 
735 // R827 access-stmt -> access-spec [[::] access-id-list]
736 TYPE_PARSER(construct<AccessStmt>(accessSpec,
737     defaulted(maybe("::"_tok) >>
738         nonemptyList("expected names and generic specifications"_err_en_US,
739             Parser<AccessId>{}))))
740 
741 // R828 access-id -> access-name | generic-spec
742 TYPE_PARSER(construct<AccessId>(indirect(genericSpec)) ||
743     construct<AccessId>(name)) // initially ambiguous with genericSpec
744 
745 // R829 allocatable-stmt -> ALLOCATABLE [::] allocatable-decl-list
746 TYPE_PARSER(construct<AllocatableStmt>("ALLOCATABLE" >> maybe("::"_tok) >>
747     nonemptyList(
748         "expected object declarations"_err_en_US, Parser<ObjectDecl>{})))
749 
750 // R830 allocatable-decl ->
751 //        object-name [( array-spec )] [lbracket coarray-spec rbracket]
752 // R860 target-decl ->
753 //        object-name [( array-spec )] [lbracket coarray-spec rbracket]
754 TYPE_PARSER(
755     construct<ObjectDecl>(objectName, maybe(arraySpec), maybe(coarraySpec)))
756 
757 // R831 asynchronous-stmt -> ASYNCHRONOUS [::] object-name-list
758 TYPE_PARSER(construct<AsynchronousStmt>("ASYNCHRONOUS" >> maybe("::"_tok) >>
759     nonemptyList("expected object names"_err_en_US, objectName)))
760 
761 // R832 bind-stmt -> language-binding-spec [::] bind-entity-list
762 TYPE_PARSER(construct<BindStmt>(languageBindingSpec / maybe("::"_tok),
763     nonemptyList("expected bind entities"_err_en_US, Parser<BindEntity>{})))
764 
765 // R833 bind-entity -> entity-name | / common-block-name /
766 TYPE_PARSER(construct<BindEntity>(pure(BindEntity::Kind::Object), name) ||
767     construct<BindEntity>("/" >> pure(BindEntity::Kind::Common), name / "/"))
768 
769 // R834 codimension-stmt -> CODIMENSION [::] codimension-decl-list
770 TYPE_PARSER(construct<CodimensionStmt>("CODIMENSION" >> maybe("::"_tok) >>
771     nonemptyList("expected codimension declarations"_err_en_US,
772         Parser<CodimensionDecl>{})))
773 
774 // R835 codimension-decl -> coarray-name lbracket coarray-spec rbracket
775 TYPE_PARSER(construct<CodimensionDecl>(name, coarraySpec))
776 
777 // R836 contiguous-stmt -> CONTIGUOUS [::] object-name-list
778 TYPE_PARSER(construct<ContiguousStmt>("CONTIGUOUS" >> maybe("::"_tok) >>
779     nonemptyList("expected object names"_err_en_US, objectName)))
780 
781 // R837 data-stmt -> DATA data-stmt-set [[,] data-stmt-set]...
782 TYPE_CONTEXT_PARSER("DATA statement"_en_US,
783     construct<DataStmt>(
784         "DATA" >> nonemptySeparated(Parser<DataStmtSet>{}, maybe(","_tok))))
785 
786 // R838 data-stmt-set -> data-stmt-object-list / data-stmt-value-list /
787 TYPE_PARSER(construct<DataStmtSet>(
788     nonemptyList(
789         "expected DATA statement objects"_err_en_US, Parser<DataStmtObject>{}),
790     withMessage("expected DATA statement value list"_err_en_US,
791         "/"_tok >> nonemptyList("expected DATA statement values"_err_en_US,
792                        Parser<DataStmtValue>{})) /
793         "/"))
794 
795 // R839 data-stmt-object -> variable | data-implied-do
796 TYPE_PARSER(construct<DataStmtObject>(indirect(variable)) ||
797     construct<DataStmtObject>(dataImpliedDo))
798 
799 // R840 data-implied-do ->
800 //        ( data-i-do-object-list , [integer-type-spec ::] data-i-do-variable
801 //        = scalar-int-constant-expr , scalar-int-constant-expr
802 //        [, scalar-int-constant-expr] )
803 // R842 data-i-do-variable -> do-variable
804 TYPE_PARSER(parenthesized(construct<DataImpliedDo>(
805     nonemptyList(Parser<DataIDoObject>{} / lookAhead(","_tok)) / ",",
806     maybe(integerTypeSpec / "::"), loopBounds(scalarIntConstantExpr))))
807 
808 // R841 data-i-do-object ->
809 //        array-element | scalar-structure-component | data-implied-do
810 TYPE_PARSER(construct<DataIDoObject>(scalar(indirect(designator))) ||
811     construct<DataIDoObject>(indirect(dataImpliedDo)))
812 
813 // R843 data-stmt-value -> [data-stmt-repeat *] data-stmt-constant
814 TYPE_PARSER(construct<DataStmtValue>(
815     maybe(Parser<DataStmtRepeat>{} / "*"), Parser<DataStmtConstant>{}))
816 
817 // R847 constant-subobject -> designator
818 // R846 int-constant-subobject -> constant-subobject
819 constexpr auto constantSubobject{constant(indirect(designator))};
820 
821 // R844 data-stmt-repeat -> scalar-int-constant | scalar-int-constant-subobject
822 // R607 int-constant -> constant
823 // Factored into: constant -> literal-constant -> int-literal-constant
824 // The named-constant alternative of constant is subsumed by constant-subobject
825 TYPE_PARSER(construct<DataStmtRepeat>(intLiteralConstant) ||
826     construct<DataStmtRepeat>(scalar(integer(constantSubobject))))
827 
828 // R845 data-stmt-constant ->
829 //        scalar-constant | scalar-constant-subobject |
830 //        signed-int-literal-constant | signed-real-literal-constant |
831 //        null-init | initial-data-target |
832 //        constant-structure-constructor
833 // N.B. scalar-constant and scalar-constant-subobject are ambiguous with
834 // initial-data-target; null-init and structure-constructor are ambiguous
835 // in the absence of parameters and components; structure-constructor with
836 // components can be ambiguous with a scalar-constant-subobject.
837 // So we parse literal constants, designator, null-init, and
838 // structure-constructor, so that semantics can figure things out later
839 // with the symbol table.
840 TYPE_PARSER(sourced(first(construct<DataStmtConstant>(literalConstant),
841     construct<DataStmtConstant>(signedRealLiteralConstant),
842     construct<DataStmtConstant>(signedIntLiteralConstant),
843     extension<LanguageFeature::SignedComplexLiteral>(
844         construct<DataStmtConstant>(Parser<SignedComplexLiteralConstant>{})),
845     construct<DataStmtConstant>(nullInit),
846     construct<DataStmtConstant>(indirect(designator) / !"("_tok),
847     construct<DataStmtConstant>(Parser<StructureConstructor>{}))))
848 
849 // R848 dimension-stmt ->
850 //        DIMENSION [::] array-name ( array-spec )
851 //        [, array-name ( array-spec )]...
852 TYPE_CONTEXT_PARSER("DIMENSION statement"_en_US,
853     construct<DimensionStmt>("DIMENSION" >> maybe("::"_tok) >>
854         nonemptyList("expected array specifications"_err_en_US,
855             construct<DimensionStmt::Declaration>(name, arraySpec))))
856 
857 // R849 intent-stmt -> INTENT ( intent-spec ) [::] dummy-arg-name-list
858 TYPE_CONTEXT_PARSER("INTENT statement"_en_US,
859     construct<IntentStmt>(
860         "INTENT" >> parenthesized(intentSpec) / maybe("::"_tok), listOfNames))
861 
862 // R850 optional-stmt -> OPTIONAL [::] dummy-arg-name-list
863 TYPE_PARSER(
864     construct<OptionalStmt>("OPTIONAL" >> maybe("::"_tok) >> listOfNames))
865 
866 // R851 parameter-stmt -> PARAMETER ( named-constant-def-list )
867 // Legacy extension: omitted parentheses, no implicit typing from names
868 TYPE_CONTEXT_PARSER("PARAMETER statement"_en_US,
869     construct<ParameterStmt>(
870         "PARAMETER" >> parenthesized(nonemptyList(Parser<NamedConstantDef>{}))))
871 TYPE_CONTEXT_PARSER("old style PARAMETER statement"_en_US,
872     extension<LanguageFeature::OldStyleParameter>(construct<OldParameterStmt>(
873         "PARAMETER" >> nonemptyList(Parser<NamedConstantDef>{}))))
874 
875 // R852 named-constant-def -> named-constant = constant-expr
876 TYPE_PARSER(construct<NamedConstantDef>(namedConstant, "=" >> constantExpr))
877 
878 // R853 pointer-stmt -> POINTER [::] pointer-decl-list
879 TYPE_PARSER(construct<PointerStmt>("POINTER" >> maybe("::"_tok) >>
880     nonemptyList(
881         "expected pointer declarations"_err_en_US, Parser<PointerDecl>{})))
882 
883 // R854 pointer-decl ->
884 //        object-name [( deferred-shape-spec-list )] | proc-entity-name
885 TYPE_PARSER(
886     construct<PointerDecl>(name, maybe(parenthesized(deferredShapeSpecList))))
887 
888 // R855 protected-stmt -> PROTECTED [::] entity-name-list
889 TYPE_PARSER(
890     construct<ProtectedStmt>("PROTECTED" >> maybe("::"_tok) >> listOfNames))
891 
892 // R856 save-stmt -> SAVE [[::] saved-entity-list]
893 TYPE_PARSER(construct<SaveStmt>(
894     "SAVE" >> defaulted(maybe("::"_tok) >>
895                   nonemptyList("expected SAVE entities"_err_en_US,
896                       Parser<SavedEntity>{}))))
897 
898 // R857 saved-entity -> object-name | proc-pointer-name | / common-block-name /
899 // R858 proc-pointer-name -> name
900 TYPE_PARSER(construct<SavedEntity>(pure(SavedEntity::Kind::Entity), name) ||
901     construct<SavedEntity>("/" >> pure(SavedEntity::Kind::Common), name / "/"))
902 
903 // R859 target-stmt -> TARGET [::] target-decl-list
904 TYPE_PARSER(construct<TargetStmt>("TARGET" >> maybe("::"_tok) >>
905     nonemptyList("expected objects"_err_en_US, Parser<ObjectDecl>{})))
906 
907 // R861 value-stmt -> VALUE [::] dummy-arg-name-list
908 TYPE_PARSER(construct<ValueStmt>("VALUE" >> maybe("::"_tok) >> listOfNames))
909 
910 // R862 volatile-stmt -> VOLATILE [::] object-name-list
911 TYPE_PARSER(construct<VolatileStmt>("VOLATILE" >> maybe("::"_tok) >>
912     nonemptyList("expected object names"_err_en_US, objectName)))
913 
914 // R866 implicit-name-spec -> EXTERNAL | TYPE
915 constexpr auto implicitNameSpec{
916     "EXTERNAL" >> pure(ImplicitStmt::ImplicitNoneNameSpec::External) ||
917     "TYPE" >> pure(ImplicitStmt::ImplicitNoneNameSpec::Type)};
918 
919 // R863 implicit-stmt ->
920 //        IMPLICIT implicit-spec-list |
921 //        IMPLICIT NONE [( [implicit-name-spec-list] )]
922 TYPE_CONTEXT_PARSER("IMPLICIT statement"_en_US,
923     construct<ImplicitStmt>(
924         "IMPLICIT" >> nonemptyList("expected IMPLICIT specifications"_err_en_US,
925                           Parser<ImplicitSpec>{})) ||
926         construct<ImplicitStmt>("IMPLICIT NONE"_sptok >>
927             defaulted(parenthesized(optionalList(implicitNameSpec)))))
928 
929 // R864 implicit-spec -> declaration-type-spec ( letter-spec-list )
930 // The variant form of declarationTypeSpec is meant to avoid misrecognition
931 // of a letter-spec as a simple parenthesized expression for kind or character
932 // length, e.g., PARAMETER(I=5,N=1); IMPLICIT REAL(I-N)(O-Z) vs.
933 // IMPLICIT REAL(I-N).  The variant form needs to attempt to reparse only
934 // types with optional parenthesized kind/length expressions, so derived
935 // type specs, DOUBLE PRECISION, and DOUBLE COMPLEX need not be considered.
936 constexpr auto noKindSelector{construct<std::optional<KindSelector>>()};
937 constexpr auto implicitSpecDeclarationTypeSpecRetry{
938     construct<DeclarationTypeSpec>(first(
939         construct<IntrinsicTypeSpec>(
940             construct<IntegerTypeSpec>("INTEGER" >> noKindSelector)),
941         construct<IntrinsicTypeSpec>(
942             construct<IntrinsicTypeSpec::Real>("REAL" >> noKindSelector)),
943         construct<IntrinsicTypeSpec>(
944             construct<IntrinsicTypeSpec::Complex>("COMPLEX" >> noKindSelector)),
945         construct<IntrinsicTypeSpec>(construct<IntrinsicTypeSpec::Character>(
946             "CHARACTER" >> construct<std::optional<CharSelector>>())),
947         construct<IntrinsicTypeSpec>(construct<IntrinsicTypeSpec::Logical>(
948             "LOGICAL" >> noKindSelector))))};
949 
950 TYPE_PARSER(construct<ImplicitSpec>(declarationTypeSpec,
951                 parenthesized(nonemptyList(Parser<LetterSpec>{}))) ||
952     construct<ImplicitSpec>(implicitSpecDeclarationTypeSpecRetry,
953         parenthesized(nonemptyList(Parser<LetterSpec>{}))))
954 
955 // R865 letter-spec -> letter [- letter]
956 TYPE_PARSER(space >> (construct<LetterSpec>(letter, maybe("-" >> letter)) ||
957                          construct<LetterSpec>(otherIdChar,
958                              construct<std::optional<const char *>>())))
959 
960 // R867 import-stmt ->
961 //        IMPORT [[::] import-name-list] |
962 //        IMPORT , ONLY : import-name-list | IMPORT , NONE | IMPORT , ALL
963 TYPE_CONTEXT_PARSER("IMPORT statement"_en_US,
964     construct<ImportStmt>(
965         "IMPORT , ONLY :" >> pure(common::ImportKind::Only), listOfNames) ||
966         construct<ImportStmt>(
967             "IMPORT , NONE" >> pure(common::ImportKind::None)) ||
968         construct<ImportStmt>(
969             "IMPORT , ALL" >> pure(common::ImportKind::All)) ||
970         construct<ImportStmt>(
971             "IMPORT" >> maybe("::"_tok) >> optionalList(name)))
972 
973 // R868 namelist-stmt ->
974 //        NAMELIST / namelist-group-name / namelist-group-object-list
975 //        [[,] / namelist-group-name / namelist-group-object-list]...
976 // R869 namelist-group-object -> variable-name
977 TYPE_PARSER(construct<NamelistStmt>("NAMELIST" >>
978     nonemptySeparated(
979         construct<NamelistStmt::Group>("/" >> name / "/", listOfNames),
980         maybe(","_tok))))
981 
982 // R870 equivalence-stmt -> EQUIVALENCE equivalence-set-list
983 // R871 equivalence-set -> ( equivalence-object , equivalence-object-list )
984 TYPE_PARSER(construct<EquivalenceStmt>("EQUIVALENCE" >>
985     nonemptyList(
986         parenthesized(nonemptyList("expected EQUIVALENCE objects"_err_en_US,
987             Parser<EquivalenceObject>{})))))
988 
989 // R872 equivalence-object -> variable-name | array-element | substring
990 TYPE_PARSER(construct<EquivalenceObject>(indirect(designator)))
991 
992 // R873 common-stmt ->
993 //        COMMON [/ [common-block-name] /] common-block-object-list
994 //        [[,] / [common-block-name] / common-block-object-list]...
995 TYPE_PARSER(
996     construct<CommonStmt>("COMMON" >> defaulted("/" >> maybe(name) / "/"),
997         nonemptyList("expected COMMON block objects"_err_en_US,
998             Parser<CommonBlockObject>{}),
999         many(maybe(","_tok) >>
1000             construct<CommonStmt::Block>("/" >> maybe(name) / "/",
1001                 nonemptyList("expected COMMON block objects"_err_en_US,
1002                     Parser<CommonBlockObject>{})))))
1003 
1004 // R874 common-block-object -> variable-name [( array-spec )]
1005 TYPE_PARSER(construct<CommonBlockObject>(name, maybe(arraySpec)))
1006 
1007 // R901 designator -> object-name | array-element | array-section |
1008 //                    coindexed-named-object | complex-part-designator |
1009 //                    structure-component | substring
1010 // The Standard's productions for designator and its alternatives are
1011 // ambiguous without recourse to a symbol table.  Many of the alternatives
1012 // for designator (viz., array-element, coindexed-named-object,
1013 // and structure-component) are all syntactically just data-ref.
1014 // What designator boils down to is this:
1015 //  It starts with either a name or a character literal.
1016 //  If it starts with a character literal, it must be a substring.
1017 //  If it starts with a name, it's a sequence of %-separated parts;
1018 //  each part is a name, maybe a (section-subscript-list), and
1019 //  maybe an [image-selector].
1020 //  If it's a substring, it ends with (substring-range).
1021 TYPE_CONTEXT_PARSER("designator"_en_US,
1022     sourced(construct<Designator>(substring) || construct<Designator>(dataRef)))
1023 
1024 constexpr auto percentOrDot{"%"_tok ||
1025     // legacy VAX extension for RECORD field access
1026     extension<LanguageFeature::DECStructures>(
1027         "."_tok / lookAhead(OldStructureComponentName{}))};
1028 
1029 // R902 variable -> designator | function-reference
1030 // This production appears to be left-recursive in the grammar via
1031 //   function-reference ->  procedure-designator -> proc-component-ref ->
1032 //     scalar-variable
1033 // and would be so if we were to allow functions to be called via procedure
1034 // pointer components within derived type results of other function references
1035 // (a reasonable extension, esp. in the case of procedure pointer components
1036 // that are NOPASS).  However, Fortran constrains the use of a variable in a
1037 // proc-component-ref to be a data-ref without coindices (C1027).
1038 // Some array element references will be misrecognized as function references.
1039 constexpr auto noMoreAddressing{!"("_tok >> !"["_tok >> !percentOrDot};
1040 TYPE_CONTEXT_PARSER("variable"_en_US,
1041     construct<Variable>(indirect(functionReference / noMoreAddressing)) ||
1042         construct<Variable>(indirect(designator)))
1043 
1044 // R908 substring -> parent-string ( substring-range )
1045 // R909 parent-string ->
1046 //        scalar-variable-name | array-element | coindexed-named-object |
1047 //        scalar-structure-component | scalar-char-literal-constant |
1048 //        scalar-named-constant
1049 TYPE_PARSER(
1050     construct<Substring>(dataRef, parenthesized(Parser<SubstringRange>{})))
1051 
1052 TYPE_PARSER(construct<CharLiteralConstantSubstring>(
1053     charLiteralConstant, parenthesized(Parser<SubstringRange>{})))
1054 
1055 // R910 substring-range -> [scalar-int-expr] : [scalar-int-expr]
1056 TYPE_PARSER(construct<SubstringRange>(
1057     maybe(scalarIntExpr), ":" >> maybe(scalarIntExpr)))
1058 
1059 // R911 data-ref -> part-ref [% part-ref]...
1060 // R914 coindexed-named-object -> data-ref
1061 // R917 array-element -> data-ref
1062 TYPE_PARSER(
1063     construct<DataRef>(nonemptySeparated(Parser<PartRef>{}, percentOrDot)))
1064 
1065 // R912 part-ref -> part-name [( section-subscript-list )] [image-selector]
1066 TYPE_PARSER(construct<PartRef>(name,
1067     defaulted(
1068         parenthesized(nonemptyList(Parser<SectionSubscript>{})) / !"=>"_tok),
1069     maybe(Parser<ImageSelector>{})))
1070 
1071 // R913 structure-component -> data-ref
1072 // The final part-ref in the data-ref is not allowed to have subscripts.
1073 TYPE_PARSER(construct<StructureComponent>(
1074     construct<DataRef>(some(Parser<PartRef>{} / percentOrDot)), name))
1075 
1076 // R919 subscript -> scalar-int-expr
1077 constexpr auto subscript{scalarIntExpr};
1078 
1079 // R920 section-subscript -> subscript | subscript-triplet | vector-subscript
1080 // R923 vector-subscript -> int-expr
1081 // N.B. The distinction that needs to be made between "subscript" and
1082 // "vector-subscript" is deferred to semantic analysis.
1083 TYPE_PARSER(construct<SectionSubscript>(Parser<SubscriptTriplet>{}) ||
1084     construct<SectionSubscript>(intExpr))
1085 
1086 // R921 subscript-triplet -> [subscript] : [subscript] [: stride]
1087 TYPE_PARSER(construct<SubscriptTriplet>(
1088     maybe(subscript), ":" >> maybe(subscript), maybe(":" >> subscript)))
1089 
1090 // R925 cosubscript -> scalar-int-expr
1091 constexpr auto cosubscript{scalarIntExpr};
1092 
1093 // R924 image-selector ->
1094 //        lbracket cosubscript-list [, image-selector-spec-list] rbracket
1095 TYPE_CONTEXT_PARSER("image selector"_en_US,
1096     construct<ImageSelector>(
1097         "[" >> nonemptyList(cosubscript / lookAhead(space / ",]"_ch)),
1098         defaulted("," >> nonemptyList(Parser<ImageSelectorSpec>{})) / "]"))
1099 
1100 // R926 image-selector-spec ->
1101 //        STAT = stat-variable | TEAM = team-value |
1102 //        TEAM_NUMBER = scalar-int-expr
1103 TYPE_PARSER(construct<ImageSelectorSpec>(construct<ImageSelectorSpec::Stat>(
1104                 "STAT =" >> scalar(integer(indirect(variable))))) ||
1105     construct<ImageSelectorSpec>(construct<TeamValue>("TEAM =" >> teamValue)) ||
1106     construct<ImageSelectorSpec>(construct<ImageSelectorSpec::Team_Number>(
1107         "TEAM_NUMBER =" >> scalarIntExpr)))
1108 
1109 // R927 allocate-stmt ->
1110 //        ALLOCATE ( [type-spec ::] allocation-list [, alloc-opt-list] )
1111 TYPE_CONTEXT_PARSER("ALLOCATE statement"_en_US,
1112     construct<AllocateStmt>("ALLOCATE (" >> maybe(typeSpec / "::"),
1113         nonemptyList(Parser<Allocation>{}),
1114         defaulted("," >> nonemptyList(Parser<AllocOpt>{})) / ")"))
1115 
1116 // R928 alloc-opt ->
1117 //        ERRMSG = errmsg-variable | MOLD = source-expr |
1118 //        SOURCE = source-expr | STAT = stat-variable
1119 // R931 source-expr -> expr
1120 TYPE_PARSER(construct<AllocOpt>(
1121                 construct<AllocOpt::Mold>("MOLD =" >> indirect(expr))) ||
1122     construct<AllocOpt>(
1123         construct<AllocOpt::Source>("SOURCE =" >> indirect(expr))) ||
1124     construct<AllocOpt>(statOrErrmsg))
1125 
1126 // R929 stat-variable -> scalar-int-variable
1127 TYPE_PARSER(construct<StatVariable>(scalar(integer(variable))))
1128 
1129 // R932 allocation ->
1130 //        allocate-object [( allocate-shape-spec-list )]
1131 //        [lbracket allocate-coarray-spec rbracket]
1132 TYPE_PARSER(construct<Allocation>(Parser<AllocateObject>{},
1133     defaulted(parenthesized(nonemptyList(Parser<AllocateShapeSpec>{}))),
1134     maybe(bracketed(Parser<AllocateCoarraySpec>{}))))
1135 
1136 // R933 allocate-object -> variable-name | structure-component
1137 TYPE_PARSER(construct<AllocateObject>(structureComponent) ||
1138     construct<AllocateObject>(name / !"="_tok))
1139 
1140 // R934 allocate-shape-spec -> [lower-bound-expr :] upper-bound-expr
1141 // R938 allocate-coshape-spec -> [lower-bound-expr :] upper-bound-expr
1142 TYPE_PARSER(construct<AllocateShapeSpec>(maybe(boundExpr / ":"), boundExpr))
1143 
1144 // R937 allocate-coarray-spec ->
1145 //      [allocate-coshape-spec-list ,] [lower-bound-expr :] *
1146 TYPE_PARSER(construct<AllocateCoarraySpec>(
1147     defaulted(nonemptyList(Parser<AllocateShapeSpec>{}) / ","),
1148     maybe(boundExpr / ":") / "*"))
1149 
1150 // R939 nullify-stmt -> NULLIFY ( pointer-object-list )
1151 TYPE_CONTEXT_PARSER("NULLIFY statement"_en_US,
1152     "NULLIFY" >> parenthesized(construct<NullifyStmt>(
1153                      nonemptyList(Parser<PointerObject>{}))))
1154 
1155 // R940 pointer-object ->
1156 //        variable-name | structure-component | proc-pointer-name
1157 TYPE_PARSER(construct<PointerObject>(structureComponent) ||
1158     construct<PointerObject>(name))
1159 
1160 // R941 deallocate-stmt ->
1161 //        DEALLOCATE ( allocate-object-list [, dealloc-opt-list] )
1162 TYPE_CONTEXT_PARSER("DEALLOCATE statement"_en_US,
1163     construct<DeallocateStmt>(
1164         "DEALLOCATE (" >> nonemptyList(Parser<AllocateObject>{}),
1165         defaulted("," >> nonemptyList(statOrErrmsg)) / ")"))
1166 
1167 // R942 dealloc-opt -> STAT = stat-variable | ERRMSG = errmsg-variable
1168 // R1165 sync-stat -> STAT = stat-variable | ERRMSG = errmsg-variable
1169 TYPE_PARSER(construct<StatOrErrmsg>("STAT =" >> statVariable) ||
1170     construct<StatOrErrmsg>("ERRMSG =" >> msgVariable))
1171 
1172 // Directives, extensions, and deprecated statements
1173 // !DIR$ IGNORE_TKR [ [(tkr...)] name ]...
1174 // !DIR$ name...
1175 constexpr auto beginDirective{skipStuffBeforeStatement >> "!"_ch};
1176 constexpr auto endDirective{space >> endOfLine};
1177 constexpr auto ignore_tkr{
1178     "DIR$ IGNORE_TKR" >> optionalList(construct<CompilerDirective::IgnoreTKR>(
1179                              defaulted(parenthesized(some("tkr"_ch))), name))};
1180 TYPE_PARSER(beginDirective >>
1181     sourced(construct<CompilerDirective>(ignore_tkr) ||
1182         construct<CompilerDirective>(
1183             "DIR$" >> many(construct<CompilerDirective::NameValue>(name,
1184                           maybe(("="_tok || ":"_tok) >> digitString64))))) /
1185         endDirective)
1186 
1187 TYPE_PARSER(extension<LanguageFeature::CrayPointer>(construct<BasedPointerStmt>(
1188     "POINTER" >> nonemptyList("expected POINTER associations"_err_en_US,
1189                      construct<BasedPointer>("(" >> objectName / ",",
1190                          objectName, maybe(Parser<ArraySpec>{}) / ")")))))
1191 
1192 // Subtle: the name includes the surrounding slashes, which avoids
1193 // clashes with other uses of the name in the same scope.
1194 TYPE_PARSER(construct<StructureStmt>(
1195     "STRUCTURE" >> maybe(sourced("/" >> name / "/")), optionalList(entityDecl)))
1196 
1197 constexpr auto nestedStructureDef{
1198     CONTEXT_PARSER("nested STRUCTURE definition"_en_US,
1199         construct<StructureDef>(statement(NestedStructureStmt{}),
1200             many(Parser<StructureField>{}),
1201             statement(construct<StructureDef::EndStructureStmt>(
1202                 "END STRUCTURE"_tok))))};
1203 
1204 TYPE_PARSER(construct<StructureField>(statement(StructureComponents{})) ||
1205     construct<StructureField>(indirect(Parser<Union>{})) ||
1206     construct<StructureField>(indirect(nestedStructureDef)))
1207 
1208 TYPE_CONTEXT_PARSER("STRUCTURE definition"_en_US,
1209     extension<LanguageFeature::DECStructures>(construct<StructureDef>(
1210         statement(Parser<StructureStmt>{}), many(Parser<StructureField>{}),
1211         statement(
1212             construct<StructureDef::EndStructureStmt>("END STRUCTURE"_tok)))))
1213 
1214 TYPE_CONTEXT_PARSER("UNION definition"_en_US,
1215     construct<Union>(statement(construct<Union::UnionStmt>("UNION"_tok)),
1216         many(Parser<Map>{}),
1217         statement(construct<Union::EndUnionStmt>("END UNION"_tok))))
1218 
1219 TYPE_CONTEXT_PARSER("MAP definition"_en_US,
1220     construct<Map>(statement(construct<Map::MapStmt>("MAP"_tok)),
1221         many(Parser<StructureField>{}),
1222         statement(construct<Map::EndMapStmt>("END MAP"_tok))))
1223 
1224 TYPE_CONTEXT_PARSER("arithmetic IF statement"_en_US,
1225     deprecated<LanguageFeature::ArithmeticIF>(construct<ArithmeticIfStmt>(
1226         "IF" >> parenthesized(expr), label / ",", label / ",", label)))
1227 
1228 TYPE_CONTEXT_PARSER("ASSIGN statement"_en_US,
1229     deprecated<LanguageFeature::Assign>(
1230         construct<AssignStmt>("ASSIGN" >> label, "TO" >> name)))
1231 
1232 TYPE_CONTEXT_PARSER("assigned GOTO statement"_en_US,
1233     deprecated<LanguageFeature::AssignedGOTO>(construct<AssignedGotoStmt>(
1234         "GO TO" >> name,
1235         defaulted(maybe(","_tok) >>
1236             parenthesized(nonemptyList("expected labels"_err_en_US, label))))))
1237 
1238 TYPE_CONTEXT_PARSER("PAUSE statement"_en_US,
1239     deprecated<LanguageFeature::Pause>(
1240         construct<PauseStmt>("PAUSE" >> maybe(Parser<StopCode>{}))))
1241 
1242 // These requirement productions are defined by the Fortran standard but never
1243 // used directly by the grammar:
1244 //   R620 delimiter -> ( | ) | / | [ | ] | (/ | /)
1245 //   R1027 numeric-expr -> expr
1246 //   R1031 int-constant-expr -> int-expr
1247 //   R1221 dtv-type-spec -> TYPE ( derived-type-spec ) |
1248 //           CLASS ( derived-type-spec )
1249 //
1250 // These requirement productions are defined and used, but need not be
1251 // defined independently here in this file:
1252 //   R771 lbracket -> [
1253 //   R772 rbracket -> ]
1254 //
1255 // Further note that:
1256 //   R607 int-constant -> constant
1257 //     is used only once via R844 scalar-int-constant
1258 //   R904 logical-variable -> variable
1259 //     is used only via scalar-logical-variable
1260 //   R906 default-char-variable -> variable
1261 //     is used only via scalar-default-char-variable
1262 //   R907 int-variable -> variable
1263 //     is used only via scalar-int-variable
1264 //   R915 complex-part-designator -> designator % RE | designator % IM
1265 //     %RE and %IM are initially recognized as structure components
1266 //   R916 type-param-inquiry -> designator % type-param-name
1267 //     is occulted by structure component designators
1268 //   R918 array-section ->
1269 //        data-ref [( substring-range )] | complex-part-designator
1270 //     is not used because parsing is not sensitive to rank
1271 //   R1030 default-char-constant-expr -> default-char-expr
1272 //     is only used via scalar-default-char-constant-expr
1273 } // namespace Fortran::parser
1274