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);
267 | SUB subname startsub
269 if ($2->op_type == OP_CONST) {
270 const char *const name =
271 SvPV_nolen_const(((SVOP*)$2)->op_sv);
272 if (strEQ(name, "BEGIN") || strEQ(name, "END")
273 || strEQ(name, "INIT") || strEQ(name, "CHECK")
274 || strEQ(name, "UNITCHECK"))
275 CvSPECIAL_on(PL_compcv);
278 /* State subs inside anonymous subs need to be
279 clonable themselves. */
280 if (CvANON(CvOUTSIDE(PL_compcv))
281 || CvCLONE(CvOUTSIDE(PL_compcv))
282 || !PadnameIsSTATE(PadlistNAMESARRAY(CvPADLIST(
285 CvCLONE_on(PL_compcv);
287 parser->in_my_stash = NULL;
289 proto subattrlist optsubbody
291 SvREFCNT_inc_simple_void(PL_compcv);
292 $2->op_type == OP_CONST
293 ? newATTRSUB($3, $2, $5, $6, $7)
294 : newMYSUB($3, $2, $5, $6, $7)
298 parser->parsed_sub = 1;
300 | PACKAGE WORD WORD ';'
308 { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
309 WORD WORD optlistexpr ';'
311 SvREFCNT_inc_simple_void(PL_compcv);
312 utilize($1, $2, $4, $5, $6);
313 parser->parsed_sub = 1;
316 | IF '(' remember mexpr ')' mblock else
319 newCONDOP(0, $4, op_scope($6), $7));
320 parser->copline = (line_t)$1;
322 | UNLESS '(' remember miexpr ')' mblock else
325 newCONDOP(0, $4, op_scope($6), $7));
326 parser->copline = (line_t)$1;
328 | GIVEN '(' remember mexpr ')' mblock
330 const PADOFFSET offset = pad_findmy_pvs("$_", 0);
332 newGIVENOP($4, op_scope($6),
334 || PAD_COMPNAME_FLAGS_isOUR(offset)
337 parser->copline = (line_t)$1;
339 | WHEN '(' remember mexpr ')' mblock
340 { $$ = block_end($3, newWHENOP($4, op_scope($6))); }
342 { $$ = newWHENOP(0, op_scope($2)); }
343 | WHILE '(' remember texpr ')' mintro mblock cont
346 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
348 parser->copline = (line_t)$1;
350 | UNTIL '(' remember iexpr ')' mintro mblock cont
353 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
355 parser->copline = (line_t)$1;
357 | FOR '(' remember mnexpr ';'
358 { parser->expect = XTERM; }
360 { parser->expect = XTERM; }
365 OP *forop = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
366 scalar($7), $13, $11, $10);
368 forop = op_prepend_elem(OP_LINESEQ, initop,
369 op_append_elem(OP_LINESEQ,
370 newOP(OP_UNSTACK, OPf_SPECIAL),
373 $$ = block_end($3, forop);
374 parser->copline = (line_t)$1;
376 | FOR MY remember my_scalar '(' mexpr ')' mblock cont
378 $$ = block_end($3, newFOROP(0, $4, $6, $8, $9));
379 parser->copline = (line_t)$1;
381 | FOR scalar '(' remember mexpr ')' mblock cont
383 $$ = block_end($4, newFOROP(0,
384 op_lvalue($2, OP_ENTERLOOP), $5, $7, $8));
385 parser->copline = (line_t)$1;
387 | FOR REFGEN MY remember my_var
388 { parser->in_my = 0; $<opval>$ = my($5); }
389 '(' mexpr ')' mblock cont
395 newUNOP(OP_REFGEN, 0,
400 parser->copline = (line_t)$1;
402 | FOR REFGEN refgen_topic '(' remember mexpr ')' mblock cont
404 $$ = block_end($5, newFOROP(
405 0, op_lvalue(newUNOP(OP_REFGEN, 0,
407 OP_ENTERLOOP), $6, $8, $9));
408 parser->copline = (line_t)$1;
410 | FOR '(' remember mexpr ')' mblock cont
413 newFOROP(0, (OP*)NULL, $4, $6, $7));
414 parser->copline = (line_t)$1;
418 /* a block is a loop that happens once */
419 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
420 (OP*)NULL, $1, $2, 0);
422 | PACKAGE WORD WORD '{' remember
431 /* a block is a loop that happens once */
432 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
433 (OP*)NULL, block_end($5, $7), (OP*)NULL, 0);
434 if (parser->copline > (line_t)$4)
435 parser->copline = (line_t)$4;
444 parser->copline = NOLINE;
449 formline: THING formarg
453 list = op_append_elem(OP_LIST, $1, term);
458 if (parser->copline == NOLINE)
459 parser->copline = CopLINE(PL_curcop)-1;
460 else parser->copline--;
461 $$ = newSTATEOP(0, NULL,
462 op_convert_list(OP_FORMLINE, 0, list));
468 | FORMLBRACK stmtseq FORMRBRACK
469 { $$ = op_unscope($2); }
472 /* An expression which may have a side-effect */
478 { $$ = newLOGOP(OP_AND, 0, $3, $1); }
480 { $$ = newLOGOP(OP_OR, 0, $3, $1); }
482 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); }
484 { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1); }
486 { $$ = newFOROP(0, (OP*)NULL, $3, $1, (OP*)NULL);
487 parser->copline = (line_t)$2; }
489 { $$ = newWHENOP($3, op_scope($1)); }
492 /* else and elsif blocks */
497 ($2)->op_flags |= OPf_PARENS;
500 | ELSIF '(' mexpr ')' mblock else
501 { parser->copline = (line_t)$1;
503 newSTATEOP(OPf_SPECIAL,NULL,$3),
505 PL_hints |= HINT_BLOCK_SCOPE;
509 /* Continue blocks */
513 { $$ = op_scope($2); }
516 /* determine whether there are any new my declarations */
518 { $$ = (PL_min_intro_pending &&
519 PL_max_intro_pending >= PL_min_intro_pending);
522 /* Normal expression */
528 /* Boolean expression */
529 texpr : /* NULL means true */
531 (void)scan_num("1", &tmplval);
532 $$ = tmplval.opval; }
536 /* Inverted boolean expression */
538 { $$ = invert(scalar($1)); }
541 /* Expression with its own lexical scope */
543 { $$ = $1; intro_my(); }
547 { $$ = $1; intro_my(); }
551 { $$ = $1; intro_my(); }
554 formname: WORD { $$ = $1; }
555 | /* NULL */ { $$ = (OP*)NULL; }
558 startsub: /* NULL */ /* start a regular subroutine scope */
559 { $$ = start_subparse(FALSE, 0);
560 SAVEFREESV(PL_compcv); }
564 startanonsub: /* NULL */ /* start an anonymous subroutine scope */
565 { $$ = start_subparse(FALSE, CVf_ANON);
566 SAVEFREESV(PL_compcv); }
569 startformsub: /* NULL */ /* start a format subroutine scope */
570 { $$ = start_subparse(TRUE, 0);
571 SAVEFREESV(PL_compcv); }
574 /* Name of a subroutine - must be a bareword, could be special */
579 /* Subroutine prototype */
585 /* Optional list of subroutine attributes */
586 subattrlist: /* NULL */
594 /* List of attributes for a "my" variable declaration */
595 myattrlist: COLONATTR THING
601 /* Optional subroutine signature */
602 subsignature: /* NULL */ { $$ = (OP*)NULL; }
605 if (!FEATURE_SIGNATURES_IS_ENABLED)
606 Perl_croak(aTHX_ "Experimental "
607 "subroutine signatures not enabled");
608 Perl_ck_warner_d(aTHX_
609 packWARN(WARN_EXPERIMENTAL__SIGNATURES),
610 "The signatures feature is experimental");
611 $<opval>$ = parse_subsignature();
615 $$ = op_append_list(OP_LINESEQ, $<opval>2,
616 newSTATEOP(0, NULL, sawparens(newNULLLIST())));
617 parser->expect = XBLOCK;
621 /* Subroutine body - block with optional signature */
622 realsubbody: remember subsignature '{' stmtseq '}'
624 if (parser->copline > (line_t)$3)
625 parser->copline = (line_t)$3;
627 op_append_list(OP_LINESEQ, $2, $4));
631 /* Optional subroutine body, for named subroutine declaration */
632 optsubbody: realsubbody { $$ = $1; }
633 | ';' { $$ = (OP*)NULL; }
636 /* Ordinary expressions; logical combinations */
637 expr : expr ANDOP expr
638 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
640 { $$ = newLOGOP($2, 0, $1, $3); }
642 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
643 | listexpr %prec PREC_LOW
646 /* Expressions are a list of terms joined by commas */
647 listexpr: listexpr ','
652 $$ = op_append_elem(OP_LIST, $1, term);
654 | term %prec PREC_LOW
658 listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
659 { $$ = op_convert_list($1, OPf_STACKED,
660 op_prepend_elem(OP_LIST, newGVREF($1,$2), $3) );
662 | FUNC '(' indirob expr ')' /* print ($fh @args */
663 { $$ = op_convert_list($1, OPf_STACKED,
664 op_prepend_elem(OP_LIST, newGVREF($1,$3), $4) );
666 | term ARROW method '(' optexpr ')' /* $foo->bar(list) */
667 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
668 op_append_elem(OP_LIST,
669 op_prepend_elem(OP_LIST, scalar($1), $5),
670 newMETHOP(OP_METHOD, 0, $3)));
672 | term ARROW method /* $foo->bar */
673 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
674 op_append_elem(OP_LIST, scalar($1),
675 newMETHOP(OP_METHOD, 0, $3)));
677 | METHOD indirob optlistexpr /* new Class @args */
678 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
679 op_append_elem(OP_LIST,
680 op_prepend_elem(OP_LIST, $2, $3),
681 newMETHOP(OP_METHOD, 0, $1)));
683 | FUNCMETH indirob '(' optexpr ')' /* method $object (@args) */
684 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
685 op_append_elem(OP_LIST,
686 op_prepend_elem(OP_LIST, $2, $4),
687 newMETHOP(OP_METHOD, 0, $1)));
689 | LSTOP optlistexpr /* print @args */
690 { $$ = op_convert_list($1, 0, $2); }
691 | FUNC '(' optexpr ')' /* print (@args) */
692 { $$ = op_convert_list($1, 0, $3); }
693 | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */
694 { SvREFCNT_inc_simple_void(PL_compcv);
695 $<opval>$ = newANONATTRSUB($2, 0, (OP*)NULL, $3); }
696 optlistexpr %prec LSTOP /* ... @bar */
697 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
698 op_append_elem(OP_LIST,
699 op_prepend_elem(OP_LIST, $<opval>4, $5), $1));
703 /* Names of methods. May use $object->$methodname */
708 /* Some kind of subscripted expression */
709 subscripted: gelem '{' expr ';' '}' /* *main::{something} */
710 /* In this and all the hash accessors, ';' is
711 * provided by the tokeniser */
712 { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); }
713 | scalar '[' expr ']' /* $array[$element] */
714 { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3));
716 | term ARROW '[' expr ']' /* somearef->[$element] */
717 { $$ = newBINOP(OP_AELEM, 0,
718 ref(newAVREF($1),OP_RV2AV),
721 | subscripted '[' expr ']' /* $foo->[$bar]->[$baz] */
722 { $$ = newBINOP(OP_AELEM, 0,
723 ref(newAVREF($1),OP_RV2AV),
726 | scalar '{' expr ';' '}' /* $foo{bar();} */
727 { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
729 | term ARROW '{' expr ';' '}' /* somehref->{bar();} */
730 { $$ = newBINOP(OP_HELEM, 0,
731 ref(newHVREF($1),OP_RV2HV),
733 | subscripted '{' expr ';' '}' /* $foo->[bar]->{baz;} */
734 { $$ = newBINOP(OP_HELEM, 0,
735 ref(newHVREF($1),OP_RV2HV),
737 | term ARROW '(' ')' /* $subref->() */
738 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
739 newCVREF(0, scalar($1))); }
740 | term ARROW '(' expr ')' /* $subref->(@args) */
741 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
742 op_append_elem(OP_LIST, $4,
743 newCVREF(0, scalar($1)))); }
745 | subscripted '(' expr ')' /* $foo->{bar}->(@args) */
746 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
747 op_append_elem(OP_LIST, $3,
748 newCVREF(0, scalar($1)))); }
749 | subscripted '(' ')' /* $foo->{bar}->() */
750 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
751 newCVREF(0, scalar($1))); }
752 | '(' expr ')' '[' expr ']' /* list slice */
753 { $$ = newSLICEOP(0, $5, $2); }
754 | QWLIST '[' expr ']' /* list literal slice */
755 { $$ = newSLICEOP(0, $3, $1); }
756 | '(' ')' '[' expr ']' /* empty list slice! */
757 { $$ = newSLICEOP(0, $4, (OP*)NULL); }
760 /* Binary operators between terms */
761 termbinop: term ASSIGNOP term /* $x = $y */
762 { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); }
763 | term POWOP term /* $x ** $y */
764 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
765 | term MULOP term /* $x * $y, $x x $y */
766 { if ($2 != OP_REPEAT)
768 $$ = newBINOP($2, 0, $1, scalar($3));
770 | term ADDOP term /* $x + $y */
771 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
772 | term SHIFTOP term /* $x >> $y, $x << $y */
773 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
774 | term RELOP term /* $x > $y, etc. */
775 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
776 | term EQOP term /* $x == $y, $x eq $y */
777 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
778 | term BITANDOP term /* $x & $y */
779 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
780 | term BITOROP term /* $x | $y */
781 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
782 | term DOTDOT term /* $x..$y, $x...$y */
783 { $$ = newRANGE($2, scalar($1), scalar($3)); }
784 | term ANDAND term /* $x && $y */
785 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
786 | term OROR term /* $x || $y */
787 { $$ = newLOGOP(OP_OR, 0, $1, $3); }
788 | term DORDOR term /* $x // $y */
789 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
790 | term MATCHOP term /* $x =~ /$y/ */
791 { $$ = bind_match($2, $1, $3); }
794 /* Unary operators and terms */
795 termunop : '-' term %prec UMINUS /* -$x */
796 { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); }
797 | '+' term %prec UMINUS /* +$x */
801 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
803 { $$ = newUNOP(OP_COMPLEMENT, 0, scalar($2)); }
804 | term POSTINC /* $x++ */
805 { $$ = newUNOP(OP_POSTINC, 0,
806 op_lvalue(scalar($1), OP_POSTINC)); }
807 | term POSTDEC /* $x-- */
808 { $$ = newUNOP(OP_POSTDEC, 0,
809 op_lvalue(scalar($1), OP_POSTDEC));}
810 | term POSTJOIN /* implicit join after interpolated ->@ */
811 { $$ = op_convert_list(OP_JOIN, 0,
821 | PREINC term /* ++$x */
822 { $$ = newUNOP(OP_PREINC, 0,
823 op_lvalue(scalar($2), OP_PREINC)); }
824 | PREDEC term /* --$x */
825 { $$ = newUNOP(OP_PREDEC, 0,
826 op_lvalue(scalar($2), OP_PREDEC)); }
830 /* Constructors for anonymous data */
831 anonymous: '[' expr ']'
832 { $$ = newANONLIST($2); }
834 { $$ = newANONLIST((OP*)NULL);}
835 | HASHBRACK expr ';' '}' %prec '(' /* { foo => "Bar" } */
836 { $$ = newANONHASH($2); }
837 | HASHBRACK ';' '}' %prec '(' /* { } (';' by tokener) */
838 { $$ = newANONHASH((OP*)NULL); }
839 | ANONSUB startanonsub proto subattrlist realsubbody %prec '('
840 { SvREFCNT_inc_simple_void(PL_compcv);
841 $$ = newANONATTRSUB($2, $3, $4, $5); }
845 /* Things called with "do" */
846 termdo : DO term %prec UNIOP /* do $filename */
847 { $$ = dofile($2, $1);}
848 | DO block %prec '(' /* do { code */
849 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($2));}
856 | term '?' term ':' term
857 { $$ = newCONDOP(0, $1, $3, $5); }
858 | REFGEN term /* \$x, \@y, \%z */
859 { $$ = newUNOP(OP_REFGEN, 0, op_lvalue($2,OP_REFGEN)); }
860 | myattrterm %prec UNIOP
862 | LOCAL term %prec UNIOP
863 { $$ = localize($2,$1); }
865 { $$ = sawparens($2); }
869 { $$ = sawparens(newNULLLIST()); }
878 | arylen %prec '(' /* $#x, $#{ something } */
879 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
882 | sliceme '[' expr ']' /* array slice */
883 { $$ = op_prepend_elem(OP_ASLICE,
884 newOP(OP_PUSHMARK, 0),
885 newLISTOP(OP_ASLICE, 0,
887 ref($1, OP_ASLICE)));
890 $1->op_private & OPpSLICEWARNING;
892 | kvslice '[' expr ']' /* array key/value slice */
893 { $$ = op_prepend_elem(OP_KVASLICE,
894 newOP(OP_PUSHMARK, 0),
895 newLISTOP(OP_KVASLICE, 0,
897 ref(oopsAV($1), OP_KVASLICE)));
900 $1->op_private & OPpSLICEWARNING;
902 | sliceme '{' expr ';' '}' /* @hash{@keys} */
903 { $$ = op_prepend_elem(OP_HSLICE,
904 newOP(OP_PUSHMARK, 0),
905 newLISTOP(OP_HSLICE, 0,
907 ref(oopsHV($1), OP_HSLICE)));
910 $1->op_private & OPpSLICEWARNING;
912 | kvslice '{' expr ';' '}' /* %hash{@keys} */
913 { $$ = op_prepend_elem(OP_KVHSLICE,
914 newOP(OP_PUSHMARK, 0),
915 newLISTOP(OP_KVHSLICE, 0,
917 ref($1, OP_KVHSLICE)));
920 $1->op_private & OPpSLICEWARNING;
925 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
926 | amper '(' ')' /* &foo() or foo() */
927 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1));
929 | amper '(' expr ')' /* &foo(@args) or foo(@args) */
931 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
932 op_append_elem(OP_LIST, $3, scalar($1)));
934 | NOAMP subname optlistexpr /* foo @args (no parens) */
935 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
936 op_append_elem(OP_LIST, $3, scalar($2)));
939 { $$ = newSVREF($1); }
941 { $$ = newAVREF($1); }
943 { $$ = newHVREF($1); }
945 { $$ = newUNOP(OP_ENTERSUB, 0,
946 scalar(newCVREF($3,$1))); }
947 | term ARROW '*' '*' %prec '('
948 { $$ = newGVREF(0,$1); }
949 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
950 { $$ = newOP($1, OPf_SPECIAL);
951 PL_hints |= HINT_BLOCK_SCOPE; }
953 { $$ = newLOOPEX($1,$2); }
954 | NOTOP listexpr /* not $foo */
955 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
956 | UNIOP /* Unary op, $_ implied */
957 { $$ = newOP($1, 0); }
958 | UNIOP block /* eval { foo }* */
959 { $$ = newUNOP($1, 0, $2); }
960 | UNIOP term /* Unary op */
961 { $$ = newUNOP($1, 0, $2); }
962 | REQUIRE /* require, $_ implied */
963 { $$ = newOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0); }
964 | REQUIRE term /* require Foo */
965 { $$ = newUNOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0, $2); }
967 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
968 | UNIOPSUB term /* Sub treated as unop */
969 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
970 op_append_elem(OP_LIST, $2, scalar($1))); }
971 | FUNC0 /* Nullary operator */
972 { $$ = newOP($1, 0); }
974 { $$ = newOP($1, 0);}
975 | FUNC0OP /* Same as above, but op created in toke.c */
979 | FUNC0SUB /* Sub treated as nullop */
980 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
981 | FUNC1 '(' ')' /* not () */
982 { $$ = ($1 == OP_NOT)
983 ? newUNOP($1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
984 : newOP($1, OPf_SPECIAL); }
985 | FUNC1 '(' expr ')' /* not($foo) */
986 { $$ = newUNOP($1, 0, $3); }
987 | PMFUNC /* m//, s///, qr//, tr/// */
989 if ( $1->op_type != OP_TRANS
990 && $1->op_type != OP_TRANSR
991 && (((PMOP*)$1)->op_pmflags & PMf_HAS_CV))
993 $<ival>$ = start_subparse(FALSE, CVf_ANON);
994 SAVEFREESV(PL_compcv);
999 { $$ = pmruntime($1, $4, 1, $<ival>2); }
1004 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
1005 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
1010 /* "my" declarations, with optional attributes */
1011 myattrterm: MY myterm myattrlist
1012 { $$ = my_attrs($2,$3); }
1014 { $$ = localize($2,$1); }
1017 /* Things that can be "my"'d */
1018 myterm : '(' expr ')'
1019 { $$ = sawparens($2); }
1021 { $$ = sawparens(newNULLLIST()); }
1031 /* Basic list expressions */
1032 optlistexpr: /* NULL */ %prec PREC_LOW
1034 | listexpr %prec PREC_LOW
1044 /* A little bit of trickery to make "for my $foo (@bar)" actually be
1047 { parser->in_my = 0; $$ = my($1); }
1055 refgen_topic: my_var
1060 { $$ = newCVREF($1,$2); }
1063 scalar : '$' indirob
1064 { $$ = newSVREF($2); }
1068 { $$ = newAVREF($2);
1069 if ($$) $$->op_private |= $1;
1074 { $$ = newHVREF($2);
1075 if ($$) $$->op_private |= $1;
1079 arylen : DOLSHARP indirob
1080 { $$ = newAVREF($2); }
1081 | term ARROW DOLSHARP '*'
1082 { $$ = newAVREF($1); }
1086 { $$ = newGVREF(0,$2); }
1091 { $$ = newAVREF($1); }
1096 { $$ = newHVREF($1); }
1101 { $$ = newGVREF(0,$1); }
1104 /* Indirect objects */
1106 { $$ = scalar($1); }
1107 | scalar %prec PREC_LOW
1108 { $$ = scalar($1); }
1110 { $$ = op_scope($1); }