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