3 * Copyright (c) 1991-2002, 2003, 2004, 2005, 2006 Larry Wall
4 * Copyright (c) 2007, 2008, 2009, 2010, 2011 by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
12 * 'I see,' laughed Strider. 'I look foul and feel fair. Is that it?
13 * All that is gold does not glitter, not all those who wander are lost.'
15 * [p.171 of _The Lord of the Rings_, I/x: "Strider"]
19 * This file holds the grammar for the Perl language. If edited, you need
20 * to run regen_perly.pl, which re-creates the files perly.h, perly.tab
21 * and perly.act which are derived from this.
23 * The main job of of this grammar is to call the various newFOO()
24 * functions in op.c to build a syntax tree of OP structs.
25 * It relies on the lexer in toke.c to do the tokenizing.
27 * Note: due to the way that the cleanup code works WRT to freeing ops on
28 * the parse stack, it is dangerous to assign to the $n variables within
32 /* Make the parser re-entrant. */
39 I32 ival; /* __DEFAULT__ (marker for regen_perly.pl;
40 must always be 1st union member) */
46 %token <ival> GRAMPROG GRAMEXPR GRAMBLOCK GRAMBARESTMT GRAMFULLSTMT GRAMSTMTSEQ
48 %token <ival> '{' '}' '[' ']' '-' '+' '$' '@' '%' '*' '&' ';' '=' '.'
50 %token <opval> WORD METHOD FUNCMETH THING PMFUNC PRIVATEREF QWLIST
51 %token <opval> FUNC0OP FUNC0SUB UNIOPSUB LSTOPSUB
52 %token <opval> PLUGEXPR PLUGSTMT
54 %token <ival> FORMAT SUB ANONSUB PACKAGE USE
55 %token <ival> WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE FOR
56 %token <ival> GIVEN WHEN DEFAULT
57 %token <ival> LOOPEX DOTDOT YADAYADA
58 %token <ival> FUNC0 FUNC1 FUNC UNIOP LSTOP
59 %token <ival> RELOP EQOP MULOP ADDOP
60 %token <ival> DOLSHARP DO HASHBRACK NOAMP
61 %token <ival> LOCAL MY REQUIRE
62 %token <ival> COLONATTR FORMLBRACK FORMRBRACK
64 %type <ival> grammar remember mremember
65 %type <ival> startsub startanonsub startformsub
69 %type <opval> stmtseq fullstmt labfullstmt barestmt block mblock else
70 %type <opval> expr term subscripted scalar ary hsh arylen star amper sideff
71 %type <opval> sliceme kvslice gelem
72 %type <opval> listexpr nexpr texpr iexpr mexpr mnexpr miexpr
73 %type <opval> optlistexpr optexpr indirob listop method
74 %type <opval> formname subname proto optsubbody cont my_scalar my_var
75 %type <opval> refgen_topic formblock
76 %type <opval> subattrlist myattrlist myattrterm myterm
77 %type <opval> realsubbody subsignature termbinop termunop anonymous termdo
78 %type <opval> formstmtseq formline formarg
80 %nonassoc <ival> PREC_LOW
83 %left <ival> OROP DOROP
86 %nonassoc LSTOP LSTOPSUB
88 %right <ival> ASSIGNOP
90 %nonassoc DOTDOT YADAYADA
91 %left <ival> OROR DORDOR
97 %nonassoc UNIOP UNIOPSUB
103 %right <ival> '!' '~' UMINUS REFGEN
105 %nonassoc <ival> PREINC PREDEC POSTINC POSTDEC POSTJOIN
113 /* Top-level choice of what kind of thing yyparse was called to parse */
116 parser->expect = XSTATE;
120 newPROG(block_end($3,$4));
121 PL_compiling.cop_seq = 0;
126 parser->expect = XTERM;
135 parser->expect = XBLOCK;
139 PL_pad_reset_pending = TRUE;
143 parser->yychar = YYEOF;
147 parser->expect = XSTATE;
151 PL_pad_reset_pending = TRUE;
155 parser->yychar = YYEOF;
159 parser->expect = XSTATE;
163 PL_pad_reset_pending = TRUE;
167 parser->yychar = YYEOF;
171 parser->expect = XSTATE;
180 /* An ordinary block */
181 block : '{' remember stmtseq '}'
182 { if (parser->copline > (line_t)$1)
183 parser->copline = (line_t)$1;
184 $$ = block_end($2, $3);
189 formblock: '=' remember ';' FORMRBRACK formstmtseq ';' '.'
190 { if (parser->copline > (line_t)$1)
191 parser->copline = (line_t)$1;
192 $$ = block_end($2, $5);
196 remember: /* NULL */ /* start a full lexical scope */
197 { $$ = block_start(TRUE);
198 parser->parsed_sub = 0; }
201 mblock : '{' mremember stmtseq '}'
202 { if (parser->copline > (line_t)$1)
203 parser->copline = (line_t)$1;
204 $$ = block_end($2, $3);
208 mremember: /* NULL */ /* start a partial lexical scope */
209 { $$ = block_start(FALSE);
210 parser->parsed_sub = 0; }
213 /* A sequence of statements in the program */
217 { $$ = op_append_list(OP_LINESEQ, $1, $2);
218 PL_pad_reset_pending = TRUE;
220 PL_hints |= HINT_BLOCK_SCOPE;
224 /* A sequence of format lines */
225 formstmtseq: /* NULL */
227 | formstmtseq formline
228 { $$ = op_append_list(OP_LINESEQ, $1, $2);
229 PL_pad_reset_pending = TRUE;
231 PL_hints |= HINT_BLOCK_SCOPE;
235 /* A statement in the program, including optional labels */
238 $$ = $1 ? newSTATEOP(0, NULL, $1) : NULL;
244 labfullstmt: LABEL barestmt
246 $$ = newSTATEOP(SVf_UTF8 * $1[strlen($1)+1], $1, $2);
250 $$ = newSTATEOP(SVf_UTF8 * $1[strlen($1)+1], $1, $2);
254 /* A bare statement, lacking label and other aspects of state op */
257 | FORMAT startformsub formname formblock
259 CV *fmtcv = PL_compcv;
262 if (CvOUTSIDE(fmtcv) && !CvEVAL(CvOUTSIDE(fmtcv))) {
263 SvREFCNT_inc_simple_void(fmtcv);
264 pad_add_anon(fmtcv, OP_NULL);
266 parser->parsed_sub = 1;
268 | SUB subname startsub
270 if ($2->op_type == OP_CONST) {
271 const char *const name =
272 SvPV_nolen_const(((SVOP*)$2)->op_sv);
273 if (strEQ(name, "BEGIN") || strEQ(name, "END")
274 || strEQ(name, "INIT") || strEQ(name, "CHECK")
275 || strEQ(name, "UNITCHECK"))
276 CvSPECIAL_on(PL_compcv);
279 /* State subs inside anonymous subs need to be
280 clonable themselves. */
281 if (CvANON(CvOUTSIDE(PL_compcv))
282 || CvCLONE(CvOUTSIDE(PL_compcv))
283 || !PadnameIsSTATE(PadlistNAMESARRAY(CvPADLIST(
286 CvCLONE_on(PL_compcv);
288 parser->in_my_stash = NULL;
290 proto subattrlist optsubbody
292 SvREFCNT_inc_simple_void(PL_compcv);
293 $2->op_type == OP_CONST
294 ? newATTRSUB($3, $2, $5, $6, $7)
295 : newMYSUB($3, $2, $5, $6, $7)
299 parser->parsed_sub = 1;
301 | PACKAGE WORD WORD ';'
309 { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
310 WORD WORD optlistexpr ';'
312 SvREFCNT_inc_simple_void(PL_compcv);
313 utilize($1, $2, $4, $5, $6);
314 parser->parsed_sub = 1;
317 | IF '(' remember mexpr ')' mblock else
320 newCONDOP(0, $4, op_scope($6), $7));
321 parser->copline = (line_t)$1;
323 | UNLESS '(' remember miexpr ')' mblock else
326 newCONDOP(0, $4, op_scope($6), $7));
327 parser->copline = (line_t)$1;
329 | GIVEN '(' remember mexpr ')' mblock
331 const PADOFFSET offset = pad_findmy_pvs("$_", 0);
333 newGIVENOP($4, op_scope($6),
335 || PAD_COMPNAME_FLAGS_isOUR(offset)
338 parser->copline = (line_t)$1;
340 | WHEN '(' remember mexpr ')' mblock
341 { $$ = block_end($3, newWHENOP($4, op_scope($6))); }
343 { $$ = newWHENOP(0, op_scope($2)); }
344 | WHILE '(' remember texpr ')' mintro mblock cont
347 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
349 parser->copline = (line_t)$1;
351 | UNTIL '(' remember iexpr ')' mintro mblock cont
354 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
356 parser->copline = (line_t)$1;
358 | FOR '(' remember mnexpr ';'
359 { parser->expect = XTERM; }
361 { parser->expect = XTERM; }
366 OP *forop = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
367 scalar($7), $13, $11, $10);
369 forop = op_prepend_elem(OP_LINESEQ, initop,
370 op_append_elem(OP_LINESEQ,
371 newOP(OP_UNSTACK, OPf_SPECIAL),
374 PL_hints |= HINT_BLOCK_SCOPE;
375 $$ = block_end($3, forop);
376 parser->copline = (line_t)$1;
378 | FOR MY remember my_scalar '(' mexpr ')' mblock cont
380 $$ = block_end($3, newFOROP(0, $4, $6, $8, $9));
381 parser->copline = (line_t)$1;
383 | FOR scalar '(' remember mexpr ')' mblock cont
385 $$ = block_end($4, newFOROP(0,
386 op_lvalue($2, OP_ENTERLOOP), $5, $7, $8));
387 parser->copline = (line_t)$1;
389 | FOR REFGEN MY remember my_var
390 { parser->in_my = 0; $<opval>$ = my($5); }
391 '(' mexpr ')' mblock cont
397 newUNOP(OP_REFGEN, 0,
402 parser->copline = (line_t)$1;
404 | FOR REFGEN refgen_topic '(' remember mexpr ')' mblock cont
406 $$ = block_end($5, newFOROP(
407 0, op_lvalue(newUNOP(OP_REFGEN, 0,
409 OP_ENTERLOOP), $6, $8, $9));
410 parser->copline = (line_t)$1;
412 | FOR '(' remember mexpr ')' mblock cont
415 newFOROP(0, (OP*)NULL, $4, $6, $7));
416 parser->copline = (line_t)$1;
420 /* a block is a loop that happens once */
421 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
422 (OP*)NULL, $1, $2, 0);
424 | PACKAGE WORD WORD '{' remember
433 /* a block is a loop that happens once */
434 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
435 (OP*)NULL, block_end($5, $7), (OP*)NULL, 0);
436 if (parser->copline > (line_t)$4)
437 parser->copline = (line_t)$4;
446 parser->copline = NOLINE;
451 formline: THING formarg
455 list = op_append_elem(OP_LIST, $1, term);
460 if (parser->copline == NOLINE)
461 parser->copline = CopLINE(PL_curcop)-1;
462 else parser->copline--;
463 $$ = newSTATEOP(0, NULL,
464 op_convert_list(OP_FORMLINE, 0, list));
470 | FORMLBRACK stmtseq FORMRBRACK
471 { $$ = op_unscope($2); }
474 /* An expression which may have a side-effect */
480 { $$ = newLOGOP(OP_AND, 0, $3, $1); }
482 { $$ = newLOGOP(OP_OR, 0, $3, $1); }
484 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); }
486 { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1); }
488 { $$ = newFOROP(0, (OP*)NULL, $3, $1, (OP*)NULL);
489 parser->copline = (line_t)$2; }
491 { $$ = newWHENOP($3, op_scope($1)); }
494 /* else and elsif blocks */
499 ($2)->op_flags |= OPf_PARENS;
502 | ELSIF '(' mexpr ')' mblock else
503 { parser->copline = (line_t)$1;
505 newSTATEOP(OPf_SPECIAL,NULL,$3),
507 PL_hints |= HINT_BLOCK_SCOPE;
511 /* Continue blocks */
515 { $$ = op_scope($2); }
518 /* determine whether there are any new my declarations */
520 { $$ = (PL_min_intro_pending &&
521 PL_max_intro_pending >= PL_min_intro_pending);
524 /* Normal expression */
530 /* Boolean expression */
531 texpr : /* NULL means true */
533 (void)scan_num("1", &tmplval);
534 $$ = tmplval.opval; }
538 /* Inverted boolean expression */
540 { $$ = invert(scalar($1)); }
543 /* Expression with its own lexical scope */
545 { $$ = $1; intro_my(); }
549 { $$ = $1; intro_my(); }
553 { $$ = $1; intro_my(); }
556 formname: WORD { $$ = $1; }
557 | /* NULL */ { $$ = (OP*)NULL; }
560 startsub: /* NULL */ /* start a regular subroutine scope */
561 { $$ = start_subparse(FALSE, 0);
562 SAVEFREESV(PL_compcv); }
566 startanonsub: /* NULL */ /* start an anonymous subroutine scope */
567 { $$ = start_subparse(FALSE, CVf_ANON);
568 SAVEFREESV(PL_compcv); }
571 startformsub: /* NULL */ /* start a format subroutine scope */
572 { $$ = start_subparse(TRUE, 0);
573 SAVEFREESV(PL_compcv); }
576 /* Name of a subroutine - must be a bareword, could be special */
581 /* Subroutine prototype */
587 /* Optional list of subroutine attributes */
588 subattrlist: /* NULL */
596 /* List of attributes for a "my" variable declaration */
597 myattrlist: COLONATTR THING
603 /* Optional subroutine signature */
604 subsignature: /* NULL */ { $$ = (OP*)NULL; }
607 if (!FEATURE_SIGNATURES_IS_ENABLED)
608 Perl_croak(aTHX_ "Experimental "
609 "subroutine signatures not enabled");
610 Perl_ck_warner_d(aTHX_
611 packWARN(WARN_EXPERIMENTAL__SIGNATURES),
612 "The signatures feature is experimental");
613 $<opval>$ = parse_subsignature();
617 $$ = op_append_list(OP_LINESEQ, $<opval>2,
618 newSTATEOP(0, NULL, sawparens(newNULLLIST())));
619 parser->expect = XBLOCK;
623 /* Subroutine body - block with optional signature */
624 realsubbody: remember subsignature '{' stmtseq '}'
626 if (parser->copline > (line_t)$3)
627 parser->copline = (line_t)$3;
629 op_append_list(OP_LINESEQ, $2, $4));
633 /* Optional subroutine body, for named subroutine declaration */
634 optsubbody: realsubbody { $$ = $1; }
635 | ';' { $$ = (OP*)NULL; }
638 /* Ordinary expressions; logical combinations */
639 expr : expr ANDOP expr
640 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
642 { $$ = newLOGOP($2, 0, $1, $3); }
644 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
645 | listexpr %prec PREC_LOW
648 /* Expressions are a list of terms joined by commas */
649 listexpr: listexpr ','
654 $$ = op_append_elem(OP_LIST, $1, term);
656 | term %prec PREC_LOW
660 listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
661 { $$ = op_convert_list($1, OPf_STACKED,
662 op_prepend_elem(OP_LIST, newGVREF($1,$2), $3) );
664 | FUNC '(' indirob expr ')' /* print ($fh @args */
665 { $$ = op_convert_list($1, OPf_STACKED,
666 op_prepend_elem(OP_LIST, newGVREF($1,$3), $4) );
668 | term ARROW method '(' optexpr ')' /* $foo->bar(list) */
669 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
670 op_append_elem(OP_LIST,
671 op_prepend_elem(OP_LIST, scalar($1), $5),
672 newMETHOP(OP_METHOD, 0, $3)));
674 | term ARROW method /* $foo->bar */
675 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
676 op_append_elem(OP_LIST, scalar($1),
677 newMETHOP(OP_METHOD, 0, $3)));
679 | METHOD indirob optlistexpr /* new Class @args */
680 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
681 op_append_elem(OP_LIST,
682 op_prepend_elem(OP_LIST, $2, $3),
683 newMETHOP(OP_METHOD, 0, $1)));
685 | FUNCMETH indirob '(' optexpr ')' /* method $object (@args) */
686 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
687 op_append_elem(OP_LIST,
688 op_prepend_elem(OP_LIST, $2, $4),
689 newMETHOP(OP_METHOD, 0, $1)));
691 | LSTOP optlistexpr /* print @args */
692 { $$ = op_convert_list($1, 0, $2); }
693 | FUNC '(' optexpr ')' /* print (@args) */
694 { $$ = op_convert_list($1, 0, $3); }
695 | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */
696 { SvREFCNT_inc_simple_void(PL_compcv);
697 $<opval>$ = newANONATTRSUB($2, 0, (OP*)NULL, $3); }
698 optlistexpr %prec LSTOP /* ... @bar */
699 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
700 op_append_elem(OP_LIST,
701 op_prepend_elem(OP_LIST, $<opval>4, $5), $1));
705 /* Names of methods. May use $object->$methodname */
710 /* Some kind of subscripted expression */
711 subscripted: gelem '{' expr ';' '}' /* *main::{something} */
712 /* In this and all the hash accessors, ';' is
713 * provided by the tokeniser */
714 { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); }
715 | scalar '[' expr ']' /* $array[$element] */
716 { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3));
718 | term ARROW '[' expr ']' /* somearef->[$element] */
719 { $$ = newBINOP(OP_AELEM, 0,
720 ref(newAVREF($1),OP_RV2AV),
723 | subscripted '[' expr ']' /* $foo->[$bar]->[$baz] */
724 { $$ = newBINOP(OP_AELEM, 0,
725 ref(newAVREF($1),OP_RV2AV),
728 | scalar '{' expr ';' '}' /* $foo{bar();} */
729 { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
731 | term ARROW '{' expr ';' '}' /* somehref->{bar();} */
732 { $$ = newBINOP(OP_HELEM, 0,
733 ref(newHVREF($1),OP_RV2HV),
735 | subscripted '{' expr ';' '}' /* $foo->[bar]->{baz;} */
736 { $$ = newBINOP(OP_HELEM, 0,
737 ref(newHVREF($1),OP_RV2HV),
739 | term ARROW '(' ')' /* $subref->() */
740 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
741 newCVREF(0, scalar($1))); }
742 | term ARROW '(' expr ')' /* $subref->(@args) */
743 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
744 op_append_elem(OP_LIST, $4,
745 newCVREF(0, scalar($1)))); }
747 | subscripted '(' expr ')' /* $foo->{bar}->(@args) */
748 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
749 op_append_elem(OP_LIST, $3,
750 newCVREF(0, scalar($1)))); }
751 | subscripted '(' ')' /* $foo->{bar}->() */
752 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
753 newCVREF(0, scalar($1))); }
754 | '(' expr ')' '[' expr ']' /* list slice */
755 { $$ = newSLICEOP(0, $5, $2); }
756 | QWLIST '[' expr ']' /* list literal slice */
757 { $$ = newSLICEOP(0, $3, $1); }
758 | '(' ')' '[' expr ']' /* empty list slice! */
759 { $$ = newSLICEOP(0, $4, (OP*)NULL); }
762 /* Binary operators between terms */
763 termbinop: term ASSIGNOP term /* $x = $y */
764 { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); }
765 | term POWOP term /* $x ** $y */
766 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
767 | term MULOP term /* $x * $y, $x x $y */
768 { if ($2 != OP_REPEAT)
770 $$ = newBINOP($2, 0, $1, scalar($3));
772 | term ADDOP term /* $x + $y */
773 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
774 | term SHIFTOP term /* $x >> $y, $x << $y */
775 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
776 | term RELOP term /* $x > $y, etc. */
777 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
778 | term EQOP term /* $x == $y, $x eq $y */
779 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
780 | term BITANDOP term /* $x & $y */
781 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
782 | term BITOROP term /* $x | $y */
783 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
784 | term DOTDOT term /* $x..$y, $x...$y */
785 { $$ = newRANGE($2, scalar($1), scalar($3)); }
786 | term ANDAND term /* $x && $y */
787 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
788 | term OROR term /* $x || $y */
789 { $$ = newLOGOP(OP_OR, 0, $1, $3); }
790 | term DORDOR term /* $x // $y */
791 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
792 | term MATCHOP term /* $x =~ /$y/ */
793 { $$ = bind_match($2, $1, $3); }
796 /* Unary operators and terms */
797 termunop : '-' term %prec UMINUS /* -$x */
798 { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); }
799 | '+' term %prec UMINUS /* +$x */
803 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
805 { $$ = newUNOP(OP_COMPLEMENT, 0, scalar($2)); }
806 | term POSTINC /* $x++ */
807 { $$ = newUNOP(OP_POSTINC, 0,
808 op_lvalue(scalar($1), OP_POSTINC)); }
809 | term POSTDEC /* $x-- */
810 { $$ = newUNOP(OP_POSTDEC, 0,
811 op_lvalue(scalar($1), OP_POSTDEC));}
812 | term POSTJOIN /* implicit join after interpolated ->@ */
813 { $$ = op_convert_list(OP_JOIN, 0,
823 | PREINC term /* ++$x */
824 { $$ = newUNOP(OP_PREINC, 0,
825 op_lvalue(scalar($2), OP_PREINC)); }
826 | PREDEC term /* --$x */
827 { $$ = newUNOP(OP_PREDEC, 0,
828 op_lvalue(scalar($2), OP_PREDEC)); }
832 /* Constructors for anonymous data */
833 anonymous: '[' expr ']'
834 { $$ = newANONLIST($2); }
836 { $$ = newANONLIST((OP*)NULL);}
837 | HASHBRACK expr ';' '}' %prec '(' /* { foo => "Bar" } */
838 { $$ = newANONHASH($2); }
839 | HASHBRACK ';' '}' %prec '(' /* { } (';' by tokener) */
840 { $$ = newANONHASH((OP*)NULL); }
841 | ANONSUB startanonsub proto subattrlist realsubbody %prec '('
842 { SvREFCNT_inc_simple_void(PL_compcv);
843 $$ = newANONATTRSUB($2, $3, $4, $5); }
847 /* Things called with "do" */
848 termdo : DO term %prec UNIOP /* do $filename */
849 { $$ = dofile($2, $1);}
850 | DO block %prec '(' /* do { code */
851 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($2));}
858 | term '?' term ':' term
859 { $$ = newCONDOP(0, $1, $3, $5); }
860 | REFGEN term /* \$x, \@y, \%z */
861 { $$ = newUNOP(OP_REFGEN, 0, op_lvalue($2,OP_REFGEN)); }
862 | myattrterm %prec UNIOP
864 | LOCAL term %prec UNIOP
865 { $$ = localize($2,$1); }
867 { $$ = sawparens($2); }
871 { $$ = sawparens(newNULLLIST()); }
880 | arylen %prec '(' /* $#x, $#{ something } */
881 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
884 | sliceme '[' expr ']' /* array slice */
885 { $$ = op_prepend_elem(OP_ASLICE,
886 newOP(OP_PUSHMARK, 0),
887 newLISTOP(OP_ASLICE, 0,
889 ref($1, OP_ASLICE)));
892 $1->op_private & OPpSLICEWARNING;
894 | kvslice '[' expr ']' /* array key/value slice */
895 { $$ = op_prepend_elem(OP_KVASLICE,
896 newOP(OP_PUSHMARK, 0),
897 newLISTOP(OP_KVASLICE, 0,
899 ref(oopsAV($1), OP_KVASLICE)));
902 $1->op_private & OPpSLICEWARNING;
904 | sliceme '{' expr ';' '}' /* @hash{@keys} */
905 { $$ = op_prepend_elem(OP_HSLICE,
906 newOP(OP_PUSHMARK, 0),
907 newLISTOP(OP_HSLICE, 0,
909 ref(oopsHV($1), OP_HSLICE)));
912 $1->op_private & OPpSLICEWARNING;
914 | kvslice '{' expr ';' '}' /* %hash{@keys} */
915 { $$ = op_prepend_elem(OP_KVHSLICE,
916 newOP(OP_PUSHMARK, 0),
917 newLISTOP(OP_KVHSLICE, 0,
919 ref($1, OP_KVHSLICE)));
922 $1->op_private & OPpSLICEWARNING;
927 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
928 | amper '(' ')' /* &foo() or foo() */
929 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1));
931 | amper '(' expr ')' /* &foo(@args) or foo(@args) */
933 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
934 op_append_elem(OP_LIST, $3, scalar($1)));
936 | NOAMP subname optlistexpr /* foo @args (no parens) */
937 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
938 op_append_elem(OP_LIST, $3, scalar($2)));
941 { $$ = newSVREF($1); }
943 { $$ = newAVREF($1); }
945 { $$ = newHVREF($1); }
947 { $$ = newUNOP(OP_ENTERSUB, 0,
948 scalar(newCVREF($3,$1))); }
949 | term ARROW '*' '*' %prec '('
950 { $$ = newGVREF(0,$1); }
951 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
952 { $$ = newOP($1, OPf_SPECIAL);
953 PL_hints |= HINT_BLOCK_SCOPE; }
955 { $$ = newLOOPEX($1,$2); }
956 | NOTOP listexpr /* not $foo */
957 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
958 | UNIOP /* Unary op, $_ implied */
959 { $$ = newOP($1, 0); }
960 | UNIOP block /* eval { foo }* */
961 { $$ = newUNOP($1, 0, $2); }
962 | UNIOP term /* Unary op */
963 { $$ = newUNOP($1, 0, $2); }
964 | REQUIRE /* require, $_ implied */
965 { $$ = newOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0); }
966 | REQUIRE term /* require Foo */
967 { $$ = newUNOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0, $2); }
969 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
970 | UNIOPSUB term /* Sub treated as unop */
971 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
972 op_append_elem(OP_LIST, $2, scalar($1))); }
973 | FUNC0 /* Nullary operator */
974 { $$ = newOP($1, 0); }
976 { $$ = newOP($1, 0);}
977 | FUNC0OP /* Same as above, but op created in toke.c */
981 | FUNC0SUB /* Sub treated as nullop */
982 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
983 | FUNC1 '(' ')' /* not () */
984 { $$ = ($1 == OP_NOT)
985 ? newUNOP($1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
986 : newOP($1, OPf_SPECIAL); }
987 | FUNC1 '(' expr ')' /* not($foo) */
988 { $$ = newUNOP($1, 0, $3); }
989 | PMFUNC /* m//, s///, qr//, tr/// */
991 if ( $1->op_type != OP_TRANS
992 && $1->op_type != OP_TRANSR
993 && (((PMOP*)$1)->op_pmflags & PMf_HAS_CV))
995 $<ival>$ = start_subparse(FALSE, CVf_ANON);
996 SAVEFREESV(PL_compcv);
1001 { $$ = pmruntime($1, $4, 1, $<ival>2); }
1006 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
1007 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
1012 /* "my" declarations, with optional attributes */
1013 myattrterm: MY myterm myattrlist
1014 { $$ = my_attrs($2,$3); }
1016 { $$ = localize($2,$1); }
1019 /* Things that can be "my"'d */
1020 myterm : '(' expr ')'
1021 { $$ = sawparens($2); }
1023 { $$ = sawparens(newNULLLIST()); }
1033 /* Basic list expressions */
1034 optlistexpr: /* NULL */ %prec PREC_LOW
1036 | listexpr %prec PREC_LOW
1046 /* A little bit of trickery to make "for my $foo (@bar)" actually be
1049 { parser->in_my = 0; $$ = my($1); }
1057 refgen_topic: my_var
1062 { $$ = newCVREF($1,$2); }
1065 scalar : '$' indirob
1066 { $$ = newSVREF($2); }
1070 { $$ = newAVREF($2);
1071 if ($$) $$->op_private |= $1;
1076 { $$ = newHVREF($2);
1077 if ($$) $$->op_private |= $1;
1081 arylen : DOLSHARP indirob
1082 { $$ = newAVREF($2); }
1083 | term ARROW DOLSHARP '*'
1084 { $$ = newAVREF($1); }
1088 { $$ = newGVREF(0,$2); }
1093 { $$ = newAVREF($1); }
1098 { $$ = newHVREF($1); }
1103 { $$ = newGVREF(0,$1); }
1106 /* Indirect objects */
1108 { $$ = scalar($1); }
1109 | scalar %prec PREC_LOW
1110 { $$ = scalar($1); }
1112 { $$ = op_scope($1); }