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 formblock
75 %type <opval> subattrlist myattrlist myattrterm myterm
76 %type <opval> realsubbody subsignature termbinop termunop anonymous termdo
77 %type <opval> formstmtseq formline formarg
79 %nonassoc <ival> PREC_LOW
82 %left <ival> OROP DOROP
85 %nonassoc LSTOP LSTOPSUB
87 %right <ival> ASSIGNOP
89 %nonassoc DOTDOT YADAYADA
90 %left <ival> OROR DORDOR
96 %nonassoc UNIOP UNIOPSUB
102 %right <ival> '!' '~' UMINUS REFGEN
104 %nonassoc <ival> PREINC PREDEC POSTINC POSTDEC POSTJOIN
112 /* Top-level choice of what kind of thing yyparse was called to parse */
115 parser->expect = XSTATE;
119 newPROG(block_end($3,$4));
124 parser->expect = XTERM;
133 parser->expect = XBLOCK;
137 PL_pad_reset_pending = TRUE;
141 parser->yychar = YYEOF;
145 parser->expect = XSTATE;
149 PL_pad_reset_pending = TRUE;
153 parser->yychar = YYEOF;
157 parser->expect = XSTATE;
161 PL_pad_reset_pending = TRUE;
165 parser->yychar = YYEOF;
169 parser->expect = XSTATE;
178 /* An ordinary block */
179 block : '{' remember stmtseq '}'
180 { if (parser->copline > (line_t)$1)
181 parser->copline = (line_t)$1;
182 $$ = block_end($2, $3);
187 formblock: '=' remember ';' FORMRBRACK formstmtseq ';' '.'
188 { if (parser->copline > (line_t)$1)
189 parser->copline = (line_t)$1;
190 $$ = block_end($2, $5);
194 remember: /* NULL */ /* start a full lexical scope */
195 { $$ = block_start(TRUE); }
198 mblock : '{' mremember stmtseq '}'
199 { if (parser->copline > (line_t)$1)
200 parser->copline = (line_t)$1;
201 $$ = block_end($2, $3);
205 mremember: /* NULL */ /* start a partial lexical scope */
206 { $$ = block_start(FALSE); }
209 /* A sequence of statements in the program */
213 { $$ = op_append_list(OP_LINESEQ, $1, $2);
214 PL_pad_reset_pending = TRUE;
216 PL_hints |= HINT_BLOCK_SCOPE;
220 /* A sequence of format lines */
221 formstmtseq: /* NULL */
223 | formstmtseq formline
224 { $$ = op_append_list(OP_LINESEQ, $1, $2);
225 PL_pad_reset_pending = TRUE;
227 PL_hints |= HINT_BLOCK_SCOPE;
231 /* A statement in the program, including optional labels */
234 $$ = $1 ? newSTATEOP(0, NULL, $1) : NULL;
240 labfullstmt: LABEL barestmt
242 $$ = newSTATEOP(SVf_UTF8 * $1[strlen($1)+1], $1, $2);
246 $$ = newSTATEOP(SVf_UTF8 * $1[strlen($1)+1], $1, $2);
250 /* A bare statement, lacking label and other aspects of state op */
253 | FORMAT startformsub formname formblock
255 CV *fmtcv = PL_compcv;
258 if (CvOUTSIDE(fmtcv) && !CvEVAL(CvOUTSIDE(fmtcv))) {
259 SvREFCNT_inc_simple_void(fmtcv);
260 pad_add_anon(fmtcv, OP_NULL);
263 | SUB subname startsub
265 if ($2->op_type == OP_CONST) {
266 const char *const name =
267 SvPV_nolen_const(((SVOP*)$2)->op_sv);
268 if (strEQ(name, "BEGIN") || strEQ(name, "END")
269 || strEQ(name, "INIT") || strEQ(name, "CHECK")
270 || strEQ(name, "UNITCHECK"))
271 CvSPECIAL_on(PL_compcv);
274 /* State subs inside anonymous subs need to be
275 clonable themselves. */
276 if (CvANON(CvOUTSIDE(PL_compcv))
277 || CvCLONE(CvOUTSIDE(PL_compcv))
278 || !PadnameIsSTATE(PadlistNAMESARRAY(CvPADLIST(
281 CvCLONE_on(PL_compcv);
283 parser->in_my_stash = NULL;
285 proto subattrlist optsubbody
287 SvREFCNT_inc_simple_void(PL_compcv);
288 $2->op_type == OP_CONST
289 ? newATTRSUB($3, $2, $5, $6, $7)
290 : newMYSUB($3, $2, $5, $6, $7)
295 | PACKAGE WORD WORD ';'
303 { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
304 WORD WORD optlistexpr ';'
306 SvREFCNT_inc_simple_void(PL_compcv);
307 utilize($1, $2, $4, $5, $6);
310 | IF '(' remember mexpr ')' mblock else
313 newCONDOP(0, $4, op_scope($6), $7));
314 parser->copline = (line_t)$1;
316 | UNLESS '(' remember miexpr ')' mblock else
319 newCONDOP(0, $4, op_scope($6), $7));
320 parser->copline = (line_t)$1;
322 | GIVEN '(' remember mexpr ')' mblock
324 const PADOFFSET offset = pad_findmy_pvs("$_", 0);
326 newGIVENOP($4, op_scope($6),
328 || PAD_COMPNAME_FLAGS_isOUR(offset)
331 parser->copline = (line_t)$1;
333 | WHEN '(' remember mexpr ')' mblock
334 { $$ = block_end($3, newWHENOP($4, op_scope($6))); }
336 { $$ = newWHENOP(0, op_scope($2)); }
337 | WHILE '(' remember texpr ')' mintro mblock cont
340 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
342 parser->copline = (line_t)$1;
344 | UNTIL '(' remember iexpr ')' mintro mblock cont
347 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
349 parser->copline = (line_t)$1;
351 | FOR '(' remember mnexpr ';'
352 { parser->expect = XTERM; }
354 { parser->expect = XTERM; }
359 OP *forop = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
360 scalar($7), $13, $11, $10);
362 forop = op_prepend_elem(OP_LINESEQ, initop,
363 op_append_elem(OP_LINESEQ,
364 newOP(OP_UNSTACK, OPf_SPECIAL),
367 $$ = block_end($3, forop);
368 parser->copline = (line_t)$1;
370 | FOR MY remember my_scalar '(' mexpr ')' mblock cont
372 $$ = block_end($3, newFOROP(0, $4, $6, $8, $9));
373 parser->copline = (line_t)$1;
375 | FOR scalar '(' remember mexpr ')' mblock cont
377 $$ = block_end($4, newFOROP(0,
378 op_lvalue($2, OP_ENTERLOOP), $5, $7, $8));
379 parser->copline = (line_t)$1;
381 | FOR '(' remember mexpr ')' mblock cont
384 newFOROP(0, (OP*)NULL, $4, $6, $7));
385 parser->copline = (line_t)$1;
389 /* a block is a loop that happens once */
390 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
391 (OP*)NULL, $1, $2, 0);
393 | PACKAGE WORD WORD '{' remember
402 /* a block is a loop that happens once */
403 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
404 (OP*)NULL, block_end($5, $7), (OP*)NULL, 0);
405 if (parser->copline > (line_t)$4)
406 parser->copline = (line_t)$4;
415 parser->copline = NOLINE;
420 formline: THING formarg
424 list = op_append_elem(OP_LIST, $1, term);
429 if (parser->copline == NOLINE)
430 parser->copline = CopLINE(PL_curcop)-1;
431 else parser->copline--;
432 $$ = newSTATEOP(0, NULL,
433 convert(OP_FORMLINE, 0, list));
439 | FORMLBRACK stmtseq FORMRBRACK
440 { $$ = op_unscope($2); }
443 /* An expression which may have a side-effect */
449 { $$ = newLOGOP(OP_AND, 0, $3, $1); }
451 { $$ = newLOGOP(OP_OR, 0, $3, $1); }
453 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); }
455 { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1); }
457 { $$ = newFOROP(0, (OP*)NULL, $3, $1, (OP*)NULL);
458 parser->copline = (line_t)$2; }
460 { $$ = newWHENOP($3, op_scope($1)); }
463 /* else and elsif blocks */
468 ($2)->op_flags |= OPf_PARENS;
471 | ELSIF '(' mexpr ')' mblock else
472 { parser->copline = (line_t)$1;
474 newSTATEOP(OPf_SPECIAL,NULL,$3),
476 PL_hints |= HINT_BLOCK_SCOPE;
480 /* Continue blocks */
484 { $$ = op_scope($2); }
487 /* determine whether there are any new my declarations */
489 { $$ = (PL_min_intro_pending &&
490 PL_max_intro_pending >= PL_min_intro_pending);
493 /* Normal expression */
499 /* Boolean expression */
500 texpr : /* NULL means true */
502 (void)scan_num("1", &tmplval);
503 $$ = tmplval.opval; }
507 /* Inverted boolean expression */
509 { $$ = invert(scalar($1)); }
512 /* Expression with its own lexical scope */
514 { $$ = $1; intro_my(); }
518 { $$ = $1; intro_my(); }
522 { $$ = $1; intro_my(); }
525 formname: WORD { $$ = $1; }
526 | /* NULL */ { $$ = (OP*)NULL; }
529 startsub: /* NULL */ /* start a regular subroutine scope */
530 { $$ = start_subparse(FALSE, 0);
531 SAVEFREESV(PL_compcv); }
535 startanonsub: /* NULL */ /* start an anonymous subroutine scope */
536 { $$ = start_subparse(FALSE, CVf_ANON);
537 SAVEFREESV(PL_compcv); }
540 startformsub: /* NULL */ /* start a format subroutine scope */
541 { $$ = start_subparse(TRUE, 0);
542 SAVEFREESV(PL_compcv); }
545 /* Name of a subroutine - must be a bareword, could be special */
550 /* Subroutine prototype */
556 /* Optional list of subroutine attributes */
557 subattrlist: /* NULL */
565 /* List of attributes for a "my" variable declaration */
566 myattrlist: COLONATTR THING
572 /* Optional subroutine signature */
573 subsignature: /* NULL */ { $$ = (OP*)NULL; }
576 if (!FEATURE_SIGNATURES_IS_ENABLED)
577 Perl_croak(aTHX_ "Experimental "
578 "subroutine signatures not enabled");
579 Perl_ck_warner_d(aTHX_
580 packWARN(WARN_EXPERIMENTAL__SIGNATURES),
581 "The signatures feature is experimental");
582 $<opval>$ = parse_subsignature();
586 $$ = op_append_list(OP_LINESEQ, $<opval>2,
587 newSTATEOP(0, NULL, sawparens(newNULLLIST())));
588 parser->expect = XBLOCK;
592 /* Subroutine body - block with optional signature */
593 realsubbody: remember subsignature '{' stmtseq '}'
595 if (parser->copline > (line_t)$3)
596 parser->copline = (line_t)$3;
598 op_append_list(OP_LINESEQ, $2, $4));
602 /* Optional subroutine body, for named subroutine declaration */
603 optsubbody: realsubbody { $$ = $1; }
604 | ';' { $$ = (OP*)NULL; }
607 /* Ordinary expressions; logical combinations */
608 expr : expr ANDOP expr
609 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
611 { $$ = newLOGOP($2, 0, $1, $3); }
613 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
614 | listexpr %prec PREC_LOW
617 /* Expressions are a list of terms joined by commas */
618 listexpr: listexpr ','
623 $$ = op_append_elem(OP_LIST, $1, term);
625 | term %prec PREC_LOW
629 listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
630 { $$ = convert($1, OPf_STACKED,
631 op_prepend_elem(OP_LIST, newGVREF($1,$2), $3) );
633 | FUNC '(' indirob expr ')' /* print ($fh @args */
634 { $$ = convert($1, OPf_STACKED,
635 op_prepend_elem(OP_LIST, newGVREF($1,$3), $4) );
637 | term ARROW method '(' optexpr ')' /* $foo->bar(list) */
638 { $$ = convert(OP_ENTERSUB, OPf_STACKED,
639 op_append_elem(OP_LIST,
640 op_prepend_elem(OP_LIST, scalar($1), $5),
641 newUNOP(OP_METHOD, 0, $3)));
643 | term ARROW method /* $foo->bar */
644 { $$ = convert(OP_ENTERSUB, OPf_STACKED,
645 op_append_elem(OP_LIST, scalar($1),
646 newUNOP(OP_METHOD, 0, $3)));
648 | METHOD indirob optlistexpr /* new Class @args */
649 { $$ = convert(OP_ENTERSUB, OPf_STACKED,
650 op_append_elem(OP_LIST,
651 op_prepend_elem(OP_LIST, $2, $3),
652 newUNOP(OP_METHOD, 0, $1)));
654 | FUNCMETH indirob '(' optexpr ')' /* method $object (@args) */
655 { $$ = convert(OP_ENTERSUB, OPf_STACKED,
656 op_append_elem(OP_LIST,
657 op_prepend_elem(OP_LIST, $2, $4),
658 newUNOP(OP_METHOD, 0, $1)));
660 | LSTOP optlistexpr /* print @args */
661 { $$ = convert($1, 0, $2); }
662 | FUNC '(' optexpr ')' /* print (@args) */
663 { $$ = convert($1, 0, $3); }
664 | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */
665 { SvREFCNT_inc_simple_void(PL_compcv);
666 $<opval>$ = newANONATTRSUB($2, 0, (OP*)NULL, $3); }
667 optlistexpr %prec LSTOP /* ... @bar */
668 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
669 op_append_elem(OP_LIST,
670 op_prepend_elem(OP_LIST, $<opval>4, $5), $1));
674 /* Names of methods. May use $object->$methodname */
679 /* Some kind of subscripted expression */
680 subscripted: gelem '{' expr ';' '}' /* *main::{something} */
681 /* In this and all the hash accessors, ';' is
682 * provided by the tokeniser */
683 { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); }
684 | scalar '[' expr ']' /* $array[$element] */
685 { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3));
687 | term ARROW '[' expr ']' /* somearef->[$element] */
688 { $$ = newBINOP(OP_AELEM, 0,
689 ref(newAVREF($1),OP_RV2AV),
692 | subscripted '[' expr ']' /* $foo->[$bar]->[$baz] */
693 { $$ = newBINOP(OP_AELEM, 0,
694 ref(newAVREF($1),OP_RV2AV),
697 | scalar '{' expr ';' '}' /* $foo{bar();} */
698 { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
700 | term ARROW '{' expr ';' '}' /* somehref->{bar();} */
701 { $$ = newBINOP(OP_HELEM, 0,
702 ref(newHVREF($1),OP_RV2HV),
704 | subscripted '{' expr ';' '}' /* $foo->[bar]->{baz;} */
705 { $$ = newBINOP(OP_HELEM, 0,
706 ref(newHVREF($1),OP_RV2HV),
708 | term ARROW '(' ')' /* $subref->() */
709 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
710 newCVREF(0, scalar($1))); }
711 | term ARROW '(' expr ')' /* $subref->(@args) */
712 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
713 op_append_elem(OP_LIST, $4,
714 newCVREF(0, scalar($1)))); }
716 | subscripted '(' expr ')' /* $foo->{bar}->(@args) */
717 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
718 op_append_elem(OP_LIST, $3,
719 newCVREF(0, scalar($1)))); }
720 | subscripted '(' ')' /* $foo->{bar}->() */
721 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
722 newCVREF(0, scalar($1))); }
723 | '(' expr ')' '[' expr ']' /* list slice */
724 { $$ = newSLICEOP(0, $5, $2); }
725 | QWLIST '[' expr ']' /* list literal slice */
726 { $$ = newSLICEOP(0, $3, $1); }
727 | '(' ')' '[' expr ']' /* empty list slice! */
728 { $$ = newSLICEOP(0, $4, (OP*)NULL); }
731 /* Binary operators between terms */
732 termbinop: term ASSIGNOP term /* $x = $y */
733 { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); }
734 | term POWOP term /* $x ** $y */
735 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
736 | term MULOP term /* $x * $y, $x x $y */
737 { if ($2 != OP_REPEAT)
739 $$ = newBINOP($2, 0, $1, scalar($3));
741 | term ADDOP term /* $x + $y */
742 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
743 | term SHIFTOP term /* $x >> $y, $x << $y */
744 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
745 | term RELOP term /* $x > $y, etc. */
746 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
747 | term EQOP term /* $x == $y, $x eq $y */
748 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
749 | term BITANDOP term /* $x & $y */
750 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
751 | term BITOROP term /* $x | $y */
752 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
753 | term DOTDOT term /* $x..$y, $x...$y */
754 { $$ = newRANGE($2, scalar($1), scalar($3)); }
755 | term ANDAND term /* $x && $y */
756 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
757 | term OROR term /* $x || $y */
758 { $$ = newLOGOP(OP_OR, 0, $1, $3); }
759 | term DORDOR term /* $x // $y */
760 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
761 | term MATCHOP term /* $x =~ /$y/ */
762 { $$ = bind_match($2, $1, $3); }
765 /* Unary operators and terms */
766 termunop : '-' term %prec UMINUS /* -$x */
767 { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); }
768 | '+' term %prec UMINUS /* +$x */
772 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
774 { $$ = newUNOP(OP_COMPLEMENT, 0, scalar($2)); }
775 | term POSTINC /* $x++ */
776 { $$ = newUNOP(OP_POSTINC, 0,
777 op_lvalue(scalar($1), OP_POSTINC)); }
778 | term POSTDEC /* $x-- */
779 { $$ = newUNOP(OP_POSTDEC, 0,
780 op_lvalue(scalar($1), OP_POSTDEC));}
781 | term POSTJOIN /* implicit join after interpolated ->@ */
782 { $$ = convert(OP_JOIN, 0,
792 | PREINC term /* ++$x */
793 { $$ = newUNOP(OP_PREINC, 0,
794 op_lvalue(scalar($2), OP_PREINC)); }
795 | PREDEC term /* --$x */
796 { $$ = newUNOP(OP_PREDEC, 0,
797 op_lvalue(scalar($2), OP_PREDEC)); }
801 /* Constructors for anonymous data */
802 anonymous: '[' expr ']'
803 { $$ = newANONLIST($2); }
805 { $$ = newANONLIST((OP*)NULL);}
806 | HASHBRACK expr ';' '}' %prec '(' /* { foo => "Bar" } */
807 { $$ = newANONHASH($2); }
808 | HASHBRACK ';' '}' %prec '(' /* { } (';' by tokener) */
809 { $$ = newANONHASH((OP*)NULL); }
810 | ANONSUB startanonsub proto subattrlist realsubbody %prec '('
811 { SvREFCNT_inc_simple_void(PL_compcv);
812 $$ = newANONATTRSUB($2, $3, $4, $5); }
816 /* Things called with "do" */
817 termdo : DO term %prec UNIOP /* do $filename */
818 { $$ = dofile($2, $1);}
819 | DO block %prec '(' /* do { code */
820 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($2));}
827 | term '?' term ':' term
828 { $$ = newCONDOP(0, $1, $3, $5); }
829 | REFGEN term /* \$x, \@y, \%z */
830 { $$ = newUNOP(OP_REFGEN, 0, op_lvalue($2,OP_REFGEN)); }
831 | myattrterm %prec UNIOP
833 | LOCAL term %prec UNIOP
834 { $$ = localize($2,$1); }
836 { $$ = sawparens($2); }
840 { $$ = sawparens(newNULLLIST()); }
849 | arylen %prec '(' /* $#x, $#{ something } */
850 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
853 | sliceme '[' expr ']' /* array slice */
854 { $$ = op_prepend_elem(OP_ASLICE,
855 newOP(OP_PUSHMARK, 0),
856 newLISTOP(OP_ASLICE, 0,
858 ref($1, OP_ASLICE)));
861 $1->op_private & OPpSLICEWARNING;
863 | kvslice '[' expr ']' /* array key/value slice */
864 { $$ = op_prepend_elem(OP_KVASLICE,
865 newOP(OP_PUSHMARK, 0),
866 newLISTOP(OP_KVASLICE, 0,
868 ref(oopsAV($1), OP_KVASLICE)));
871 $1->op_private & OPpSLICEWARNING;
873 | sliceme '{' expr ';' '}' /* @hash{@keys} */
874 { $$ = op_prepend_elem(OP_HSLICE,
875 newOP(OP_PUSHMARK, 0),
876 newLISTOP(OP_HSLICE, 0,
878 ref(oopsHV($1), OP_HSLICE)));
881 $1->op_private & OPpSLICEWARNING;
883 | kvslice '{' expr ';' '}' /* %hash{@keys} */
884 { $$ = op_prepend_elem(OP_KVHSLICE,
885 newOP(OP_PUSHMARK, 0),
886 newLISTOP(OP_KVHSLICE, 0,
888 ref($1, OP_KVHSLICE)));
891 $1->op_private & OPpSLICEWARNING;
896 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
897 | amper '(' ')' /* &foo() or foo() */
898 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1));
900 | amper '(' expr ')' /* &foo(@args) or foo(@args) */
902 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
903 op_append_elem(OP_LIST, $3, scalar($1)));
905 | NOAMP subname optlistexpr /* foo @args (no parens) */
906 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
907 op_append_elem(OP_LIST, $3, scalar($2)));
910 { $$ = newSVREF($1); }
912 { $$ = newAVREF($1); }
914 { $$ = newHVREF($1); }
916 { $$ = newUNOP(OP_ENTERSUB, 0,
917 scalar(newCVREF($3,$1))); }
918 | term ARROW '*' '*' %prec '('
919 { $$ = newGVREF(0,$1); }
920 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
921 { $$ = newOP($1, OPf_SPECIAL);
922 PL_hints |= HINT_BLOCK_SCOPE; }
924 { $$ = newLOOPEX($1,$2); }
925 | NOTOP listexpr /* not $foo */
926 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
927 | UNIOP /* Unary op, $_ implied */
928 { $$ = newOP($1, 0); }
929 | UNIOP block /* eval { foo }* */
930 { $$ = newUNOP($1, 0, $2); }
931 | UNIOP term /* Unary op */
932 { $$ = newUNOP($1, 0, $2); }
933 | REQUIRE /* require, $_ implied */
934 { $$ = newOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0); }
935 | REQUIRE term /* require Foo */
936 { $$ = newUNOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0, $2); }
938 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
939 | UNIOPSUB term /* Sub treated as unop */
940 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
941 op_append_elem(OP_LIST, $2, scalar($1))); }
942 | FUNC0 /* Nullary operator */
943 { $$ = newOP($1, 0); }
945 { $$ = newOP($1, 0);}
946 | FUNC0OP /* Same as above, but op created in toke.c */
950 | FUNC0SUB /* Sub treated as nullop */
951 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
952 | FUNC1 '(' ')' /* not () */
953 { $$ = ($1 == OP_NOT)
954 ? newUNOP($1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
955 : newOP($1, OPf_SPECIAL); }
956 | FUNC1 '(' expr ')' /* not($foo) */
957 { $$ = newUNOP($1, 0, $3); }
958 | PMFUNC /* m//, s///, qr//, tr/// */
960 if ( $1->op_type != OP_TRANS
961 && $1->op_type != OP_TRANSR
962 && (((PMOP*)$1)->op_pmflags & PMf_HAS_CV))
964 $<ival>$ = start_subparse(FALSE, CVf_ANON);
965 SAVEFREESV(PL_compcv);
970 { $$ = pmruntime($1, $4, 1, $<ival>2); }
975 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
976 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
981 /* "my" declarations, with optional attributes */
982 myattrterm: MY myterm myattrlist
983 { $$ = my_attrs($2,$3); }
985 { $$ = localize($2,$1); }
988 /* Things that can be "my"'d */
989 myterm : '(' expr ')'
990 { $$ = sawparens($2); }
992 { $$ = sawparens(newNULLLIST()); }
1002 /* Basic list expressions */
1003 optlistexpr: /* NULL */ %prec PREC_LOW
1005 | listexpr %prec PREC_LOW
1015 /* A little bit of trickery to make "for my $foo (@bar)" actually be
1018 { parser->in_my = 0; $$ = my($1); }
1022 { $$ = newCVREF($1,$2); }
1025 scalar : '$' indirob
1026 { $$ = newSVREF($2); }
1030 { $$ = newAVREF($2);
1031 if ($$) $$->op_private |= $1;
1036 { $$ = newHVREF($2);
1037 if ($$) $$->op_private |= $1;
1041 arylen : DOLSHARP indirob
1042 { $$ = newAVREF($2); }
1043 | term ARROW DOLSHARP '*'
1044 { $$ = newAVREF($1); }
1048 { $$ = newGVREF(0,$2); }
1053 { $$ = newAVREF($1); }
1058 { $$ = newHVREF($1); }
1063 { $$ = newGVREF(0,$1); }
1066 /* Indirect objects */
1068 { $$ = scalar($1); }
1069 | scalar %prec PREC_LOW
1070 { $$ = scalar($1); }
1072 { $$ = op_scope($1); }