| 1 | ///////////////////////////////////////////////////////////////////////////////
|
|---|
| 2 | // //
|
|---|
| 3 | // FortranParserRiceCAF.g - grammar extensions for the CAF 2.0 translator //
|
|---|
| 4 | // //
|
|---|
| 5 | // Copyright ((c)) 2008-2011, Rice University. //
|
|---|
| 6 | // All rights reserved. See the file "LICENSE" for details. //
|
|---|
| 7 | // //
|
|---|
| 8 | ///////////////////////////////////////////////////////////////////////////////
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 | parser grammar FortranParserRiceCAF;
|
|---|
| 12 |
|
|---|
| 13 | options {
|
|---|
| 14 | language=Java;
|
|---|
| 15 | superClass=AbstractFortranParser;
|
|---|
| 16 | tokenVocab=FortranLexer;
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | import FortranParser08;
|
|---|
| 20 |
|
|---|
| 21 | /* ANTLR 3.5 doesn't allow redefinition of headers in composite grammars.
|
|---|
| 22 | Our solution for this is: add the header (package, imported package)
|
|---|
| 23 | to the generated java file in ant.
|
|---|
| 24 | @header {
|
|---|
| 25 | package dev.civl.abc.front.fortran.parse;
|
|---|
| 26 | import dev.civl.abc.front.fortran.parse.IActionEnums;
|
|---|
| 27 | }*/
|
|---|
| 28 |
|
|---|
| 29 | @members {
|
|---|
| 30 | int gCount1;
|
|---|
| 31 | int gCount2;
|
|---|
| 32 |
|
|---|
| 33 | public void initialize(String[] args, String kind, String filename, String path) {
|
|---|
| 34 | action = FortranParserActionFactory.newAction(args, this, kind, filename);
|
|---|
| 35 |
|
|---|
| 36 | initialize(this, action, filename, path);
|
|---|
| 37 | gFortranParser08.initialize(this, action, filename, path);
|
|---|
| 38 |
|
|---|
| 39 | action.start_of_file(filename, path);
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | public void eofAction() {
|
|---|
| 43 | gFortranParser08.eofAction();
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | } // end members
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | /**
|
|---|
| 50 | * Section/Clause 1: Overview
|
|---|
| 51 | */
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 | /*
|
|---|
| 55 | * Section/Clause 2: Fortran concepts
|
|---|
| 56 | */
|
|---|
| 57 |
|
|---|
| 58 | /*
|
|---|
| 59 | * R204 specification-part
|
|---|
| 60 | * is [ use-stmt ] ...
|
|---|
| 61 | * [ import-stmt ] ...
|
|---|
| 62 | * [ implicit-part ]
|
|---|
| 63 | * [ declaration-construct ] ...
|
|---|
| 64 | */
|
|---|
| 65 |
|
|---|
| 66 | /*
|
|---|
| 67 | * C201-F08 (R208) An execution-part shall not contain an end-function-stmt,
|
|---|
| 68 | * end-mp-subprogram-stmt, end-program-stmt, or end-subroutine-stmt.
|
|---|
| 69 | */
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 | ////////////
|
|---|
| 73 | // R204-F08
|
|---|
| 74 | //
|
|---|
| 75 | specification_part
|
|---|
| 76 | @init{int numUseStmts=0; int numImportStmts=0; gCount1=0; gCount2=0;}
|
|---|
| 77 | : ( use_stmt {numUseStmts++;} )*
|
|---|
| 78 | ( import_stmt {numImportStmts++;} )*
|
|---|
| 79 | implicit_part_recursion // making nonoptional with predicates fixes ambiguity
|
|---|
| 80 | ( declaration_construct {gCount2++;} )*
|
|---|
| 81 | {action.specification_part(numUseStmts, numImportStmts, gCount1, gCount2);}
|
|---|
| 82 | ;
|
|---|
| 83 |
|
|---|
| 84 | /*
|
|---|
| 85 | * R205-F08 implicit-part is [ implicit-part-stmt ] ...
|
|---|
| 86 | * implicit-stmt
|
|---|
| 87 | */
|
|---|
| 88 |
|
|---|
| 89 | /*
|
|---|
| 90 | * R206-F08 implicit-part-stmt is implicit-stmt
|
|---|
| 91 | * or parameter-stmt
|
|---|
| 92 | * or format-stmt
|
|---|
| 93 | * or entry-stmt
|
|---|
| 94 | */
|
|---|
| 95 |
|
|---|
| 96 | ////////////
|
|---|
| 97 | // R205-F08
|
|---|
| 98 | // R206-F08 combined
|
|---|
| 99 | //
|
|---|
| 100 | implicit_part_recursion
|
|---|
| 101 | : ((label)? T_IMPLICIT) => implicit_stmt {gCount1++;} implicit_part_recursion
|
|---|
| 102 | | ((label)? T_PARAMETER) => parameter_stmt {gCount2++;} implicit_part_recursion
|
|---|
| 103 | | ((label)? T_FORMAT) => format_stmt {gCount2++;} implicit_part_recursion
|
|---|
| 104 | | ((label)? T_ENTRY) => entry_stmt {gCount2++;} implicit_part_recursion
|
|---|
| 105 | | // empty
|
|---|
| 106 | ;
|
|---|
| 107 |
|
|---|
| 108 | /*
|
|---|
| 109 | * R213-F08 executable-construct
|
|---|
| 110 | * is action-stmt
|
|---|
| 111 | * or associate-construct
|
|---|
| 112 | * or block-construct // NEW_TO_2008
|
|---|
| 113 | * or case-construct
|
|---|
| 114 | * or critical-construct // NEW_TO_2008
|
|---|
| 115 | * or do-construct
|
|---|
| 116 | * or forall-construct
|
|---|
| 117 | * or if-construct
|
|---|
| 118 | * or select-type-construct
|
|---|
| 119 | * or where-construct
|
|---|
| 120 | */
|
|---|
| 121 |
|
|---|
| 122 | ////////////
|
|---|
| 123 | // R213-F08
|
|---|
| 124 | //
|
|---|
| 125 | executable_construct
|
|---|
| 126 | @after {action.executable_construct();}
|
|---|
| 127 | : action_stmt
|
|---|
| 128 | | associate_construct
|
|---|
| 129 | | block_construct // NEW_TO_2008
|
|---|
| 130 | | case_construct
|
|---|
| 131 | | critical_construct // NEW_TO_2008
|
|---|
| 132 | | do_construct
|
|---|
| 133 | | forall_construct
|
|---|
| 134 | | if_construct
|
|---|
| 135 | | select_type_construct
|
|---|
| 136 | | where_construct
|
|---|
| 137 | | rice_with_team_construct
|
|---|
| 138 | | rice_finish_construct
|
|---|
| 139 | | rice_spawn_stmt
|
|---|
| 140 | ;
|
|---|
| 141 |
|
|---|
| 142 | /*
|
|---|
| 143 | * R214-F08 action-stmt
|
|---|
| 144 | * is allocate-stmt
|
|---|
| 145 | * or assignment-stmt
|
|---|
| 146 | * or backspace-stmt
|
|---|
| 147 | * or call-stmt
|
|---|
| 148 | * or close-stmt
|
|---|
| 149 | * or continue-stmt
|
|---|
| 150 | * or cycle-stmt
|
|---|
| 151 | * or deallocate-stmt
|
|---|
| 152 | * or end-function-stmt
|
|---|
| 153 | * or end-mp-subprogram-stmt // NEW_TO_2008
|
|---|
| 154 | * or end-program-stmt
|
|---|
| 155 | * or end-subroutine-stmt
|
|---|
| 156 | * or endfile-stmt
|
|---|
| 157 | * or errorstop-stmt // NEW_TO_2008
|
|---|
| 158 | * or exit-stmt
|
|---|
| 159 | * or flush-stmt
|
|---|
| 160 | * or forall-stmt
|
|---|
| 161 | * or goto-stmt
|
|---|
| 162 | * or if-stmt
|
|---|
| 163 | * or inquire-stmt
|
|---|
| 164 | * or lock-stmt // NEW_TO_2008
|
|---|
| 165 | * or nullify-stmt
|
|---|
| 166 | * or open-stmt
|
|---|
| 167 | * or pointer-assignment-stmt
|
|---|
| 168 | * or print-stmt
|
|---|
| 169 | * or read-stmt
|
|---|
| 170 | * or return-stmt
|
|---|
| 171 | * or rewind-stmt
|
|---|
| 172 | * or stop-stmt
|
|---|
| 173 | * or sync-all-stmt // NEW_TO_2008
|
|---|
| 174 | * or sync-images-stmt // NEW_TO_2008
|
|---|
| 175 | * or sync-memory-stmt // NEW_TO_2008
|
|---|
| 176 | * or unlock-stmt // NEW_TO_2008
|
|---|
| 177 | * or wait-stmt
|
|---|
| 178 | * or where-stmt
|
|---|
| 179 | * or write-stmt
|
|---|
| 180 | * or arithmetic-if-stmt
|
|---|
| 181 | * or computed-goto-stmt
|
|---|
| 182 | */
|
|---|
| 183 |
|
|---|
| 184 | ////////////
|
|---|
| 185 | // R214-F08
|
|---|
| 186 | //
|
|---|
| 187 | // C201-F08 (R208) An execution-part shall not contain an end-function-stmt,
|
|---|
| 188 | // end-mp-subprogram-stmt, end-program-stmt, or end-subroutine-stmt.
|
|---|
| 189 | //
|
|---|
| 190 | // (But they can be in a branch target statement, which is not in the grammar,
|
|---|
| 191 | // so the end-xxx-stmts deleted.)
|
|---|
| 192 | // TODO continue-stmt is ambiguous with same in end-do, check for label and if
|
|---|
| 193 | // label matches do-stmt label, then match end-do there
|
|---|
| 194 | // the original generated rules do not allow the label, so add (label)?
|
|---|
| 195 | //
|
|---|
| 196 | action_stmt
|
|---|
| 197 | @after {action.action_stmt();}
|
|---|
| 198 | // Removed backtracking by inserting extra tokens in the stream by the prepass
|
|---|
| 199 | // that signals whether we have an assignment-stmt, a pointer-assignment-stmt,
|
|---|
| 200 | // or an arithmetic if. This approach may work for other parts of backtracking
|
|---|
| 201 | // also. However, need to see if there is a way to define tokens w/o defining
|
|---|
| 202 | // them in the lexer so that the lexer doesn't have to add them to it's parsing.
|
|---|
| 203 | // 02.05.07
|
|---|
| 204 | : allocate_stmt
|
|---|
| 205 | | assignment_stmt
|
|---|
| 206 | | backspace_stmt
|
|---|
| 207 | | call_stmt
|
|---|
| 208 | | close_stmt
|
|---|
| 209 | | continue_stmt
|
|---|
| 210 | | cycle_stmt
|
|---|
| 211 | | deallocate_stmt
|
|---|
| 212 | //////////
|
|---|
| 213 | // These end functions are not needed because the initiating constructs are called
|
|---|
| 214 | // explicitly to avoid ambiguities.
|
|---|
| 215 | // | end_function_stmt
|
|---|
| 216 | // | end_mp_subprogram_stmt // NEW_TO_2008
|
|---|
| 217 | // | end_program_stmt
|
|---|
| 218 | // | end_subroutine_stmt
|
|---|
| 219 | | endfile_stmt
|
|---|
| 220 | | errorstop_stmt // NEW_TO_2008
|
|---|
| 221 | | exit_stmt
|
|---|
| 222 | | flush_stmt
|
|---|
| 223 | | forall_stmt
|
|---|
| 224 | | goto_stmt
|
|---|
| 225 | | if_stmt
|
|---|
| 226 | | inquire_stmt
|
|---|
| 227 | | lock_stmt // NEW_TO_2008
|
|---|
| 228 | | nullify_stmt
|
|---|
| 229 | | open_stmt
|
|---|
| 230 | | pointer_assignment_stmt
|
|---|
| 231 | | print_stmt
|
|---|
| 232 | | read_stmt
|
|---|
| 233 | | return_stmt
|
|---|
| 234 | | rewind_stmt
|
|---|
| 235 | | stop_stmt
|
|---|
| 236 | | sync_all_stmt // NEW_TO_2008
|
|---|
| 237 | | sync_images_stmt // NEW_TO_2008
|
|---|
| 238 | | sync_memory_stmt // NEW_TO_2008
|
|---|
| 239 | | unlock_stmt // NEW_TO_2008
|
|---|
| 240 | | wait_stmt
|
|---|
| 241 | | where_stmt
|
|---|
| 242 | | write_stmt
|
|---|
| 243 | | arithmetic_if_stmt
|
|---|
| 244 | | computed_goto_stmt
|
|---|
| 245 | | assign_stmt // ADDED?
|
|---|
| 246 | | assigned_goto_stmt // ADDED?
|
|---|
| 247 | | pause_stmt // ADDED?
|
|---|
| 248 | ;
|
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 | /**
|
|---|
| 252 | * Section/Clause 3: Lexical tokens and source form
|
|---|
| 253 | */
|
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 | /*
|
|---|
| 257 | * Section/Clause 4: Types
|
|---|
| 258 | */
|
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 | /*
|
|---|
| 262 | * Section/Clause 5: Attribute declarations and specifications
|
|---|
| 263 | */
|
|---|
| 264 |
|
|---|
| 265 | // R501
|
|---|
| 266 | type_declaration_stmt
|
|---|
| 267 | @init {Token lbl = null; int numAttrSpecs = 0;}
|
|---|
| 268 | @after{checkForInclude();}
|
|---|
| 269 | : (label {lbl=$label.tk;})? rice_declaration_type_spec
|
|---|
| 270 | ( (T_COMMA attr_spec {numAttrSpecs += 1;})* T_COLON_COLON )?
|
|---|
| 271 | entity_decl_list end_of_stmt
|
|---|
| 272 | { action.type_declaration_stmt(lbl, numAttrSpecs, $end_of_stmt.tk); }
|
|---|
| 273 | ;
|
|---|
| 274 |
|
|---|
| 275 | // Copointer extensions to rules R503(F03)/R502(F08), R441(F03)/R437(F08), R1213(F080)
|
|---|
| 276 | // Note that in F08 the 'TARGET' attribute can only appear in 'attr-spec's,
|
|---|
| 277 | // so we make the same decision for our new 'COTARGET' attribute.
|
|---|
| 278 | attr_spec_extension
|
|---|
| 279 | : T_COPOINTER
|
|---|
| 280 | {action.attr_spec($T_COPOINTER, IActionEnums.AttrSpec_COPOINTER);}
|
|---|
| 281 | | T_COTARGET
|
|---|
| 282 | {action.attr_spec($T_COTARGET, IActionEnums.AttrSpec_COTARGET);}
|
|---|
| 283 | ;
|
|---|
| 284 | component_attr_spec_extension
|
|---|
| 285 | : T_COPOINTER
|
|---|
| 286 | {action.attr_spec($T_COPOINTER, IActionEnums.AttrSpec_COPOINTER);}
|
|---|
| 287 | ;
|
|---|
| 288 | proc_attr_spec_extension
|
|---|
| 289 | : T_COPOINTER
|
|---|
| 290 | {action.attr_spec($T_COPOINTER, IActionEnums.AttrSpec_COPOINTER);}
|
|---|
| 291 | ;
|
|---|
| 292 |
|
|---|
| 293 |
|
|---|
| 294 | /*
|
|---|
| 295 | * R510-F08 deferred-coshape-spec
|
|---|
| 296 | * is :
|
|---|
| 297 | */
|
|---|
| 298 |
|
|---|
| 299 | ////////////
|
|---|
| 300 | // R510-F08
|
|---|
| 301 | //
|
|---|
| 302 | // deferred_coshape_spec is replaced by array_spec (see R509-F08)
|
|---|
| 303 | //
|
|---|
| 304 |
|
|---|
| 305 | /*
|
|---|
| 306 | * R511-08 explicit-coshape-spec
|
|---|
| 307 | * is [ [ lower-cobound : ] upper-cobound, ]...
|
|---|
| 308 | * [ lower-cobound : ] *
|
|---|
| 309 | */
|
|---|
| 310 |
|
|---|
| 311 | ////////////
|
|---|
| 312 | // R511-F08
|
|---|
| 313 | //
|
|---|
| 314 | // explicit_coshape_spec is replaced by array_spec (see R509-F08)
|
|---|
| 315 | //
|
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 | /**
|
|---|
| 319 | * Section/Clause 6: Use of data objects
|
|---|
| 320 | */
|
|---|
| 321 |
|
|---|
| 322 |
|
|---|
| 323 | ////////////
|
|---|
| 324 | // Rice extension for copointer dereferencing
|
|---|
| 325 | ////////////
|
|---|
| 326 |
|
|---|
| 327 | // This rule is written so that the 'part_ref' action's signature doesn't change between F08 and CAF2.
|
|---|
| 328 | // and so the action sequence is not quite natural when a co-deref-op is present.
|
|---|
| 329 | part_ref
|
|---|
| 330 | @init{boolean hasSSL = false; boolean hasImageSelector = false;}
|
|---|
| 331 | : (T_IDENT T_LPAREN) =>
|
|---|
| 332 | T_IDENT T_LPAREN section_subscript_list T_RPAREN
|
|---|
| 333 | (image_selector {hasImageSelector=true;})?
|
|---|
| 334 | {hasSSL=true; action.part_ref($T_IDENT, hasSSL, hasImageSelector);}
|
|---|
| 335 | | (T_IDENT T_LBRACKET T_RBRACKET ) =>
|
|---|
| 336 | T_IDENT T_LBRACKET T_RBRACKET
|
|---|
| 337 | ( (T_LPAREN) => T_LPAREN section_subscript_list T_RPAREN {hasSSL=true;} )?
|
|---|
| 338 | (image_selector {hasImageSelector=true;})?
|
|---|
| 339 | {action.part_ref($T_IDENT, hasSSL, hasImageSelector); action.rice_co_dereference_op($T_LBRACKET, $T_RBRACKET);}
|
|---|
| 340 | | (T_IDENT T_LBRACKET) =>
|
|---|
| 341 | T_IDENT image_selector
|
|---|
| 342 | {hasImageSelector=true; action.part_ref($T_IDENT, hasSSL, hasImageSelector);}
|
|---|
| 343 | | T_IDENT
|
|---|
| 344 | {action.part_ref($T_IDENT, hasSSL, hasImageSelector);}
|
|---|
| 345 | ;
|
|---|
| 346 |
|
|---|
| 347 |
|
|---|
| 348 | /* alternate syntax for co-dereferencing
|
|---|
| 349 |
|
|---|
| 350 | part_ref
|
|---|
| 351 | @init{boolean hasCoDeref = false; }
|
|---|
| 352 | : part_ref (rice_co_dereference_op {hasCoDeref=true;})?
|
|---|
| 353 | {action.part_ref(hasCoDeref);}
|
|---|
| 354 | ;
|
|---|
| 355 |
|
|---|
| 356 | rice_co_dereference_op
|
|---|
| 357 | : T_LBRACKET T_RBRACKET
|
|---|
| 358 | {action.rice_co_dereference_op($T_LBRACKET, $T_RBRACKET);}
|
|---|
| 359 | ;
|
|---|
| 360 | */
|
|---|
| 361 |
|
|---|
| 362 |
|
|---|
| 363 | /**
|
|---|
| 364 | * R620-F08 section-subscript
|
|---|
| 365 | * is subscript
|
|---|
| 366 | * or subscript-triplet
|
|---|
| 367 | * or vector-subscript
|
|---|
| 368 | */
|
|---|
| 369 |
|
|---|
| 370 | ////////////
|
|---|
| 371 | // R620-F08, R619-F03
|
|---|
| 372 | //
|
|---|
| 373 | // expr inlined for subscript, vector_subscript, and stride (thus deleted option 3)
|
|---|
| 374 | // refactored first optional expr from subscript_triplet modified to also match
|
|---|
| 375 | // actual_arg_spec_list to reduce ambiguities and need for backtracking
|
|---|
| 376 | section_subscript returns [boolean isEmpty]
|
|---|
| 377 | @init {
|
|---|
| 378 | boolean hasLowerBounds = false;
|
|---|
| 379 | boolean hasUpperBounds = false;
|
|---|
| 380 | boolean hasStride = false;
|
|---|
| 381 | boolean hasExpr = false;
|
|---|
| 382 | }
|
|---|
| 383 | : expr section_subscript_ambiguous
|
|---|
| 384 | | T_COLON (expr {hasUpperBounds=true;})? (T_COLON expr {hasStride=true;})?
|
|---|
| 385 | { action.section_subscript(hasLowerBounds, hasUpperBounds, hasStride, false); }
|
|---|
| 386 | | T_COLON_COLON expr
|
|---|
| 387 | { hasStride=true;
|
|---|
| 388 | action.section_subscript(hasLowerBounds, hasUpperBounds, hasStride, false);}
|
|---|
| 389 | | T_IDENT T_EQUALS expr // could be an actual-arg, see R1220
|
|---|
| 390 | { hasExpr=true; action.actual_arg(hasExpr, null);
|
|---|
| 391 | action.actual_arg_spec($T_IDENT); }
|
|---|
| 392 | | T_IDENT T_EQUALS T_ASTERISK label // could be an actual-arg, see R1220
|
|---|
| 393 | { action.actual_arg(hasExpr, $label.tk); action.actual_arg_spec($T_IDENT); }
|
|---|
| 394 | | T_ASTERISK label /* could be an actual-arg, see R1220 */
|
|---|
| 395 | { action.actual_arg(hasExpr, $label.tk); action.actual_arg_spec(null); }
|
|---|
| 396 | | { isEmpty = true; /* empty could be an actual-arg, see R1220 */ }
|
|---|
| 397 | ;
|
|---|
| 398 |
|
|---|
| 399 | section_subscript_ambiguous
|
|---|
| 400 | @init {
|
|---|
| 401 | boolean hasLowerBound = true;
|
|---|
| 402 | boolean hasUpperBound = false;
|
|---|
| 403 | boolean hasStride = false;
|
|---|
| 404 | boolean isAmbiguous = false;
|
|---|
| 405 | }
|
|---|
| 406 | : T_COLON (expr {hasUpperBound=true;})? (T_COLON expr {hasStride=true;})?
|
|---|
| 407 | { action.section_subscript(hasLowerBound, hasUpperBound, hasStride, isAmbiguous);}
|
|---|
| 408 | // this alternative is necessary because if alt1 above has no expr
|
|---|
| 409 | // following the first : and there is the optional second : with no
|
|---|
| 410 | // WS between the two, the lexer will make a T_COLON_COLON token
|
|---|
| 411 | // instead of two T_COLON tokens. in this case, the second expr is
|
|---|
| 412 | // required. for an example, see J3/04-007, Note 7.44.
|
|---|
| 413 | | T_COLON_COLON expr
|
|---|
| 414 | { hasStride=true;
|
|---|
| 415 | action.section_subscript(hasLowerBound, hasUpperBound, hasStride, isAmbiguous);}
|
|---|
| 416 | | { /* empty, could be an actual-arg, see R1220 */
|
|---|
| 417 | isAmbiguous=true;
|
|---|
| 418 | action.section_subscript(hasLowerBound, hasUpperBound, hasStride, isAmbiguous);
|
|---|
| 419 | }
|
|---|
| 420 | ;
|
|---|
| 421 |
|
|---|
| 422 |
|
|---|
| 423 |
|
|---|
| 424 | /**
|
|---|
| 425 | * R620-F08 section-subscript
|
|---|
| 426 | * is subscript
|
|---|
| 427 | * or subscript-triplet
|
|---|
| 428 | * or vector-subscript
|
|---|
| 429 | */
|
|---|
| 430 |
|
|---|
| 431 | ////////////
|
|---|
| 432 | // R620-F08 list
|
|---|
| 433 | //
|
|---|
| 434 | // This rule must be kept here with part-ref, otherwise parsing errors will occur.
|
|---|
| 435 | // It is unknown why this happens.
|
|---|
| 436 | //
|
|---|
| 437 | section_subscript_list
|
|---|
| 438 | @init{int count = 0;}
|
|---|
| 439 | : { action.section_subscript_list__begin(); }
|
|---|
| 440 | isEmpty=section_subscript
|
|---|
| 441 | {
|
|---|
| 442 | if (isEmpty == false) count += 1;
|
|---|
| 443 | }
|
|---|
| 444 | (T_COMMA section_subscript {count += 1;})*
|
|---|
| 445 | { action.section_subscript_list(count); }
|
|---|
| 446 | ;
|
|---|
| 447 |
|
|---|
| 448 | /*
|
|---|
| 449 | * R624-F08 image-selector
|
|---|
| 450 | * is lbracket cosubscript-list rbracket
|
|---|
| 451 | */
|
|---|
| 452 |
|
|---|
| 453 | ////////////
|
|---|
| 454 | // R624-F08
|
|---|
| 455 | //
|
|---|
| 456 | image_selector
|
|---|
| 457 | : T_LBRACKET cosubscript_list T_RBRACKET
|
|---|
| 458 | {action.image_selector($T_LBRACKET, $T_RBRACKET);}
|
|---|
| 459 | ;
|
|---|
| 460 |
|
|---|
| 461 |
|
|---|
| 462 | /*
|
|---|
| 463 | * R631-08 allocation
|
|---|
| 464 | * is allocate-object [ ( allocate-shape-spec-list ) ]
|
|---|
| 465 | * [ lbracket allocate-coarray-spec rbracket ] // NEW_TO_2008
|
|---|
| 466 | */
|
|---|
| 467 |
|
|---|
| 468 | ////////////
|
|---|
| 469 | // R631-F08, R628-F03
|
|---|
| 470 | //
|
|---|
| 471 | allocation
|
|---|
| 472 | @init{boolean hasAllocateShapeSpecList = false; boolean hasAllocateCoarraySpec = false;}
|
|---|
| 473 | : allocate_object
|
|---|
| 474 | ( T_LPAREN allocate_shape_spec_list {System.out.println("------> ()"); hasAllocateShapeSpecList=true;} T_RPAREN )?
|
|---|
| 475 | ( T_LBRACKET rice_allocate_coarray_spec {hasAllocateCoarraySpec=true;} T_RBRACKET )?
|
|---|
| 476 | {action.allocation(hasAllocateShapeSpecList, hasAllocateCoarraySpec);}
|
|---|
| 477 | ;
|
|---|
| 478 |
|
|---|
| 479 |
|
|---|
| 480 |
|
|---|
| 481 | /**
|
|---|
| 482 | * R632-F08 allocate-object
|
|---|
| 483 | * is variable-name
|
|---|
| 484 | * structure-component
|
|---|
| 485 | */
|
|---|
| 486 |
|
|---|
| 487 | ////////////
|
|---|
| 488 | // R636-F08, R629-F03
|
|---|
| 489 | //
|
|---|
| 490 | // C644 (R632) An allocate-object shall not be a coindexed object.
|
|---|
| 491 | //
|
|---|
| 492 | // T_IDENT inlined for variable_name
|
|---|
| 493 | // data_ref inlined for structure_component
|
|---|
| 494 | // data_ref isa T_IDENT so T_IDENT deleted
|
|---|
| 495 | // data_ref inlined and part_ref_no_image_selector called directly
|
|---|
| 496 | //
|
|---|
| 497 | allocate_object
|
|---|
| 498 | @init{int numPartRefs = 0;}
|
|---|
| 499 | : /* part_ref_no_image_selector {numPartRefs += 1;} */
|
|---|
| 500 | /* (T_PERCENT part_ref_no_image_selector {numPartRefs += 1;})* */
|
|---|
| 501 | part_ref {numPartRefs += 1;}
|
|---|
| 502 | (T_PERCENT part_ref {numPartRefs += 1;})*
|
|---|
| 503 | {action.data_ref(numPartRefs); action.allocate_object();}
|
|---|
| 504 | ;
|
|---|
| 505 |
|
|---|
| 506 | /*
|
|---|
| 507 | * R636-F08 allocate-coarray-spec
|
|---|
| 508 | * is [ allocate-coshape-spec-list , ] [ lower-bound-expr : ] *
|
|---|
| 509 | */
|
|---|
| 510 |
|
|---|
| 511 | ////////////
|
|---|
| 512 | // R636-F08
|
|---|
| 513 | //
|
|---|
| 514 | allocate_coarray_spec
|
|---|
| 515 | options{k=3;}
|
|---|
| 516 | @after {action.allocate_coarray_spec();}
|
|---|
| 517 | : (T_ASTERISK) => T_ASTERISK
|
|---|
| 518 | | (expr T_COLON T_ASTERISK) => expr T_COLON T_ASTERISK
|
|---|
| 519 | //PUTBACK | allocate_coshape_spec_list T_COMMA ( expr T_COLON )? T_ASTERISK
|
|---|
| 520 | // | T_ASTERISK // TESTING
|
|---|
| 521 | ;
|
|---|
| 522 |
|
|---|
| 523 | //R632
|
|---|
| 524 | // Laksono (2010.07.08): hack verson of allocate_object. It has to be data_ref instead
|
|---|
| 525 | /*allocate_object
|
|---|
| 526 | @init{int numPartRefs = 0;}
|
|---|
| 527 | : T_IDENT {numPartRefs += 1;}
|
|---|
| 528 | (T_PERCENT T_IDENT {numPartRefs += 1;})?
|
|---|
| 529 | {action.data_ref(numPartRefs);}
|
|---|
| 530 | ;
|
|---|
| 531 | */
|
|---|
| 532 |
|
|---|
| 533 |
|
|---|
| 534 | /**
|
|---|
| 535 | * Section/Clause 8: Execution control
|
|---|
| 536 | */
|
|---|
| 537 |
|
|---|
| 538 |
|
|---|
| 539 | /*
|
|---|
| 540 | * R866-F08 lock-variable
|
|---|
| 541 | * is scalar-variable
|
|---|
| 542 | */
|
|---|
| 543 |
|
|---|
| 544 | ////////////
|
|---|
| 545 | // R866-F08
|
|---|
| 546 | //
|
|---|
| 547 | lock_variable
|
|---|
| 548 | : scalar_variable
|
|---|
| 549 | { action.lock_variable(); }
|
|---|
| 550 | ;
|
|---|
| 551 |
|
|---|
| 552 |
|
|---|
| 553 | /*
|
|---|
| 554 | * Section/Clause 11: Program units
|
|---|
| 555 | */
|
|---|
| 556 |
|
|---|
| 557 |
|
|---|
| 558 |
|
|---|
| 559 | //----------------------------------------------------------------------------
|
|---|
| 560 | // RICE CO-ARRAY FORTRAN RULES
|
|---|
| 561 | // ---------------------------
|
|---|
| 562 | // All Rice's rules and actions will prefixed with "rice_" keyword
|
|---|
| 563 | //----------------------------------------------------------------------------
|
|---|
| 564 |
|
|---|
| 565 | rice_allocate_coarray_spec:
|
|---|
| 566 | T_AT T_IDENT
|
|---|
| 567 | { action.rice_allocate_coarray_spec(1,$T_IDENT); }
|
|---|
| 568 | |
|
|---|
| 569 | T_AT
|
|---|
| 570 | { action.rice_allocate_coarray_spec(-1,null); }
|
|---|
| 571 | |
|
|---|
| 572 | // TEMPORARY: accept old empty version for legacy code's allocate-stmts
|
|---|
| 573 | /* empty */
|
|---|
| 574 | { action.rice_allocate_coarray_spec(-1,null); }
|
|---|
| 575 | ;
|
|---|
| 576 |
|
|---|
| 577 | rice_with_team_construct
|
|---|
| 578 | : rice_with_team_stmt block rice_end_with_team_stmt
|
|---|
| 579 | ;
|
|---|
| 580 |
|
|---|
| 581 | rice_with_team_stmt
|
|---|
| 582 | @init{Token lbl = null;}
|
|---|
| 583 | :
|
|---|
| 584 | (label {lbl=$label.tk;})?
|
|---|
| 585 | (T_WITHTEAM | T_WITH T_TEAM) T_IDENT
|
|---|
| 586 | end_of_stmt
|
|---|
| 587 | { action.rice_co_with_team_stmt(lbl, $T_IDENT); }
|
|---|
| 588 | ;
|
|---|
| 589 |
|
|---|
| 590 | rice_end_with_team_stmt
|
|---|
| 591 | @init{Token lbl = null; Token id = null;}
|
|---|
| 592 | :
|
|---|
| 593 | (label {lbl=$label.tk;})?
|
|---|
| 594 | T_END (T_WITHTEAM | T_WITH T_TEAM) (T_IDENT {id=$T_IDENT;})?
|
|---|
| 595 | end_of_stmt
|
|---|
| 596 | {action.rice_end_with_team_stmt(lbl, id, $end_of_stmt.tk);}
|
|---|
| 597 | ;
|
|---|
| 598 |
|
|---|
| 599 | // R403 (rice version)
|
|---|
| 600 | rice_intrinsic_type_spec
|
|---|
| 601 | :
|
|---|
| 602 | T_LOCKSET {action.intrinsic_type_spec($T_LOCKSET, null,
|
|---|
| 603 | IActionEnums.IntrinsicTypeSpec_LOCKSET,
|
|---|
| 604 | false);}
|
|---|
| 605 | | T_LOCK {action.intrinsic_type_spec($T_LOCK, null,
|
|---|
| 606 | IActionEnums.IntrinsicTypeSpec_LOCK,
|
|---|
| 607 | false);}
|
|---|
| 608 | | T_TEAM {action.intrinsic_type_spec($T_TEAM, null,
|
|---|
| 609 | IActionEnums.IntrinsicTypeSpec_TEAM,
|
|---|
| 610 | false);}
|
|---|
| 611 | | T_TOPOLOGY {action.intrinsic_type_spec($T_TOPOLOGY, null,
|
|---|
| 612 | IActionEnums.IntrinsicTypeSpec_TOPOLOGY,
|
|---|
| 613 | false);}
|
|---|
| 614 | | T_EVENT {action.intrinsic_type_spec($T_EVENT, null,
|
|---|
| 615 | IActionEnums.IntrinsicTypeSpec_EVENT,
|
|---|
| 616 | false);}
|
|---|
| 617 | ;
|
|---|
| 618 |
|
|---|
| 619 |
|
|---|
| 620 | // R502 (rice version)
|
|---|
| 621 | rice_declaration_type_spec
|
|---|
| 622 | : // original F03 rule
|
|---|
| 623 | declaration_type_spec
|
|---|
| 624 | | // rice CAF 2.0 rules
|
|---|
| 625 | rice_intrinsic_type_spec
|
|---|
| 626 | { action.declaration_type_spec(null,
|
|---|
| 627 | IActionEnums.DeclarationTypeSpec_INTRINSIC); }
|
|---|
| 628 | ;
|
|---|
| 629 |
|
|---|
| 630 |
|
|---|
| 631 | /*
|
|---|
| 632 | * R625-F08 cosubscript
|
|---|
| 633 | * is scalar-int-expr
|
|---|
| 634 | */
|
|---|
| 635 |
|
|---|
| 636 | ////////////
|
|---|
| 637 | // R625-F08
|
|---|
| 638 | //
|
|---|
| 639 | cosubscript
|
|---|
| 640 | : expr
|
|---|
| 641 | ;
|
|---|
| 642 |
|
|---|
| 643 | cosubscript_list
|
|---|
| 644 | @init{
|
|---|
| 645 | int count=0;
|
|---|
| 646 | Token idTeam=null;
|
|---|
| 647 | }
|
|---|
| 648 | : {action.cosubscript_list__begin();}
|
|---|
| 649 | cosubscript {count++;} ( T_COMMA cosubscript {count++;} )*
|
|---|
| 650 | (T_AT T_IDENT {idTeam=$T_IDENT;})?
|
|---|
| 651 | {
|
|---|
| 652 | action.cosubscript_list(count, idTeam);
|
|---|
| 653 | }
|
|---|
| 654 | ;
|
|---|
| 655 |
|
|---|
| 656 |
|
|---|
| 657 | rice_finish_construct
|
|---|
| 658 | : rice_finish_stmt block rice_end_finish_stmt
|
|---|
| 659 | ;
|
|---|
| 660 |
|
|---|
| 661 |
|
|---|
| 662 | rice_finish_stmt
|
|---|
| 663 | @init{Token lbl = null; Token idTeam = null;}
|
|---|
| 664 | :
|
|---|
| 665 | (label {lbl=$label.tk;})?
|
|---|
| 666 | T_FINISH ( T_IDENT {idTeam=$T_IDENT;} )?
|
|---|
| 667 | end_of_stmt
|
|---|
| 668 | {
|
|---|
| 669 | action.rice_finish_stmt(lbl, idTeam, $end_of_stmt.tk);
|
|---|
| 670 | }
|
|---|
| 671 | ;
|
|---|
| 672 |
|
|---|
| 673 |
|
|---|
| 674 | rice_end_finish_stmt
|
|---|
| 675 | @init{Token lbl = null;}
|
|---|
| 676 | :
|
|---|
| 677 | (label {lbl=$label.tk;})?
|
|---|
| 678 | T_END T_FINISH
|
|---|
| 679 | end_of_stmt
|
|---|
| 680 | {
|
|---|
| 681 | action.rice_end_finish_stmt(lbl, $end_of_stmt.tk);
|
|---|
| 682 | }
|
|---|
| 683 | ;
|
|---|
| 684 |
|
|---|
| 685 |
|
|---|
| 686 | rice_spawn_stmt
|
|---|
| 687 | @init {Token lbl = null; boolean hasEvent = false;}
|
|---|
| 688 | @after{checkForInclude();}
|
|---|
| 689 | :
|
|---|
| 690 | (label {lbl=$label.tk;})?
|
|---|
| 691 | T_SPAWN ( T_LPAREN expr T_RPAREN {hasEvent=true;})?
|
|---|
| 692 | procedure_designator // includes actual parameter list and cosubscript, sigh
|
|---|
| 693 | // T_LBRACKET expr (T_AT T_IDENT)? T_RBRACKET
|
|---|
| 694 | end_of_stmt
|
|---|
| 695 | {
|
|---|
| 696 | action.rice_spawn_stmt(lbl, $T_SPAWN, $end_of_stmt.tk, hasEvent);
|
|---|
| 697 | }
|
|---|
| 698 | ;
|
|---|
| 699 |
|
|---|
| 700 |
|
|---|
| 701 | ///////////////////////////////////////////////////////////////////////////////
|
|---|
| 702 | // THESE RULES ARE COPIED FROM FORTRAN-PARSER-EXTRAS ONLY BECAUSE WE ARE //
|
|---|
| 703 | // CURRENTLY IMPORTING FORTRAAN-PARSER-08 INSTEAD. FIX THIS. //
|
|---|
| 704 | ///////////////////////////////////////////////////////////////////////////////
|
|---|
| 705 |
|
|---|
| 706 |
|
|---|
| 707 | /**
|
|---|
| 708 | * Section/Clause 7: Expressions and assignment
|
|---|
| 709 | */
|
|---|
| 710 |
|
|---|
| 711 | /*
|
|---|
| 712 | * R724-F08 logical-expr
|
|---|
| 713 | * is expr
|
|---|
| 714 | */
|
|---|
| 715 |
|
|---|
| 716 | ////////////
|
|---|
| 717 | // R724-F08, R724-F03
|
|---|
| 718 | //
|
|---|
| 719 | logical_expr
|
|---|
| 720 | : expr
|
|---|
| 721 | ;
|
|---|
| 722 |
|
|---|
| 723 | scalar_logical_expr
|
|---|
| 724 | : expr
|
|---|
| 725 | ;
|
|---|
| 726 |
|
|---|
| 727 |
|
|---|
| 728 | /*
|
|---|
| 729 | * R726-08 int-expr
|
|---|
| 730 | * is expr
|
|---|
| 731 | */
|
|---|
| 732 |
|
|---|
| 733 | ////////////
|
|---|
| 734 | // R726-F08, R727-F03
|
|---|
| 735 | //
|
|---|
| 736 | int_expr
|
|---|
| 737 | : expr
|
|---|
| 738 | ;
|
|---|
| 739 |
|
|---|
| 740 | scalar_int_expr
|
|---|
| 741 | : expr
|
|---|
| 742 | ;
|
|---|
| 743 |
|
|---|
| 744 |
|
|---|
| 745 | //----------------------------------------------------------------------------
|
|---|
| 746 | // additional rules following standard and useful for error checking
|
|---|
| 747 | //----------------------------------------------------------------------------
|
|---|
| 748 |
|
|---|
| 749 | scalar_variable
|
|---|
| 750 | : expr
|
|---|
| 751 | ;
|
|---|
| 752 |
|
|---|
| 753 |
|
|---|
| 754 |
|
|---|