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); }
200 mblock : '{' mremember stmtseq '}'
201 { if (parser->copline > (line_t)$1)
202 parser->copline = (line_t)$1;
203 $$ = block_end($2, $3);
207 mremember: /* NULL */ /* start a partial lexical scope */
208 { $$ = block_start(FALSE); }
211 /* A sequence of statements in the program */
215 { $$ = op_append_list(OP_LINESEQ, $1, $2);
216 PL_pad_reset_pending = TRUE;
218 PL_hints |= HINT_BLOCK_SCOPE;
222 /* A sequence of format lines */
223 formstmtseq: /* NULL */
225 | formstmtseq formline
226 { $$ = op_append_list(OP_LINESEQ, $1, $2);
227 PL_pad_reset_pending = TRUE;
229 PL_hints |= HINT_BLOCK_SCOPE;
233 /* A statement in the program, including optional labels */
236 $$ = $1 ? newSTATEOP(0, NULL, $1) : NULL;
242 labfullstmt: LABEL barestmt
244 $$ = newSTATEOP(SVf_UTF8 * $1[strlen($1)+1], $1, $2);
248 $$ = newSTATEOP(SVf_UTF8 * $1[strlen($1)+1], $1, $2);
252 /* A bare statement, lacking label and other aspects of state op */
255 | FORMAT startformsub formname formblock
257 CV *fmtcv = PL_compcv;
260 if (CvOUTSIDE(fmtcv) && !CvEVAL(CvOUTSIDE(fmtcv))) {
261 SvREFCNT_inc_simple_void(fmtcv);
262 pad_add_anon(fmtcv, OP_NULL);
265 | SUB subname startsub
267 if ($2->op_type == OP_CONST) {
268 const char *const name =
269 SvPV_nolen_const(((SVOP*)$2)->op_sv);
270 if (strEQ(name, "BEGIN") || strEQ(name, "END")
271 || strEQ(name, "INIT") || strEQ(name, "CHECK")
272 || strEQ(name, "UNITCHECK"))
273 CvSPECIAL_on(PL_compcv);
276 /* State subs inside anonymous subs need to be
277 clonable themselves. */
278 if (CvANON(CvOUTSIDE(PL_compcv))
279 || CvCLONE(CvOUTSIDE(PL_compcv))
280 || !PadnameIsSTATE(PadlistNAMESARRAY(CvPADLIST(
283 CvCLONE_on(PL_compcv);
285 parser->in_my_stash = NULL;
287 proto subattrlist optsubbody
289 SvREFCNT_inc_simple_void(PL_compcv);
290 $2->op_type == OP_CONST
291 ? newATTRSUB($3, $2, $5, $6, $7)
292 : newMYSUB($3, $2, $5, $6, $7)
297 | PACKAGE WORD WORD ';'
305 { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
306 WORD WORD optlistexpr ';'
308 SvREFCNT_inc_simple_void(PL_compcv);
309 utilize($1, $2, $4, $5, $6);
312 | IF '(' remember mexpr ')' mblock else
315 newCONDOP(0, $4, op_scope($6), $7));
316 parser->copline = (line_t)$1;
318 | UNLESS '(' remember miexpr ')' mblock else
321 newCONDOP(0, $4, op_scope($6), $7));
322 parser->copline = (line_t)$1;
324 | GIVEN '(' remember mexpr ')' mblock
326 const PADOFFSET offset = pad_findmy_pvs("$_", 0);
328 newGIVENOP($4, op_scope($6),
330 || PAD_COMPNAME_FLAGS_isOUR(offset)
333 parser->copline = (line_t)$1;
335 | WHEN '(' remember mexpr ')' mblock
336 { $$ = block_end($3, newWHENOP($4, op_scope($6))); }
338 { $$ = newWHENOP(0, op_scope($2)); }
339 | WHILE '(' remember texpr ')' mintro mblock cont
342 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
344 parser->copline = (line_t)$1;
346 | UNTIL '(' remember iexpr ')' mintro mblock cont
349 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
351 parser->copline = (line_t)$1;
353 | FOR '(' remember mnexpr ';'
354 { parser->expect = XTERM; }
356 { parser->expect = XTERM; }
361 OP *forop = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
362 scalar($7), $13, $11, $10);
364 forop = op_prepend_elem(OP_LINESEQ, initop,
365 op_append_elem(OP_LINESEQ,
366 newOP(OP_UNSTACK, OPf_SPECIAL),
369 $$ = block_end($3, forop);
370 parser->copline = (line_t)$1;
372 | FOR MY remember my_scalar '(' mexpr ')' mblock cont
374 $$ = block_end($3, newFOROP(0, $4, $6, $8, $9));
375 parser->copline = (line_t)$1;
377 | FOR scalar '(' remember mexpr ')' mblock cont
379 $$ = block_end($4, newFOROP(0,
380 op_lvalue($2, OP_ENTERLOOP), $5, $7, $8));
381 parser->copline = (line_t)$1;
383 | FOR REFGEN MY remember my_var
384 { parser->in_my = 0; $<opval>$ = my($5); }
385 '(' mexpr ')' mblock cont
391 newUNOP(OP_REFGEN, 0,
396 parser->copline = (line_t)$1;
398 | FOR REFGEN refgen_topic '(' remember mexpr ')' mblock cont
400 $$ = block_end($5, newFOROP(
401 0, op_lvalue(newUNOP(OP_REFGEN, 0,
403 OP_ENTERLOOP), $6, $8, $9));
404 parser->copline = (line_t)$1;
406 | FOR '(' remember mexpr ')' mblock cont
409 newFOROP(0, (OP*)NULL, $4, $6, $7));
410 parser->copline = (line_t)$1;
414 /* a block is a loop that happens once */
415 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
416 (OP*)NULL, $1, $2, 0);
418 | PACKAGE WORD WORD '{' remember
427 /* a block is a loop that happens once */
428 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
429 (OP*)NULL, block_end($5, $7), (OP*)NULL, 0);
430 if (parser->copline > (line_t)$4)
431 parser->copline = (line_t)$4;
440 parser->copline = NOLINE;
445 formline: THING formarg
449 list = op_append_elem(OP_LIST, $1, term);
454 if (parser->copline == NOLINE)
455 parser->copline = CopLINE(PL_curcop)-1;
456 else parser->copline--;
457 $$ = newSTATEOP(0, NULL,
458 op_convert_list(OP_FORMLINE, 0, list));
464 | FORMLBRACK stmtseq FORMRBRACK
465 { $$ = op_unscope($2); }
468 /* An expression which may have a side-effect */
474 { $$ = newLOGOP(OP_AND, 0, $3, $1); }
476 { $$ = newLOGOP(OP_OR, 0, $3, $1); }
478 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); }
480 { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1); }
482 { $$ = newFOROP(0, (OP*)NULL, $3, $1, (OP*)NULL);
483 parser->copline = (line_t)$2; }
485 { $$ = newWHENOP($3, op_scope($1)); }
488 /* else and elsif blocks */
493 ($2)->op_flags |= OPf_PARENS;
496 | ELSIF '(' mexpr ')' mblock else
497 { parser->copline = (line_t)$1;
499 newSTATEOP(OPf_SPECIAL,NULL,$3),
501 PL_hints |= HINT_BLOCK_SCOPE;
505 /* Continue blocks */
509 { $$ = op_scope($2); }
512 /* determine whether there are any new my declarations */
514 { $$ = (PL_min_intro_pending &&
515 PL_max_intro_pending >= PL_min_intro_pending);
518 /* Normal expression */
524 /* Boolean expression */
525 texpr : /* NULL means true */
527 (void)scan_num("1", &tmplval);
528 $$ = tmplval.opval; }
532 /* Inverted boolean expression */
534 { $$ = invert(scalar($1)); }
537 /* Expression with its own lexical scope */
539 { $$ = $1; intro_my(); }
543 { $$ = $1; intro_my(); }
547 { $$ = $1; intro_my(); }
550 formname: WORD { $$ = $1; }
551 | /* NULL */ { $$ = (OP*)NULL; }
554 startsub: /* NULL */ /* start a regular subroutine scope */
555 { $$ = start_subparse(FALSE, 0);
556 SAVEFREESV(PL_compcv); }
560 startanonsub: /* NULL */ /* start an anonymous subroutine scope */
561 { $$ = start_subparse(FALSE, CVf_ANON);
562 SAVEFREESV(PL_compcv); }
565 startformsub: /* NULL */ /* start a format subroutine scope */
566 { $$ = start_subparse(TRUE, 0);
567 SAVEFREESV(PL_compcv); }
570 /* Name of a subroutine - must be a bareword, could be special */
575 /* Subroutine prototype */
581 /* Optional list of subroutine attributes */
582 subattrlist: /* NULL */
590 /* List of attributes for a "my" variable declaration */
591 myattrlist: COLONATTR THING
597 /* Optional subroutine signature */
598 subsignature: /* NULL */ { $$ = (OP*)NULL; }
601 if (!FEATURE_SIGNATURES_IS_ENABLED)
602 Perl_croak(aTHX_ "Experimental "
603 "subroutine signatures not enabled");
604 Perl_ck_warner_d(aTHX_
605 packWARN(WARN_EXPERIMENTAL__SIGNATURES),
606 "The signatures feature is experimental");
607 $<opval>$ = parse_subsignature();
611 $$ = op_append_list(OP_LINESEQ, $<opval>2,
612 newSTATEOP(0, NULL, sawparens(newNULLLIST())));
613 parser->expect = XBLOCK;
617 /* Subroutine body - block with optional signature */
618 realsubbody: remember subsignature '{' stmtseq '}'
620 if (parser->copline > (line_t)$3)
621 parser->copline = (line_t)$3;
623 op_append_list(OP_LINESEQ, $2, $4));
627 /* Optional subroutine body, for named subroutine declaration */
628 optsubbody: realsubbody { $$ = $1; }
629 | ';' { $$ = (OP*)NULL; }
632 /* Ordinary expressions; logical combinations */
633 expr : expr ANDOP expr
634 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
636 { $$ = newLOGOP($2, 0, $1, $3); }
638 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
639 | listexpr %prec PREC_LOW
642 /* Expressions are a list of terms joined by commas */
643 listexpr: listexpr ','
648 $$ = op_append_elem(OP_LIST, $1, term);
650 | term %prec PREC_LOW
654 listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
655 { $$ = op_convert_list($1, OPf_STACKED,
656 op_prepend_elem(OP_LIST, newGVREF($1,$2), $3) );
658 | FUNC '(' indirob expr ')' /* print ($fh @args */
659 { $$ = op_convert_list($1, OPf_STACKED,
660 op_prepend_elem(OP_LIST, newGVREF($1,$3), $4) );
662 | term ARROW method '(' optexpr ')' /* $foo->bar(list) */
663 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
664 op_append_elem(OP_LIST,
665 op_prepend_elem(OP_LIST, scalar($1), $5),
666 newMETHOP(OP_METHOD, 0, $3)));
668 | term ARROW method /* $foo->bar */
669 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
670 op_append_elem(OP_LIST, scalar($1),
671 newMETHOP(OP_METHOD, 0, $3)));
673 | METHOD indirob optlistexpr /* new Class @args */
674 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
675 op_append_elem(OP_LIST,
676 op_prepend_elem(OP_LIST, $2, $3),
677 newMETHOP(OP_METHOD, 0, $1)));
679 | FUNCMETH indirob '(' optexpr ')' /* method $object (@args) */
680 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
681 op_append_elem(OP_LIST,
682 op_prepend_elem(OP_LIST, $2, $4),
683 newMETHOP(OP_METHOD, 0, $1)));
685 | LSTOP optlistexpr /* print @args */
686 { $$ = op_convert_list($1, 0, $2); }
687 | FUNC '(' optexpr ')' /* print (@args) */
688 { $$ = op_convert_list($1, 0, $3); }
689 | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */
690 { SvREFCNT_inc_simple_void(PL_compcv);
691 $<opval>$ = newANONATTRSUB($2, 0, (OP*)NULL, $3); }
692 optlistexpr %prec LSTOP /* ... @bar */
693 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
694 op_append_elem(OP_LIST,
695 op_prepend_elem(OP_LIST, $<opval>4, $5), $1));
699 /* Names of methods. May use $object->$methodname */
704 /* Some kind of subscripted expression */
705 subscripted: gelem '{' expr ';' '}' /* *main::{something} */
706 /* In this and all the hash accessors, ';' is
707 * provided by the tokeniser */
708 { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); }
709 | scalar '[' expr ']' /* $array[$element] */
710 { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3));
712 | term ARROW '[' expr ']' /* somearef->[$element] */
713 { $$ = newBINOP(OP_AELEM, 0,
714 ref(newAVREF($1),OP_RV2AV),
717 | subscripted '[' expr ']' /* $foo->[$bar]->[$baz] */
718 { $$ = newBINOP(OP_AELEM, 0,
719 ref(newAVREF($1),OP_RV2AV),
722 | scalar '{' expr ';' '}' /* $foo{bar();} */
723 { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
725 | term ARROW '{' expr ';' '}' /* somehref->{bar();} */
726 { $$ = newBINOP(OP_HELEM, 0,
727 ref(newHVREF($1),OP_RV2HV),
729 | subscripted '{' expr ';' '}' /* $foo->[bar]->{baz;} */
730 { $$ = newBINOP(OP_HELEM, 0,
731 ref(newHVREF($1),OP_RV2HV),
733 | term ARROW '(' ')' /* $subref->() */
734 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
735 newCVREF(0, scalar($1))); }
736 | term ARROW '(' expr ')' /* $subref->(@args) */
737 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
738 op_append_elem(OP_LIST, $4,
739 newCVREF(0, scalar($1)))); }
741 | subscripted '(' expr ')' /* $foo->{bar}->(@args) */
742 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
743 op_append_elem(OP_LIST, $3,
744 newCVREF(0, scalar($1)))); }
745 | subscripted '(' ')' /* $foo->{bar}->() */
746 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
747 newCVREF(0, scalar($1))); }
748 | '(' expr ')' '[' expr ']' /* list slice */
749 { $$ = newSLICEOP(0, $5, $2); }
750 | QWLIST '[' expr ']' /* list literal slice */
751 { $$ = newSLICEOP(0, $3, $1); }
752 | '(' ')' '[' expr ']' /* empty list slice! */
753 { $$ = newSLICEOP(0, $4, (OP*)NULL); }
756 /* Binary operators between terms */
757 termbinop: term ASSIGNOP term /* $x = $y */
758 { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); }
759 | term POWOP term /* $x ** $y */
760 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
761 | term MULOP term /* $x * $y, $x x $y */
762 { if ($2 != OP_REPEAT)
764 $$ = newBINOP($2, 0, $1, scalar($3));
766 | term ADDOP term /* $x + $y */
767 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
768 | term SHIFTOP term /* $x >> $y, $x << $y */
769 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
770 | term RELOP term /* $x > $y, etc. */
771 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
772 | term EQOP term /* $x == $y, $x eq $y */
773 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
774 | term BITANDOP term /* $x & $y */
775 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
776 | term BITOROP term /* $x | $y */
777 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
778 | term DOTDOT term /* $x..$y, $x...$y */
779 { $$ = newRANGE($2, scalar($1), scalar($3)); }
780 | term ANDAND term /* $x && $y */
781 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
782 | term OROR term /* $x || $y */
783 { $$ = newLOGOP(OP_OR, 0, $1, $3); }
784 | term DORDOR term /* $x // $y */
785 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
786 | term MATCHOP term /* $x =~ /$y/ */
787 { $$ = bind_match($2, $1, $3); }
790 /* Unary operators and terms */
791 termunop : '-' term %prec UMINUS /* -$x */
792 { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); }
793 | '+' term %prec UMINUS /* +$x */
797 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
799 { $$ = newUNOP(OP_COMPLEMENT, 0, scalar($2)); }
800 | term POSTINC /* $x++ */
801 { $$ = newUNOP(OP_POSTINC, 0,
802 op_lvalue(scalar($1), OP_POSTINC)); }
803 | term POSTDEC /* $x-- */
804 { $$ = newUNOP(OP_POSTDEC, 0,
805 op_lvalue(scalar($1), OP_POSTDEC));}
806 | term POSTJOIN /* implicit join after interpolated ->@ */
807 { $$ = op_convert_list(OP_JOIN, 0,
817 | PREINC term /* ++$x */
818 { $$ = newUNOP(OP_PREINC, 0,
819 op_lvalue(scalar($2), OP_PREINC)); }
820 | PREDEC term /* --$x */
821 { $$ = newUNOP(OP_PREDEC, 0,
822 op_lvalue(scalar($2), OP_PREDEC)); }
826 /* Constructors for anonymous data */
827 anonymous: '[' expr ']'
828 { $$ = newANONLIST($2); }
830 { $$ = newANONLIST((OP*)NULL);}
831 | HASHBRACK expr ';' '}' %prec '(' /* { foo => "Bar" } */
832 { $$ = newANONHASH($2); }
833 | HASHBRACK ';' '}' %prec '(' /* { } (';' by tokener) */
834 { $$ = newANONHASH((OP*)NULL); }
835 | ANONSUB startanonsub proto subattrlist realsubbody %prec '('
836 { SvREFCNT_inc_simple_void(PL_compcv);
837 $$ = newANONATTRSUB($2, $3, $4, $5); }
841 /* Things called with "do" */
842 termdo : DO term %prec UNIOP /* do $filename */
843 { $$ = dofile($2, $1);}
844 | DO block %prec '(' /* do { code */
845 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($2));}
852 | term '?' term ':' term
853 { $$ = newCONDOP(0, $1, $3, $5); }
854 | REFGEN term /* \$x, \@y, \%z */
855 { $$ = newUNOP(OP_REFGEN, 0, op_lvalue($2,OP_REFGEN)); }
856 | myattrterm %prec UNIOP
858 | LOCAL term %prec UNIOP
859 { $$ = localize($2,$1); }
861 { $$ = sawparens($2); }
865 { $$ = sawparens(newNULLLIST()); }
874 | arylen %prec '(' /* $#x, $#{ something } */
875 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
878 | sliceme '[' expr ']' /* array slice */
879 { $$ = op_prepend_elem(OP_ASLICE,
880 newOP(OP_PUSHMARK, 0),
881 newLISTOP(OP_ASLICE, 0,
883 ref($1, OP_ASLICE)));
886 $1->op_private & OPpSLICEWARNING;
888 | kvslice '[' expr ']' /* array key/value slice */
889 { $$ = op_prepend_elem(OP_KVASLICE,
890 newOP(OP_PUSHMARK, 0),
891 newLISTOP(OP_KVASLICE, 0,
893 ref(oopsAV($1), OP_KVASLICE)));
896 $1->op_private & OPpSLICEWARNING;
898 | sliceme '{' expr ';' '}' /* @hash{@keys} */
899 { $$ = op_prepend_elem(OP_HSLICE,
900 newOP(OP_PUSHMARK, 0),
901 newLISTOP(OP_HSLICE, 0,
903 ref(oopsHV($1), OP_HSLICE)));
906 $1->op_private & OPpSLICEWARNING;
908 | kvslice '{' expr ';' '}' /* %hash{@keys} */
909 { $$ = op_prepend_elem(OP_KVHSLICE,
910 newOP(OP_PUSHMARK, 0),
911 newLISTOP(OP_KVHSLICE, 0,
913 ref($1, OP_KVHSLICE)));
916 $1->op_private & OPpSLICEWARNING;
921 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
922 | amper '(' ')' /* &foo() or foo() */
923 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1));
925 | amper '(' expr ')' /* &foo(@args) or foo(@args) */
927 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
928 op_append_elem(OP_LIST, $3, scalar($1)));
930 | NOAMP subname optlistexpr /* foo @args (no parens) */
931 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
932 op_append_elem(OP_LIST, $3, scalar($2)));
935 { $$ = newSVREF($1); }
937 { $$ = newAVREF($1); }
939 { $$ = newHVREF($1); }
941 { $$ = newUNOP(OP_ENTERSUB, 0,
942 scalar(newCVREF($3,$1))); }
943 | term ARROW '*' '*' %prec '('
944 { $$ = newGVREF(0,$1); }
945 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
946 { $$ = newOP($1, OPf_SPECIAL);
947 PL_hints |= HINT_BLOCK_SCOPE; }
949 { $$ = newLOOPEX($1,$2); }
950 | NOTOP listexpr /* not $foo */
951 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
952 | UNIOP /* Unary op, $_ implied */
953 { $$ = newOP($1, 0); }
954 | UNIOP block /* eval { foo }* */
955 { $$ = newUNOP($1, 0, $2); }
956 | UNIOP term /* Unary op */
957 { $$ = newUNOP($1, 0, $2); }
958 | REQUIRE /* require, $_ implied */
959 { $$ = newOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0); }
960 | REQUIRE term /* require Foo */
961 { $$ = newUNOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0, $2); }
963 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
964 | UNIOPSUB term /* Sub treated as unop */
965 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
966 op_append_elem(OP_LIST, $2, scalar($1))); }
967 | FUNC0 /* Nullary operator */
968 { $$ = newOP($1, 0); }
970 { $$ = newOP($1, 0);}
971 | FUNC0OP /* Same as above, but op created in toke.c */
975 | FUNC0SUB /* Sub treated as nullop */
976 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
977 | FUNC1 '(' ')' /* not () */
978 { $$ = ($1 == OP_NOT)
979 ? newUNOP($1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
980 : newOP($1, OPf_SPECIAL); }
981 | FUNC1 '(' expr ')' /* not($foo) */
982 { $$ = newUNOP($1, 0, $3); }
983 | PMFUNC /* m//, s///, qr//, tr/// */
985 if ( $1->op_type != OP_TRANS
986 && $1->op_type != OP_TRANSR
987 && (((PMOP*)$1)->op_pmflags & PMf_HAS_CV))
989 $<ival>$ = start_subparse(FALSE, CVf_ANON);
990 SAVEFREESV(PL_compcv);
995 { $$ = pmruntime($1, $4, 1, $<ival>2); }
1000 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
1001 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
1006 /* "my" declarations, with optional attributes */
1007 myattrterm: MY myterm myattrlist
1008 { $$ = my_attrs($2,$3); }
1010 { $$ = localize($2,$1); }
1013 /* Things that can be "my"'d */
1014 myterm : '(' expr ')'
1015 { $$ = sawparens($2); }
1017 { $$ = sawparens(newNULLLIST()); }
1027 /* Basic list expressions */
1028 optlistexpr: /* NULL */ %prec PREC_LOW
1030 | listexpr %prec PREC_LOW
1040 /* A little bit of trickery to make "for my $foo (@bar)" actually be
1043 { parser->in_my = 0; $$ = my($1); }
1051 refgen_topic: my_var
1056 { $$ = newCVREF($1,$2); }
1059 scalar : '$' indirob
1060 { $$ = newSVREF($2); }
1064 { $$ = newAVREF($2);
1065 if ($$) $$->op_private |= $1;
1070 { $$ = newHVREF($2);
1071 if ($$) $$->op_private |= $1;
1075 arylen : DOLSHARP indirob
1076 { $$ = newAVREF($2); }
1077 | term ARROW DOLSHARP '*'
1078 { $$ = newAVREF($1); }
1082 { $$ = newGVREF(0,$2); }
1087 { $$ = newAVREF($1); }
1092 { $$ = newHVREF($1); }
1097 { $$ = newGVREF(0,$1); }
1100 /* Indirect objects */
1102 { $$ = scalar($1); }
1103 | scalar %prec PREC_LOW
1104 { $$ = scalar($1); }
1106 { $$ = op_scope($1); }