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));
125 parser->expect = XTERM;
134 parser->expect = XBLOCK;
138 PL_pad_reset_pending = TRUE;
142 parser->yychar = YYEOF;
146 parser->expect = XSTATE;
150 PL_pad_reset_pending = TRUE;
154 parser->yychar = YYEOF;
158 parser->expect = XSTATE;
162 PL_pad_reset_pending = TRUE;
166 parser->yychar = YYEOF;
170 parser->expect = XSTATE;
179 /* An ordinary block */
180 block : '{' remember stmtseq '}'
181 { if (parser->copline > (line_t)$1)
182 parser->copline = (line_t)$1;
183 $$ = block_end($2, $3);
188 formblock: '=' remember ';' FORMRBRACK formstmtseq ';' '.'
189 { if (parser->copline > (line_t)$1)
190 parser->copline = (line_t)$1;
191 $$ = block_end($2, $5);
195 remember: /* NULL */ /* start a full lexical scope */
196 { $$ = block_start(TRUE); }
199 mblock : '{' mremember stmtseq '}'
200 { if (parser->copline > (line_t)$1)
201 parser->copline = (line_t)$1;
202 $$ = block_end($2, $3);
206 mremember: /* NULL */ /* start a partial lexical scope */
207 { $$ = block_start(FALSE); }
210 /* A sequence of statements in the program */
214 { $$ = op_append_list(OP_LINESEQ, $1, $2);
215 PL_pad_reset_pending = TRUE;
217 PL_hints |= HINT_BLOCK_SCOPE;
221 /* A sequence of format lines */
222 formstmtseq: /* NULL */
224 | formstmtseq formline
225 { $$ = op_append_list(OP_LINESEQ, $1, $2);
226 PL_pad_reset_pending = TRUE;
228 PL_hints |= HINT_BLOCK_SCOPE;
232 /* A statement in the program, including optional labels */
235 $$ = $1 ? newSTATEOP(0, NULL, $1) : NULL;
241 labfullstmt: LABEL barestmt
243 $$ = newSTATEOP(SVf_UTF8 * $1[strlen($1)+1], $1, $2);
247 $$ = newSTATEOP(SVf_UTF8 * $1[strlen($1)+1], $1, $2);
251 /* A bare statement, lacking label and other aspects of state op */
254 | FORMAT startformsub formname formblock
256 CV *fmtcv = PL_compcv;
259 if (CvOUTSIDE(fmtcv) && !CvEVAL(CvOUTSIDE(fmtcv))) {
260 SvREFCNT_inc_simple_void(fmtcv);
261 pad_add_anon(fmtcv, OP_NULL);
264 | SUB subname startsub
266 if ($2->op_type == OP_CONST) {
267 const char *const name =
268 SvPV_nolen_const(((SVOP*)$2)->op_sv);
269 if (strEQ(name, "BEGIN") || strEQ(name, "END")
270 || strEQ(name, "INIT") || strEQ(name, "CHECK")
271 || strEQ(name, "UNITCHECK"))
272 CvSPECIAL_on(PL_compcv);
275 /* State subs inside anonymous subs need to be
276 clonable themselves. */
277 if (CvANON(CvOUTSIDE(PL_compcv))
278 || CvCLONE(CvOUTSIDE(PL_compcv))
279 || !PadnameIsSTATE(PadlistNAMESARRAY(CvPADLIST(
282 CvCLONE_on(PL_compcv);
284 parser->in_my_stash = NULL;
286 proto subattrlist optsubbody
288 SvREFCNT_inc_simple_void(PL_compcv);
289 $2->op_type == OP_CONST
290 ? newATTRSUB($3, $2, $5, $6, $7)
291 : newMYSUB($3, $2, $5, $6, $7)
296 | PACKAGE WORD WORD ';'
304 { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
305 WORD WORD optlistexpr ';'
307 SvREFCNT_inc_simple_void(PL_compcv);
308 utilize($1, $2, $4, $5, $6);
311 | IF '(' remember mexpr ')' mblock else
314 newCONDOP(0, $4, op_scope($6), $7));
315 parser->copline = (line_t)$1;
317 | UNLESS '(' remember miexpr ')' mblock else
320 newCONDOP(0, $4, op_scope($6), $7));
321 parser->copline = (line_t)$1;
323 | GIVEN '(' remember mexpr ')' mblock
325 const PADOFFSET offset = pad_findmy_pvs("$_", 0);
327 newGIVENOP($4, op_scope($6),
329 || PAD_COMPNAME_FLAGS_isOUR(offset)
332 parser->copline = (line_t)$1;
334 | WHEN '(' remember mexpr ')' mblock
335 { $$ = block_end($3, newWHENOP($4, op_scope($6))); }
337 { $$ = newWHENOP(0, op_scope($2)); }
338 | WHILE '(' remember texpr ')' mintro mblock cont
341 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
343 parser->copline = (line_t)$1;
345 | UNTIL '(' remember iexpr ')' mintro mblock cont
348 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
350 parser->copline = (line_t)$1;
352 | FOR '(' remember mnexpr ';'
353 { parser->expect = XTERM; }
355 { parser->expect = XTERM; }
360 OP *forop = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
361 scalar($7), $13, $11, $10);
363 forop = op_prepend_elem(OP_LINESEQ, initop,
364 op_append_elem(OP_LINESEQ,
365 newOP(OP_UNSTACK, OPf_SPECIAL),
368 $$ = block_end($3, forop);
369 parser->copline = (line_t)$1;
371 | FOR MY remember my_scalar '(' mexpr ')' mblock cont
373 $$ = block_end($3, newFOROP(0, $4, $6, $8, $9));
374 parser->copline = (line_t)$1;
376 | FOR scalar '(' remember mexpr ')' mblock cont
378 $$ = block_end($4, newFOROP(0,
379 op_lvalue($2, OP_ENTERLOOP), $5, $7, $8));
380 parser->copline = (line_t)$1;
382 | FOR REFGEN MY remember my_var
383 { parser->in_my = 0; $<opval>$ = my($5); }
384 '(' mexpr ')' mblock cont
390 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,
404 OP_ENTERLOOP), $6, $8, $9));
405 parser->copline = (line_t)$1;
407 | FOR '(' remember mexpr ')' mblock cont
410 newFOROP(0, (OP*)NULL, $4, $6, $7));
411 parser->copline = (line_t)$1;
415 /* a block is a loop that happens once */
416 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
417 (OP*)NULL, $1, $2, 0);
419 | PACKAGE WORD WORD '{' remember
428 /* a block is a loop that happens once */
429 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
430 (OP*)NULL, block_end($5, $7), (OP*)NULL, 0);
431 if (parser->copline > (line_t)$4)
432 parser->copline = (line_t)$4;
441 parser->copline = NOLINE;
446 formline: THING formarg
450 list = op_append_elem(OP_LIST, $1, term);
455 if (parser->copline == NOLINE)
456 parser->copline = CopLINE(PL_curcop)-1;
457 else parser->copline--;
458 $$ = newSTATEOP(0, NULL,
459 convert(OP_FORMLINE, 0, list));
465 | FORMLBRACK stmtseq FORMRBRACK
466 { $$ = op_unscope($2); }
469 /* An expression which may have a side-effect */
475 { $$ = newLOGOP(OP_AND, 0, $3, $1); }
477 { $$ = newLOGOP(OP_OR, 0, $3, $1); }
479 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); }
481 { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1); }
483 { $$ = newFOROP(0, (OP*)NULL, $3, $1, (OP*)NULL);
484 parser->copline = (line_t)$2; }
486 { $$ = newWHENOP($3, op_scope($1)); }
489 /* else and elsif blocks */
494 ($2)->op_flags |= OPf_PARENS;
497 | ELSIF '(' mexpr ')' mblock else
498 { parser->copline = (line_t)$1;
500 newSTATEOP(OPf_SPECIAL,NULL,$3),
502 PL_hints |= HINT_BLOCK_SCOPE;
506 /* Continue blocks */
510 { $$ = op_scope($2); }
513 /* determine whether there are any new my declarations */
515 { $$ = (PL_min_intro_pending &&
516 PL_max_intro_pending >= PL_min_intro_pending);
519 /* Normal expression */
525 /* Boolean expression */
526 texpr : /* NULL means true */
528 (void)scan_num("1", &tmplval);
529 $$ = tmplval.opval; }
533 /* Inverted boolean expression */
535 { $$ = invert(scalar($1)); }
538 /* Expression with its own lexical scope */
540 { $$ = $1; intro_my(); }
544 { $$ = $1; intro_my(); }
548 { $$ = $1; intro_my(); }
551 formname: WORD { $$ = $1; }
552 | /* NULL */ { $$ = (OP*)NULL; }
555 startsub: /* NULL */ /* start a regular subroutine scope */
556 { $$ = start_subparse(FALSE, 0);
557 SAVEFREESV(PL_compcv); }
561 startanonsub: /* NULL */ /* start an anonymous subroutine scope */
562 { $$ = start_subparse(FALSE, CVf_ANON);
563 SAVEFREESV(PL_compcv); }
566 startformsub: /* NULL */ /* start a format subroutine scope */
567 { $$ = start_subparse(TRUE, 0);
568 SAVEFREESV(PL_compcv); }
571 /* Name of a subroutine - must be a bareword, could be special */
576 /* Subroutine prototype */
582 /* Optional list of subroutine attributes */
583 subattrlist: /* NULL */
591 /* List of attributes for a "my" variable declaration */
592 myattrlist: COLONATTR THING
598 /* Optional subroutine signature */
599 subsignature: /* NULL */ { $$ = (OP*)NULL; }
602 if (!FEATURE_SIGNATURES_IS_ENABLED)
603 Perl_croak(aTHX_ "Experimental "
604 "subroutine signatures not enabled");
605 Perl_ck_warner_d(aTHX_
606 packWARN(WARN_EXPERIMENTAL__SIGNATURES),
607 "The signatures feature is experimental");
608 $<opval>$ = parse_subsignature();
612 $$ = op_append_list(OP_LINESEQ, $<opval>2,
613 newSTATEOP(0, NULL, sawparens(newNULLLIST())));
614 parser->expect = XBLOCK;
618 /* Subroutine body - block with optional signature */
619 realsubbody: remember subsignature '{' stmtseq '}'
621 if (parser->copline > (line_t)$3)
622 parser->copline = (line_t)$3;
624 op_append_list(OP_LINESEQ, $2, $4));
628 /* Optional subroutine body, for named subroutine declaration */
629 optsubbody: realsubbody { $$ = $1; }
630 | ';' { $$ = (OP*)NULL; }
633 /* Ordinary expressions; logical combinations */
634 expr : expr ANDOP expr
635 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
637 { $$ = newLOGOP($2, 0, $1, $3); }
639 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
640 | listexpr %prec PREC_LOW
643 /* Expressions are a list of terms joined by commas */
644 listexpr: listexpr ','
649 $$ = op_append_elem(OP_LIST, $1, term);
651 | term %prec PREC_LOW
655 listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
656 { $$ = convert($1, OPf_STACKED,
657 op_prepend_elem(OP_LIST, newGVREF($1,$2), $3) );
659 | FUNC '(' indirob expr ')' /* print ($fh @args */
660 { $$ = convert($1, OPf_STACKED,
661 op_prepend_elem(OP_LIST, newGVREF($1,$3), $4) );
663 | term ARROW method '(' optexpr ')' /* $foo->bar(list) */
664 { $$ = convert(OP_ENTERSUB, OPf_STACKED,
665 op_append_elem(OP_LIST,
666 op_prepend_elem(OP_LIST, scalar($1), $5),
667 newMETHOP(OP_METHOD, 0, $3)));
669 | term ARROW method /* $foo->bar */
670 { $$ = convert(OP_ENTERSUB, OPf_STACKED,
671 op_append_elem(OP_LIST, scalar($1),
672 newMETHOP(OP_METHOD, 0, $3)));
674 | METHOD indirob optlistexpr /* new Class @args */
675 { $$ = convert(OP_ENTERSUB, OPf_STACKED,
676 op_append_elem(OP_LIST,
677 op_prepend_elem(OP_LIST, $2, $3),
678 newMETHOP(OP_METHOD, 0, $1)));
680 | FUNCMETH indirob '(' optexpr ')' /* method $object (@args) */
681 { $$ = convert(OP_ENTERSUB, OPf_STACKED,
682 op_append_elem(OP_LIST,
683 op_prepend_elem(OP_LIST, $2, $4),
684 newMETHOP(OP_METHOD, 0, $1)));
686 | LSTOP optlistexpr /* print @args */
687 { $$ = convert($1, 0, $2); }
688 | FUNC '(' optexpr ')' /* print (@args) */
689 { $$ = convert($1, 0, $3); }
690 | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */
691 { SvREFCNT_inc_simple_void(PL_compcv);
692 $<opval>$ = newANONATTRSUB($2, 0, (OP*)NULL, $3); }
693 optlistexpr %prec LSTOP /* ... @bar */
694 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
695 op_append_elem(OP_LIST,
696 op_prepend_elem(OP_LIST, $<opval>4, $5), $1));
700 /* Names of methods. May use $object->$methodname */
705 /* Some kind of subscripted expression */
706 subscripted: gelem '{' expr ';' '}' /* *main::{something} */
707 /* In this and all the hash accessors, ';' is
708 * provided by the tokeniser */
709 { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); }
710 | scalar '[' expr ']' /* $array[$element] */
711 { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3));
713 | term ARROW '[' expr ']' /* somearef->[$element] */
714 { $$ = newBINOP(OP_AELEM, 0,
715 ref(newAVREF($1),OP_RV2AV),
718 | subscripted '[' expr ']' /* $foo->[$bar]->[$baz] */
719 { $$ = newBINOP(OP_AELEM, 0,
720 ref(newAVREF($1),OP_RV2AV),
723 | scalar '{' expr ';' '}' /* $foo{bar();} */
724 { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
726 | term ARROW '{' expr ';' '}' /* somehref->{bar();} */
727 { $$ = newBINOP(OP_HELEM, 0,
728 ref(newHVREF($1),OP_RV2HV),
730 | subscripted '{' expr ';' '}' /* $foo->[bar]->{baz;} */
731 { $$ = newBINOP(OP_HELEM, 0,
732 ref(newHVREF($1),OP_RV2HV),
734 | term ARROW '(' ')' /* $subref->() */
735 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
736 newCVREF(0, scalar($1))); }
737 | term ARROW '(' expr ')' /* $subref->(@args) */
738 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
739 op_append_elem(OP_LIST, $4,
740 newCVREF(0, scalar($1)))); }
742 | subscripted '(' expr ')' /* $foo->{bar}->(@args) */
743 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
744 op_append_elem(OP_LIST, $3,
745 newCVREF(0, scalar($1)))); }
746 | subscripted '(' ')' /* $foo->{bar}->() */
747 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
748 newCVREF(0, scalar($1))); }
749 | '(' expr ')' '[' expr ']' /* list slice */
750 { $$ = newSLICEOP(0, $5, $2); }
751 | QWLIST '[' expr ']' /* list literal slice */
752 { $$ = newSLICEOP(0, $3, $1); }
753 | '(' ')' '[' expr ']' /* empty list slice! */
754 { $$ = newSLICEOP(0, $4, (OP*)NULL); }
757 /* Binary operators between terms */
758 termbinop: term ASSIGNOP term /* $x = $y */
759 { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); }
760 | term POWOP term /* $x ** $y */
761 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
762 | term MULOP term /* $x * $y, $x x $y */
763 { if ($2 != OP_REPEAT)
765 $$ = newBINOP($2, 0, $1, scalar($3));
767 | term ADDOP term /* $x + $y */
768 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
769 | term SHIFTOP term /* $x >> $y, $x << $y */
770 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
771 | term RELOP term /* $x > $y, etc. */
772 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
773 | term EQOP term /* $x == $y, $x eq $y */
774 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
775 | term BITANDOP term /* $x & $y */
776 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
777 | term BITOROP term /* $x | $y */
778 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
779 | term DOTDOT term /* $x..$y, $x...$y */
780 { $$ = newRANGE($2, scalar($1), scalar($3)); }
781 | term ANDAND term /* $x && $y */
782 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
783 | term OROR term /* $x || $y */
784 { $$ = newLOGOP(OP_OR, 0, $1, $3); }
785 | term DORDOR term /* $x // $y */
786 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
787 | term MATCHOP term /* $x =~ /$y/ */
788 { $$ = bind_match($2, $1, $3); }
791 /* Unary operators and terms */
792 termunop : '-' term %prec UMINUS /* -$x */
793 { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); }
794 | '+' term %prec UMINUS /* +$x */
798 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
800 { $$ = newUNOP(OP_COMPLEMENT, 0, scalar($2)); }
801 | term POSTINC /* $x++ */
802 { $$ = newUNOP(OP_POSTINC, 0,
803 op_lvalue(scalar($1), OP_POSTINC)); }
804 | term POSTDEC /* $x-- */
805 { $$ = newUNOP(OP_POSTDEC, 0,
806 op_lvalue(scalar($1), OP_POSTDEC));}
807 | term POSTJOIN /* implicit join after interpolated ->@ */
808 { $$ = convert(OP_JOIN, 0,
818 | PREINC term /* ++$x */
819 { $$ = newUNOP(OP_PREINC, 0,
820 op_lvalue(scalar($2), OP_PREINC)); }
821 | PREDEC term /* --$x */
822 { $$ = newUNOP(OP_PREDEC, 0,
823 op_lvalue(scalar($2), OP_PREDEC)); }
827 /* Constructors for anonymous data */
828 anonymous: '[' expr ']'
829 { $$ = newANONLIST($2); }
831 { $$ = newANONLIST((OP*)NULL);}
832 | HASHBRACK expr ';' '}' %prec '(' /* { foo => "Bar" } */
833 { $$ = newANONHASH($2); }
834 | HASHBRACK ';' '}' %prec '(' /* { } (';' by tokener) */
835 { $$ = newANONHASH((OP*)NULL); }
836 | ANONSUB startanonsub proto subattrlist realsubbody %prec '('
837 { SvREFCNT_inc_simple_void(PL_compcv);
838 $$ = newANONATTRSUB($2, $3, $4, $5); }
842 /* Things called with "do" */
843 termdo : DO term %prec UNIOP /* do $filename */
844 { $$ = dofile($2, $1);}
845 | DO block %prec '(' /* do { code */
846 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($2));}
853 | term '?' term ':' term
854 { $$ = newCONDOP(0, $1, $3, $5); }
855 | REFGEN term /* \$x, \@y, \%z */
856 { $$ = newUNOP(OP_REFGEN, 0, op_lvalue($2,OP_REFGEN)); }
857 | myattrterm %prec UNIOP
859 | LOCAL term %prec UNIOP
860 { $$ = localize($2,$1); }
862 { $$ = sawparens($2); }
866 { $$ = sawparens(newNULLLIST()); }
875 | arylen %prec '(' /* $#x, $#{ something } */
876 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
879 | sliceme '[' expr ']' /* array slice */
880 { $$ = op_prepend_elem(OP_ASLICE,
881 newOP(OP_PUSHMARK, 0),
882 newLISTOP(OP_ASLICE, 0,
884 ref($1, OP_ASLICE)));
887 $1->op_private & OPpSLICEWARNING;
889 | kvslice '[' expr ']' /* array key/value slice */
890 { $$ = op_prepend_elem(OP_KVASLICE,
891 newOP(OP_PUSHMARK, 0),
892 newLISTOP(OP_KVASLICE, 0,
894 ref(oopsAV($1), OP_KVASLICE)));
897 $1->op_private & OPpSLICEWARNING;
899 | sliceme '{' expr ';' '}' /* @hash{@keys} */
900 { $$ = op_prepend_elem(OP_HSLICE,
901 newOP(OP_PUSHMARK, 0),
902 newLISTOP(OP_HSLICE, 0,
904 ref(oopsHV($1), OP_HSLICE)));
907 $1->op_private & OPpSLICEWARNING;
909 | kvslice '{' expr ';' '}' /* %hash{@keys} */
910 { $$ = op_prepend_elem(OP_KVHSLICE,
911 newOP(OP_PUSHMARK, 0),
912 newLISTOP(OP_KVHSLICE, 0,
914 ref($1, OP_KVHSLICE)));
917 $1->op_private & OPpSLICEWARNING;
922 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
923 | amper '(' ')' /* &foo() or foo() */
924 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1));
926 | amper '(' expr ')' /* &foo(@args) or foo(@args) */
928 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
929 op_append_elem(OP_LIST, $3, scalar($1)));
931 | NOAMP subname optlistexpr /* foo @args (no parens) */
932 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
933 op_append_elem(OP_LIST, $3, scalar($2)));
936 { $$ = newSVREF($1); }
938 { $$ = newAVREF($1); }
940 { $$ = newHVREF($1); }
942 { $$ = newUNOP(OP_ENTERSUB, 0,
943 scalar(newCVREF($3,$1))); }
944 | term ARROW '*' '*' %prec '('
945 { $$ = newGVREF(0,$1); }
946 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
947 { $$ = newOP($1, OPf_SPECIAL);
948 PL_hints |= HINT_BLOCK_SCOPE; }
950 { $$ = newLOOPEX($1,$2); }
951 | NOTOP listexpr /* not $foo */
952 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
953 | UNIOP /* Unary op, $_ implied */
954 { $$ = newOP($1, 0); }
955 | UNIOP block /* eval { foo }* */
956 { $$ = newUNOP($1, 0, $2); }
957 | UNIOP term /* Unary op */
958 { $$ = newUNOP($1, 0, $2); }
959 | REQUIRE /* require, $_ implied */
960 { $$ = newOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0); }
961 | REQUIRE term /* require Foo */
962 { $$ = newUNOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0, $2); }
964 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
965 | UNIOPSUB term /* Sub treated as unop */
966 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
967 op_append_elem(OP_LIST, $2, scalar($1))); }
968 | FUNC0 /* Nullary operator */
969 { $$ = newOP($1, 0); }
971 { $$ = newOP($1, 0);}
972 | FUNC0OP /* Same as above, but op created in toke.c */
976 | FUNC0SUB /* Sub treated as nullop */
977 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
978 | FUNC1 '(' ')' /* not () */
979 { $$ = ($1 == OP_NOT)
980 ? newUNOP($1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
981 : newOP($1, OPf_SPECIAL); }
982 | FUNC1 '(' expr ')' /* not($foo) */
983 { $$ = newUNOP($1, 0, $3); }
984 | PMFUNC /* m//, s///, qr//, tr/// */
986 if ( $1->op_type != OP_TRANS
987 && $1->op_type != OP_TRANSR
988 && (((PMOP*)$1)->op_pmflags & PMf_HAS_CV))
990 $<ival>$ = start_subparse(FALSE, CVf_ANON);
991 SAVEFREESV(PL_compcv);
996 { $$ = pmruntime($1, $4, 1, $<ival>2); }
1001 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
1002 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
1007 /* "my" declarations, with optional attributes */
1008 myattrterm: MY myterm myattrlist
1009 { $$ = my_attrs($2,$3); }
1011 { $$ = localize($2,$1); }
1014 /* Things that can be "my"'d */
1015 myterm : '(' expr ')'
1016 { $$ = sawparens($2); }
1018 { $$ = sawparens(newNULLLIST()); }
1028 /* Basic list expressions */
1029 optlistexpr: /* NULL */ %prec PREC_LOW
1031 | listexpr %prec PREC_LOW
1041 /* A little bit of trickery to make "for my $foo (@bar)" actually be
1044 { parser->in_my = 0; $$ = my($1); }
1052 refgen_topic: my_var
1057 { $$ = newCVREF($1,$2); }
1060 scalar : '$' indirob
1061 { $$ = newSVREF($2); }
1065 { $$ = newAVREF($2);
1066 if ($$) $$->op_private |= $1;
1071 { $$ = newHVREF($2);
1072 if ($$) $$->op_private |= $1;
1076 arylen : DOLSHARP indirob
1077 { $$ = newAVREF($2); }
1078 | term ARROW DOLSHARP '*'
1079 { $$ = newAVREF($1); }
1083 { $$ = newGVREF(0,$2); }
1088 { $$ = newAVREF($1); }
1093 { $$ = newHVREF($1); }
1098 { $$ = newGVREF(0,$1); }
1101 /* Indirect objects */
1103 { $$ = scalar($1); }
1104 | scalar %prec PREC_LOW
1105 { $$ = scalar($1); }
1107 { $$ = op_scope($1); }