1 /* perly.y 2 * 3 * Copyright (c) 1991-2002, 2003, 2004 Larry Wall 4 * 5 * You may distribute under the terms of either the GNU General Public 6 * License or the Artistic License, as specified in the README file. 7 * 8 */ 9 10 /* 11 * 'I see,' laughed Strider. 'I look foul and feel fair. Is that it? 12 * All that is gold does not glitter, not all those who wander are lost.' 13 */ 14 15 /* This file holds the grammar for the Perl language. If edited, you need 16 * to run regen_perly.pl, which re-creates the files perly.h, perly.tab 17 * and perly.act which are derived from this. 18 * 19 * The main job of of this grammar is to call the various newFOO() 20 * functions in op.c to build a syntax tree of OP structs. 21 * It relies on the lexer in toke.c to do the tokenizing. 22 */ 23 24 /* Make the parser re-entrant. */ 25 26 %pure_parser 27 28 %start prog 29 30 %union { 31 I32 ival; 32 char *pval; 33 OP *opval; 34 GV *gvval; 35 } 36 37 %token '{' 38 39 %token WORD METHOD FUNCMETH THING PMFUNC PRIVATEREF 40 %token FUNC0SUB UNIOPSUB LSTOPSUB 41 %token LABEL 42 %token FORMAT SUB ANONSUB PACKAGE USE 43 %token WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE FOR 44 %token LOOPEX DOTDOT 45 %token FUNC0 FUNC1 FUNC UNIOP LSTOP 46 %token RELOP EQOP MULOP ADDOP 47 %token DOLSHARP DO HASHBRACK NOAMP 48 %token LOCAL MY MYSUB 49 %token COLONATTR 50 51 %type prog decl format startsub startanonsub startformsub mintro 52 %type progstart remember mremember '&' savescope 53 %type block mblock lineseq line loop cond else 54 %type expr term subscripted scalar ary hsh arylen star amper sideff 55 %type argexpr nexpr texpr iexpr mexpr mnexpr miexpr 56 %type listexpr listexprcom indirob listop method 57 %type formname subname proto subbody cont my_scalar 58 %type subattrlist myattrlist mysubrout myattrterm myterm 59 %type termbinop termunop anonymous termdo 60 %type label 61 62 %nonassoc PREC_LOW 63 %nonassoc LOOPEX 64 65 %left OROP DOROP 66 %left ANDOP 67 %right NOTOP 68 %nonassoc LSTOP LSTOPSUB 69 %left ',' 70 %right ASSIGNOP 71 %right '?' ':' 72 %nonassoc DOTDOT 73 %left OROR DORDOR 74 %left ANDAND 75 %left BITOROP 76 %left BITANDOP 77 %nonassoc EQOP 78 %nonassoc RELOP 79 %nonassoc UNIOP UNIOPSUB 80 %left SHIFTOP 81 %left ADDOP 82 %left MULOP 83 %left MATCHOP 84 %right '!' '~' UMINUS REFGEN 85 %right POWOP 86 %nonassoc PREINC PREDEC POSTINC POSTDEC 87 %left ARROW 88 %nonassoc ')' 89 %left '(' 90 %left '[' '{' 91 92 %% /* RULES */ 93 94 /* The whole program */ 95 prog : progstart 96 /*CONTINUED*/ lineseq 97 105468 { $$ = $1; newPROG(block_end($1,$2)); } 98 105460 ; 99 100 /* An ordinary block */ 101 block : '{' remember lineseq '}' 102 441450 { if (PL_copline > (line_t)$1) 103 441450 PL_copline = (line_t)$1; 104 441450 $$ = block_end($2, $3); } 105 441450 ; 106 107 remember: /* NULL */ /* start a full lexical scope */ 108 812903 { $$ = block_start(TRUE); } 109 812903 ; 110 111 progstart: 112 { 113 106267 PL_expect = XSTATE; $$ = block_start(TRUE); 114 } 115 106267 ; 116 117 118 mblock : '{' mremember lineseq '}' 119 536999 { if (PL_copline > (line_t)$1) 120 536999 PL_copline = (line_t)$1; 121 536999 $$ = block_end($2, $3); } 122 536999 ; 123 124 mremember: /* NULL */ /* start a partial lexical scope */ 125 537000 { $$ = block_start(FALSE); } 126 537000 ; 127 128 savescope: /* NULL */ /* remember stack pos in case of error */ 129 3802372 { $$ = PL_savestack_ix; } 130 3802372 131 /* A collection of "lines" in the program */ 132 lineseq : /* NULL */ 133 1084729 { $$ = Nullop; } 134 1084729 | lineseq decl 135 407095 { $$ = $1; } 136 407095 | lineseq savescope line 137 3801789 { LEAVE_SCOPE($2); 138 3801789 $$ = append_list(OP_LINESEQ, 139 (LISTOP*)$1, (LISTOP*)$3); 140 3801789 PL_pad_reset_pending = TRUE; 141 3801789 if ($1 && $3) PL_hints |= HINT_BLOCK_SCOPE; } 142 1894313 ; 143 144 /* A "line" in the program */ 145 line : label cond 146 285993 { $$ = newSTATEOP(0, $1, $2); } 147 285993 | loop /* loops add their own labels */ 148 | label ';' 149 832256 { if ($1 != Nullch) { 150 312 $$ = newSTATEOP(0, $1, newOP(OP_NULL, 0)); 151 } 152 else { 153 831944 $$ = Nullop; 154 831944 PL_copline = NOLINE; 155 } 156 832256 PL_expect = XSTATE; } 157 832256 | label sideff ';' 158 2583029 { $$ = newSTATEOP(0, $1, $2); 159 2583029 PL_expect = XSTATE; } 160 2583029 ; 161 162 /* An expression which may have a side-effect */ 163 sideff : error 164 248 { $$ = Nullop; } 165 248 | expr 166 2240259 { $$ = $1; } 167 2240259 | expr IF expr 168 197140 { $$ = newLOGOP(OP_AND, 0, $3, $1); } 169 197140 | expr UNLESS expr 170 127406 { $$ = newLOGOP(OP_OR, 0, $3, $1); } 171 127406 | expr WHILE expr 172 14400 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); } 173 14400 | expr UNTIL iexpr 174 60 { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1);} 175 60 | expr FOR expr 176 10830 { $$ = newFOROP(0, Nullch, (line_t)$2, 177 Nullop, $3, $1, Nullop); } 178 10830 ; 179 180 /* else and elsif blocks */ 181 else : /* NULL */ 182 188142 { $$ = Nullop; } 183 188142 | ELSE mblock 184 97851 { ($2)->op_flags |= OPf_PARENS; $$ = scope($2); } 185 97851 | ELSIF '(' mexpr ')' mblock else 186 67708 { PL_copline = (line_t)$1; 187 67708 $$ = newCONDOP(0, $3, scope($5), $6); 188 67708 PL_hints |= HINT_BLOCK_SCOPE; } 189 67708 ; 190 191 /* Real conditional expressions */ 192 cond : IF '(' remember mexpr ')' mblock else 193 251914 { PL_copline = (line_t)$1; 194 251914 $$ = block_end($3, 195 newCONDOP(0, $4, scope($6), $7)); } 196 251914 | UNLESS '(' remember miexpr ')' mblock else 197 34079 { PL_copline = (line_t)$1; 198 34079 $$ = block_end($3, 199 newCONDOP(0, $4, scope($6), $7)); } 200 34079 ; 201 202 /* Continue blocks */ 203 cont : /* NULL */ 204 93956 { $$ = Nullop; } 205 93956 | CONTINUE block 206 756 { $$ = scope($2); } 207 756 ; 208 209 /* Loops: while, until, for, and a bare block */ 210 loop : label WHILE '(' remember texpr ')' mintro mblock cont 211 19228 { PL_copline = (line_t)$2; 212 19228 $$ = block_end($4, 213 newSTATEOP(0, $1, 214 newWHILEOP(0, 1, (LOOP*)Nullop, 215 $2, $5, $8, $9, $7))); } 216 19227 | label UNTIL '(' remember iexpr ')' mintro mblock cont 217 144 { PL_copline = (line_t)$2; 218 144 $$ = block_end($4, 219 newSTATEOP(0, $1, 220 newWHILEOP(0, 1, (LOOP*)Nullop, 221 $2, $5, $8, $9, $7))); } 222 144 | label FOR MY remember my_scalar '(' mexpr ')' mblock cont 223 33297 { $$ = block_end($4, 224 newFOROP(0, $1, (line_t)$2, $5, $7, $9, $10)); } 225 33297 | label FOR scalar '(' remember mexpr ')' mblock cont 226 14418 { $$ = block_end($5, 227 newFOROP(0, $1, (line_t)$2, mod($3, OP_ENTERLOOP), 228 $6, $8, $9)); } 229 14418 | label FOR '(' remember mexpr ')' mblock cont 230 12560 { $$ = block_end($4, 231 newFOROP(0, $1, (line_t)$2, Nullop, $5, $7, $8)); } 232 12560 | label FOR '(' remember mnexpr ';' texpr ';' mintro mnexpr ')' 233 mblock 234 /* basically fake up an initialize-while lineseq */ 235 5800 { OP *forop; 236 5800 PL_copline = (line_t)$2; 237 5800 forop = newSTATEOP(0, $1, 238 newWHILEOP(0, 1, (LOOP*)Nullop, 239 $2, scalar($7), 240 $12, $10, $9)); 241 5800 if ($5) { 242 3190 forop = append_elem(OP_LINESEQ, 243 newSTATEOP(0, ($1?savepv($1):Nullch), 244 $5), 245 forop); 246 } 247 248 5800 $$ = block_end($4, forop); } 249 5800 | label block cont /* a block is a loop that happens once */ 250 15065 { $$ = newSTATEOP(0, $1, 251 newWHILEOP(0, 1, (LOOP*)Nullop, 252 NOLINE, Nullop, $2, $3, 0)); } 253 15065 ; 254 255 /* determine whether there are any new my declarations */ 256 mintro : /* NULL */ 257 25173 { $$ = (PL_min_intro_pending && 258 PL_max_intro_pending >= PL_min_intro_pending); 259 25173 intro_my(); } 260 25173 261 /* Normal expression */ 262 nexpr : /* NULL */ 263 4485 { $$ = Nullop; } 264 4485 | sideff 265 ; 266 267 /* Boolean expression */ 268 texpr : /* NULL means true */ 269 1855 { (void)scan_num("1", &yylval); $$ = yylval.opval; } 270 1855 | expr 271 ; 272 273 /* Inverted boolean expression */ 274 iexpr : expr 275 34283 { $$ = invert(scalar($1)); } 276 34283 ; 277 278 /* Expression with its own lexical scope */ 279 mexpr : expr 280 379897 { $$ = $1; intro_my(); } 281 379897 ; 282 283 mnexpr : nexpr 284 11600 { $$ = $1; intro_my(); } 285 11600 ; 286 287 miexpr : iexpr 288 34079 { $$ = $1; intro_my(); } 289 34079 ; 290 291 /* Optional "MAIN:"-style loop labels */ 292 label : /* empty */ 293 3795286 { $$ = Nullch; } 294 3795286 | LABEL 295 ; 296 297 /* Some kind of declaration - does not take part in the parse tree */ 298 decl : format 299 88 { $$ = 0; } 300 88 | subrout 301 295968 { $$ = 0; } 302 295968 | mysubrout 303 ###### { $$ = 0; } 304 ###### | package 305 39129 { $$ = 0; } 306 39129 | use 307 71910 { $$ = 0; } 308 71910 ; 309 310 format : FORMAT startformsub formname block 311 88 { newFORM($2, $3, $4); } 312 88 ; 313 314 86 formname: WORD { $$ = $1; } 315 86 | /* NULL */ { $$ = Nullop; } 316 3 ; 317 318 /* Unimplemented "my sub foo { }" */ 319 mysubrout: MYSUB startsub subname proto subattrlist subbody 320 ###### { newMYSUB($2, $3, $4, $5, $6); } 321 296028 ; 322 323 /* Subroutine definition */ 324 subrout : SUB startsub subname proto subattrlist subbody 325 296028 { newATTRSUB($2, $3, $4, $5, $6); } 326 295968 ; 327 328 startsub: /* NULL */ /* start a regular subroutine scope */ 329 368073 { $$ = start_subparse(FALSE, 0); } 330 368073 ; 331 332 startanonsub: /* NULL */ /* start an anonymous subroutine scope */ 333 18882 { $$ = start_subparse(FALSE, CVf_ANON); } 334 18882 ; 335 336 startformsub: /* NULL */ /* start a format subroutine scope */ 337 89 { $$ = start_subparse(TRUE, 0); } 338 89 ; 339 340 /* Name of a subroutine - must be a bareword, could be special */ 341 296034 subname : WORD { STRLEN n_a; const char *name = SvPV_const(((SVOP*)$1)->op_sv,n_a); 342 296034 if (strEQ(name, "BEGIN") || strEQ(name, "END") 343 || strEQ(name, "INIT") || strEQ(name, "CHECK")) 344 6607 CvSPECIAL_on(PL_compcv); 345 296034 $$ = $1; } 346 296034 ; 347 348 /* Subroutine prototype */ 349 proto : /* NULL */ 350 285508 { $$ = Nullop; } 351 285508 | THING 352 ; 353 354 /* Optional list of subroutine attributes */ 355 subattrlist: /* NULL */ 356 314260 { $$ = Nullop; } 357 314260 | COLONATTR THING 358 31 { $$ = $2; } 359 31 | COLONATTR 360 78 { $$ = Nullop; } 361 78 ; 362 363 /* List of attributes for a "my" variable declaration */ 364 myattrlist: COLONATTR THING 365 46 { $$ = $2; } 366 46 | COLONATTR 367 1092 { $$ = Nullop; } 368 1092 ; 369 370 /* Subroutine body - either null or a block */ 371 265309 subbody : block { $$ = $1; } 372 265309 | ';' { $$ = Nullop; PL_expect = XSTATE; } 373 30719 ; 374 375 package : PACKAGE WORD ';' 376 39129 { package($2); } 377 39129 ; 378 379 use : USE startsub 380 72039 { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ } 381 72039 WORD WORD listexpr ';' 382 72038 { utilize($1, $2, $4, $5, $6); } 383 71910 ; 384 385 /* Ordinary expressions; logical combinations */ 386 expr : expr ANDOP expr 387 45342 { $$ = newLOGOP(OP_AND, 0, $1, $3); } 388 45342 | expr OROP expr 389 55624 { $$ = newLOGOP($2, 0, $1, $3); } 390 55623 | expr DOROP expr 391 10 { $$ = newLOGOP(OP_DOR, 0, $1, $3); } 392 10 | argexpr %prec PREC_LOW 393 ; 394 395 /* Expressions are a list of terms joined by commas */ 396 argexpr : argexpr ',' 397 21684 { $$ = $1; } 398 21684 | argexpr ',' term 399 2094485 { $$ = append_elem(OP_LIST, $1, $3); } 400 2094484 | term %prec PREC_LOW 401 ; 402 403 /* List operators */ 404 listop : LSTOP indirob argexpr /* map {...} @args or print $fh @args */ 405 46226 { $$ = convert($1, OPf_STACKED, 406 prepend_elem(OP_LIST, newGVREF($1,$2), $3) ); } 407 46225 | FUNC '(' indirob expr ')' /* print ($fh @args */ 408 28 { $$ = convert($1, OPf_STACKED, 409 prepend_elem(OP_LIST, newGVREF($1,$3), $4) ); } 410 28 | term ARROW method '(' listexprcom ')' /* $foo->bar(list) */ 411 193680 { $$ = convert(OP_ENTERSUB, OPf_STACKED, 412 append_elem(OP_LIST, 413 prepend_elem(OP_LIST, scalar($1), $5), 414 newUNOP(OP_METHOD, 0, $3))); } 415 193678 | term ARROW method /* $foo->bar */ 416 46943 { $$ = convert(OP_ENTERSUB, OPf_STACKED, 417 append_elem(OP_LIST, scalar($1), 418 newUNOP(OP_METHOD, 0, $3))); } 419 46943 | METHOD indirob listexpr /* new Class @args */ 420 4422 { $$ = convert(OP_ENTERSUB, OPf_STACKED, 421 append_elem(OP_LIST, 422 prepend_elem(OP_LIST, $2, $3), 423 newUNOP(OP_METHOD, 0, $1))); } 424 4422 | FUNCMETH indirob '(' listexprcom ')' /* method $object (@args) */ 425 1024 { $$ = convert(OP_ENTERSUB, OPf_STACKED, 426 append_elem(OP_LIST, 427 prepend_elem(OP_LIST, $2, $4), 428 newUNOP(OP_METHOD, 0, $1))); } 429 1024 | LSTOP listexpr /* print @args */ 430 374068 { $$ = convert($1, 0, $2); } 431 373981 | FUNC '(' listexprcom ')' /* print (@args) */ 432 737737 { $$ = convert($1, 0, $3); } 433 737733 | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */ 434 547 { $3 = newANONATTRSUB($2, 0, Nullop, $3); } 435 547 listexpr %prec LSTOP /* ... @bar */ 436 547 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, 437 append_elem(OP_LIST, 438 prepend_elem(OP_LIST, $3, $5), $1)); } 439 547 ; 440 441 /* Names of methods. May use $object->$methodname */ 442 method : METHOD 443 | scalar 444 ; 445 446 /* Some kind of subscripted expression */ 447 subscripted: star '{' expr ';' '}' /* *main::{something} */ 448 /* In this and all the hash accessors, ';' is 449 * provided by the tokeniser */ 450 2189 { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); 451 2188 PL_expect = XOPERATOR; } 452 2188 | scalar '[' expr ']' /* $array[$element] */ 453 131064 { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3)); } 454 131063 | term ARROW '[' expr ']' /* somearef->[$element] */ 455 30971 { $$ = newBINOP(OP_AELEM, 0, 456 ref(newAVREF($1),OP_RV2AV), 457 scalar($4));} 458 30970 | subscripted '[' expr ']' /* $foo->[$bar]->[$baz] */ 459 6012 { $$ = newBINOP(OP_AELEM, 0, 460 ref(newAVREF($1),OP_RV2AV), 461 scalar($3));} 462 6012 | scalar '{' expr ';' '}' /* $foo->{bar();} */ 463 241713 { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3)); 464 241712 PL_expect = XOPERATOR; } 465 241712 | term ARROW '{' expr ';' '}' /* somehref->{bar();} */ 466 220404 { $$ = newBINOP(OP_HELEM, 0, 467 ref(newHVREF($1),OP_RV2HV), 468 jmaybe($4)); 469 220402 PL_expect = XOPERATOR; } 470 220402 | subscripted '{' expr ';' '}' /* $foo->[bar]->{baz;} */ 471 10058 { $$ = newBINOP(OP_HELEM, 0, 472 ref(newHVREF($1),OP_RV2HV), 473 jmaybe($3)); 474 10058 PL_expect = XOPERATOR; } 475 10058 | term ARROW '(' ')' /* $subref->() */ 476 1805 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, 477 newCVREF(0, scalar($1))); } 478 1805 | term ARROW '(' expr ')' /* $subref->(@args) */ 479 1429 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, 480 append_elem(OP_LIST, $4, 481 newCVREF(0, scalar($1)))); } 482 1429 483 | subscripted '(' expr ')' /* $foo->{bar}->(@args) */ 484 12 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, 485 append_elem(OP_LIST, $3, 486 newCVREF(0, scalar($1)))); } 487 12 | subscripted '(' ')' /* $foo->{bar}->() */ 488 ###### { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, 489 newCVREF(0, scalar($1))); } 490 ###### ; 491 492 /* Binary operators between terms */ 493 termbinop : term ASSIGNOP term /* $x = $y */ 494 1289935 { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); } 495 1289927 | term POWOP term /* $x ** $y */ 496 1635 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); } 497 1634 | term MULOP term /* $x * $y, $x x $y */ 498 24608 { if ($2 != OP_REPEAT) 499 15643 scalar($1); 500 24608 $$ = newBINOP($2, 0, $1, scalar($3)); } 501 24604 | term ADDOP term /* $x + $y */ 502 749949 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); } 503 749944 | term SHIFTOP term /* $x >> $y, $x << $y */ 504 730 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); } 505 728 | term RELOP term /* $x > $y, etc. */ 506 67370 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); } 507 67362 | term EQOP term /* $x == $y, $x eq $y */ 508 270095 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); } 509 270089 | term BITANDOP term /* $x & $y */ 510 6487 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); } 511 6486 | term BITOROP term /* $x | $y */ 512 14027 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); } 513 14025 | term DOTDOT term /* $x..$y, $x...$y */ 514 7553 { $$ = newRANGE($2, scalar($1), scalar($3));} 515 7551 | term ANDAND term /* $x && $y */ 516 84422 { $$ = newLOGOP(OP_AND, 0, $1, $3); } 517 84421 | term OROR term /* $x || $y */ 518 90416 { $$ = newLOGOP(OP_OR, 0, $1, $3); } 519 90415 | term DORDOR term /* $x // $y */ 520 25 { $$ = newLOGOP(OP_DOR, 0, $1, $3); } 521 24 | term MATCHOP term /* $x =~ /$y/ */ 522 178802 { $$ = bind_match($2, $1, $3); } 523 178802 ; 524 525 /* Unary operators and terms */ 526 termunop : '-' term %prec UMINUS /* -$x */ 527 29506 { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); } 528 29505 | '+' term %prec UMINUS /* +$x */ 529 1706 { $$ = $2; } 530 1706 | '!' term /* !$x */ 531 75934 { $$ = newUNOP(OP_NOT, 0, scalar($2)); } 532 75933 | '~' term /* ~$x */ 533 11980 { $$ = newUNOP(OP_COMPLEMENT, 0, scalar($2));} 534 11979 | term POSTINC /* $x++ */ 535 30749 { $$ = newUNOP(OP_POSTINC, 0, 536 mod(scalar($1), OP_POSTINC)); } 537 30748 | term POSTDEC /* $x-- */ 538 12250 { $$ = newUNOP(OP_POSTDEC, 0, 539 mod(scalar($1), OP_POSTDEC)); } 540 12249 | PREINC term /* ++$x */ 541 7119 { $$ = newUNOP(OP_PREINC, 0, 542 mod(scalar($2), OP_PREINC)); } 543 7118 | PREDEC term /* --$x */ 544 1897 { $$ = newUNOP(OP_PREDEC, 0, 545 mod(scalar($2), OP_PREDEC)); } 546 1896 547 ; 548 549 /* Constructors for anonymous data */ 550 anonymous: '[' expr ']' 551 28195 { $$ = newANONLIST($2); } 552 28194 | '[' ']' 553 4069 { $$ = newANONLIST(Nullop); } 554 4069 | HASHBRACK expr ';' '}' %prec '(' /* { foo => "Bar" } */ 555 16670 { $$ = newANONHASH($2); } 556 16669 | HASHBRACK ';' '}' %prec '(' /* { } (';' by tokener) */ 557 8307 { $$ = newANONHASH(Nullop); } 558 8307 | ANONSUB startanonsub proto subattrlist block %prec '(' 559 18331 { $$ = newANONATTRSUB($2, $3, $4, $5); } 560 18330 561 ; 562 563 /* Things called with "do" */ 564 termdo : DO term %prec UNIOP /* do $filename */ 565 1083 { $$ = dofile($2); } 566 1082 | DO block %prec '(' /* do { code */ 567 16032 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, scope($2)); } 568 16032 | DO WORD '(' ')' /* do somesub() */ 569 7 { $$ = newUNOP(OP_ENTERSUB, 570 OPf_SPECIAL|OPf_STACKED, 571 prepend_elem(OP_LIST, 572 scalar(newCVREF( 573 (OPpENTERSUB_AMPER<<8), 574 scalar($2) 575 7 )),Nullop)); dep();} 576 7 | DO WORD '(' expr ')' /* do somesub(@args) */ 577 24 { $$ = newUNOP(OP_ENTERSUB, 578 OPf_SPECIAL|OPf_STACKED, 579 append_elem(OP_LIST, 580 $4, 581 scalar(newCVREF( 582 (OPpENTERSUB_AMPER<<8), 583 scalar($2) 584 24 )))); dep();} 585 24 | DO scalar '(' ')' /* do $subref () */ 586 2 { $$ = newUNOP(OP_ENTERSUB, OPf_SPECIAL|OPf_STACKED, 587 prepend_elem(OP_LIST, 588 2 scalar(newCVREF(0,scalar($2))), Nullop)); dep();} 589 2 | DO scalar '(' expr ')' /* do $subref (@args) */ 590 2 { $$ = newUNOP(OP_ENTERSUB, OPf_SPECIAL|OPf_STACKED, 591 prepend_elem(OP_LIST, 592 $4, 593 2 scalar(newCVREF(0,scalar($2))))); dep();} 594 2 595 ; 596 597 term : termbinop 598 | termunop 599 | anonymous 600 | termdo 601 | term '?' term ':' term 602 92869 { $$ = newCONDOP(0, $1, $3, $5); } 603 92868 | REFGEN term /* \$x, \@y, \%z */ 604 89292 { $$ = newUNOP(OP_REFGEN, 0, mod($2,OP_REFGEN)); } 605 89291 | myattrterm %prec UNIOP 606 607168 { $$ = $1; } 607 607168 | LOCAL term %prec UNIOP 608 51078 { $$ = localize($2,$1); } 609 51077 | '(' expr ')' 610 343626 { $$ = sawparens($2); } 611 343626 | '(' ')' 612 25052 { $$ = sawparens(newNULLLIST()); } 613 25052 | scalar %prec '(' 614 3619767 { $$ = $1; } 615 3619767 | star %prec '(' 616 57782 { $$ = $1; } 617 57782 | hsh %prec '(' 618 60940 { $$ = $1; } 619 60940 | ary %prec '(' 620 585022 { $$ = $1; } 621 585022 | arylen %prec '(' /* $#x, $#{ something } */ 622 9035 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));} 623 9034 | subscripted 624 629569 { $$ = $1; } 625 629569 | '(' expr ')' '[' expr ']' /* list slice */ 626 23660 { $$ = newSLICEOP(0, $5, $2); } 627 23660 | '(' ')' '[' expr ']' /* empty list slice! */ 628 ###### { $$ = newSLICEOP(0, $4, Nullop); } 629 ###### | ary '[' expr ']' /* array slice */ 630 1702 { $$ = prepend_elem(OP_ASLICE, 631 newOP(OP_PUSHMARK, 0), 632 newLISTOP(OP_ASLICE, 0, 633 list($3), 634 ref($1, OP_ASLICE))); } 635 1701 | ary '{' expr ';' '}' /* @hash{@keys} */ 636 10886 { $$ = prepend_elem(OP_HSLICE, 637 newOP(OP_PUSHMARK, 0), 638 newLISTOP(OP_HSLICE, 0, 639 list($3), 640 ref(oopsHV($1), OP_HSLICE))); 641 10885 PL_expect = XOPERATOR; } 642 10885 | THING %prec '(' 643 3226633 { $$ = $1; } 644 3226633 | amper /* &foo; */ 645 80258 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); } 646 80258 | amper '(' ')' /* &foo() */ 647 47765 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); } 648 47764 | amper '(' expr ')' /* &foo(@args) */ 649 279715 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, 650 append_elem(OP_LIST, $3, scalar($1))); } 651 279715 | NOAMP WORD listexpr /* foo(@args) */ 652 44754 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, 653 append_elem(OP_LIST, $3, scalar($2))); } 654 44754 | LOOPEX /* loop exiting command (goto, last, dump, etc) */ 655 52339 { $$ = newOP($1, OPf_SPECIAL); 656 52336 PL_hints |= HINT_BLOCK_SCOPE; } 657 52336 | LOOPEX term 658 41465 { $$ = newLOOPEX($1,$2); } 659 41463 | NOTOP argexpr /* not $foo */ 660 9193 { $$ = newUNOP(OP_NOT, 0, scalar($2)); } 661 9193 | UNIOP /* Unary op, $_ implied */ 662 138797 { $$ = newOP($1, 0); } 663 138729 | UNIOP block /* eval { foo } */ 664 11531 { $$ = newUNOP($1, 0, $2); } 665 11531 | UNIOP term /* Unary op */ 666 352054 { $$ = newUNOP($1, 0, $2); } 667 352011 | UNIOPSUB term /* Sub treated as unop */ 668 581 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, 669 append_elem(OP_LIST, $2, scalar($1))); } 670 581 | FUNC0 /* Nullary operator */ 671 6072 { $$ = newOP($1, 0); } 672 6051 | FUNC0 '(' ')' 673 548 { $$ = newOP($1, 0); } 674 548 | FUNC0SUB /* Sub treated as nullop */ 675 1276 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, 676 scalar($1)); } 677 1276 | FUNC1 '(' ')' /* not () */ 678 4616 { $$ = $1 == OP_NOT ? newUNOP($1, 0, newSVOP(OP_CONST, 0, newSViv(0))) 679 : newOP($1, OPf_SPECIAL); } 680 4616 | FUNC1 '(' expr ')' /* not($foo) */ 681 160012 { $$ = newUNOP($1, 0, $3); } 682 160012 | PMFUNC '(' argexpr ')' /* m//, s///, tr/// */ 683 227073 { $$ = pmruntime($1, $3, 1); } 684 226842 | WORD 685 | listop 686 ; 687 688 /* "my" declarations, with optional attributes */ 689 myattrterm: MY myterm myattrlist 690 1138 { $$ = my_attrs($2,$3); } 691 1138 | MY myterm 692 606030 { $$ = localize($2,$1); } 693 606030 ; 694 695 /* Things that can be "my"'d */ 696 myterm : '(' expr ')' 697 149329 { $$ = sawparens($2); } 698 149329 | '(' ')' 699 ###### { $$ = sawparens(newNULLLIST()); } 700 ###### | scalar %prec '(' 701 384614 { $$ = $1; } 702 384614 | hsh %prec '(' 703 29868 { $$ = $1; } 704 29868 | ary %prec '(' 705 43358 { $$ = $1; } 706 43358 ; 707 708 /* Basic list expressions */ 709 listexpr: /* NULL */ %prec PREC_LOW 710 70895 { $$ = Nullop; } 711 70895 | argexpr %prec PREC_LOW 712 424934 { $$ = $1; } 713 424934 ; 714 715 listexprcom: /* NULL */ 716 32271 { $$ = Nullop; } 717 32271 | expr 718 900171 { $$ = $1; } 719 900171 | expr ',' 720 ###### { $$ = $1; } 721 ###### ; 722 723 /* A little bit of trickery to make "for my $foo (@bar)" actually be 724 lexical */ 725 my_scalar: scalar 726 33297 { PL_in_my = 0; $$ = my($1); } 727 33297 ; 728 729 amper : '&' indirob 730 407740 { $$ = newCVREF($1,$2); } 731 407739 ; 732 733 scalar : '$' indirob 734 4547962 { $$ = newSVREF($2); } 735 4547961 ; 736 737 ary : '@' indirob 738 640969 { $$ = newAVREF($2); } 739 640968 ; 740 741 hsh : '%' indirob 742 90809 { $$ = newHVREF($2); } 743 90808 ; 744 745 arylen : DOLSHARP indirob 746 9035 { $$ = newAVREF($2); } 747 9035 ; 748 749 star : '*' indirob 750 59972 { $$ = newGVREF(0,$2); } 751 59971 ; 752 753 /* Indirect objects */ 754 indirob : WORD 755 1762690 { $$ = scalar($1); } 756 1762690 | scalar %prec PREC_LOW 757 121681 { $$ = scalar($1); } 758 121681 | block 759 113791 { $$ = scope($1); } 760 113791 761 | PRIVATEREF 762 3810026 { $$ = $1; } 763 ;