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 pad_add_weakref(fmtcv);
265 parser->parsed_sub = 1;
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 PL_hints |= HINT_BLOCK_SCOPE;
374 $$ = block_end($3, forop);
375 parser->copline = (line_t)$1;
377 | FOR MY remember my_scalar '(' mexpr ')' mblock cont
379 $$ = block_end($3, newFOROP(0, $4, $6, $8, $9));
380 parser->copline = (line_t)$1;
382 | FOR scalar '(' remember mexpr ')' mblock cont
384 $$ = block_end($4, newFOROP(0,
385 op_lvalue($2, OP_ENTERLOOP), $5, $7, $8));
386 parser->copline = (line_t)$1;
388 | FOR REFGEN MY remember my_var
389 { parser->in_my = 0; $<opval>$ = my($5); }
390 '(' mexpr ')' mblock cont
396 newUNOP(OP_REFGEN, 0,
401 parser->copline = (line_t)$1;
403 | FOR REFGEN refgen_topic '(' remember mexpr ')' mblock cont
405 $$ = block_end($5, newFOROP(
406 0, op_lvalue(newUNOP(OP_REFGEN, 0,
408 OP_ENTERLOOP), $6, $8, $9));
409 parser->copline = (line_t)$1;
411 | FOR '(' remember mexpr ')' mblock cont
414 newFOROP(0, (OP*)NULL, $4, $6, $7));
415 parser->copline = (line_t)$1;
419 /* a block is a loop that happens once */
420 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
421 (OP*)NULL, $1, $2, 0);
423 | PACKAGE WORD WORD '{' remember
432 /* a block is a loop that happens once */
433 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
434 (OP*)NULL, block_end($5, $7), (OP*)NULL, 0);
435 if (parser->copline > (line_t)$4)
436 parser->copline = (line_t)$4;
445 parser->copline = NOLINE;
450 formline: THING formarg
454 list = op_append_elem(OP_LIST, $1, term);
459 if (parser->copline == NOLINE)
460 parser->copline = CopLINE(PL_curcop)-1;
461 else parser->copline--;
462 $$ = newSTATEOP(0, NULL,
463 op_convert_list(OP_FORMLINE, 0, list));
469 | FORMLBRACK stmtseq FORMRBRACK
470 { $$ = op_unscope($2); }
473 /* An expression which may have a side-effect */
479 { $$ = newLOGOP(OP_AND, 0, $3, $1); }
481 { $$ = newLOGOP(OP_OR, 0, $3, $1); }
483 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); }
485 { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1); }
487 { $$ = newFOROP(0, (OP*)NULL, $3, $1, (OP*)NULL);
488 parser->copline = (line_t)$2; }
490 { $$ = newWHENOP($3, op_scope($1)); }
493 /* else and elsif blocks */
498 ($2)->op_flags |= OPf_PARENS;
501 | ELSIF '(' mexpr ')' mblock else
502 { parser->copline = (line_t)$1;
504 newSTATEOP(OPf_SPECIAL,NULL,$3),
506 PL_hints |= HINT_BLOCK_SCOPE;
510 /* Continue blocks */
514 { $$ = op_scope($2); }
517 /* determine whether there are any new my declarations */
519 { $$ = (PL_min_intro_pending &&
520 PL_max_intro_pending >= PL_min_intro_pending);
523 /* Normal expression */
529 /* Boolean expression */
530 texpr : /* NULL means true */
532 (void)scan_num("1", &tmplval);
533 $$ = tmplval.opval; }
537 /* Inverted boolean expression */
539 { $$ = invert(scalar($1)); }
542 /* Expression with its own lexical scope */
544 { $$ = $1; intro_my(); }
548 { $$ = $1; intro_my(); }
552 { $$ = $1; intro_my(); }
555 formname: WORD { $$ = $1; }
556 | /* NULL */ { $$ = (OP*)NULL; }
559 startsub: /* NULL */ /* start a regular subroutine scope */
560 { $$ = start_subparse(FALSE, 0);
561 SAVEFREESV(PL_compcv); }
565 startanonsub: /* NULL */ /* start an anonymous subroutine scope */
566 { $$ = start_subparse(FALSE, CVf_ANON);
567 SAVEFREESV(PL_compcv); }
570 startformsub: /* NULL */ /* start a format subroutine scope */
571 { $$ = start_subparse(TRUE, 0);
572 SAVEFREESV(PL_compcv); }
575 /* Name of a subroutine - must be a bareword, could be special */
580 /* Subroutine prototype */
586 /* Optional list of subroutine attributes */
587 subattrlist: /* NULL */
595 /* List of attributes for a "my" variable declaration */
596 myattrlist: COLONATTR THING
602 /* Optional subroutine signature */
603 subsignature: /* NULL */ { $$ = (OP*)NULL; }
606 if (!FEATURE_SIGNATURES_IS_ENABLED)
607 Perl_croak(aTHX_ "Experimental "
608 "subroutine signatures not enabled");
609 Perl_ck_warner_d(aTHX_
610 packWARN(WARN_EXPERIMENTAL__SIGNATURES),
611 "The signatures feature is experimental");
612 $<opval>$ = parse_subsignature();
616 $$ = op_append_list(OP_LINESEQ, $<opval>2,
617 newSTATEOP(0, NULL, sawparens(newNULLLIST())));
618 parser->expect = XBLOCK;
622 /* Subroutine body - block with optional signature */
623 realsubbody: remember subsignature '{' stmtseq '}'
625 if (parser->copline > (line_t)$3)
626 parser->copline = (line_t)$3;
628 op_append_list(OP_LINESEQ, $2, $4));
632 /* Optional subroutine body, for named subroutine declaration */
633 optsubbody: realsubbody { $$ = $1; }
634 | ';' { $$ = (OP*)NULL; }
637 /* Ordinary expressions; logical combinations */
638 expr : expr ANDOP expr
639 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
641 { $$ = newLOGOP($2, 0, $1, $3); }
643 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
644 | listexpr %prec PREC_LOW
647 /* Expressions are a list of terms joined by commas */
648 listexpr: listexpr ','
653 $$ = op_append_elem(OP_LIST, $1, term);
655 | term %prec PREC_LOW
659 listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
660 { $$ = op_convert_list($1, OPf_STACKED,
661 op_prepend_elem(OP_LIST, newGVREF($1,$2), $3) );
663 | FUNC '(' indirob expr ')' /* print ($fh @args */
664 { $$ = op_convert_list($1, OPf_STACKED,
665 op_prepend_elem(OP_LIST, newGVREF($1,$3), $4) );
667 | term ARROW method '(' optexpr ')' /* $foo->bar(list) */
668 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
669 op_append_elem(OP_LIST,
670 op_prepend_elem(OP_LIST, scalar($1), $5),
671 newMETHOP(OP_METHOD, 0, $3)));
673 | term ARROW method /* $foo->bar */
674 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
675 op_append_elem(OP_LIST, scalar($1),
676 newMETHOP(OP_METHOD, 0, $3)));
678 | METHOD indirob optlistexpr /* new Class @args */
679 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
680 op_append_elem(OP_LIST,
681 op_prepend_elem(OP_LIST, $2, $3),
682 newMETHOP(OP_METHOD, 0, $1)));
684 | FUNCMETH indirob '(' optexpr ')' /* method $object (@args) */
685 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
686 op_append_elem(OP_LIST,
687 op_prepend_elem(OP_LIST, $2, $4),
688 newMETHOP(OP_METHOD, 0, $1)));
690 | LSTOP optlistexpr /* print @args */
691 { $$ = op_convert_list($1, 0, $2); }
692 | FUNC '(' optexpr ')' /* print (@args) */
693 { $$ = op_convert_list($1, 0, $3); }
694 | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */
695 { SvREFCNT_inc_simple_void(PL_compcv);
696 $<opval>$ = newANONATTRSUB($2, 0, (OP*)NULL, $3); }
697 optlistexpr %prec LSTOP /* ... @bar */
698 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
699 op_append_elem(OP_LIST,
700 op_prepend_elem(OP_LIST, $<opval>4, $5), $1));
704 /* Names of methods. May use $object->$methodname */
709 /* Some kind of subscripted expression */
710 subscripted: gelem '{' expr ';' '}' /* *main::{something} */
711 /* In this and all the hash accessors, ';' is
712 * provided by the tokeniser */
713 { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); }
714 | scalar '[' expr ']' /* $array[$element] */
715 { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3));
717 | term ARROW '[' expr ']' /* somearef->[$element] */
718 { $$ = newBINOP(OP_AELEM, 0,
719 ref(newAVREF($1),OP_RV2AV),
722 | subscripted '[' expr ']' /* $foo->[$bar]->[$baz] */
723 { $$ = newBINOP(OP_AELEM, 0,
724 ref(newAVREF($1),OP_RV2AV),
727 | scalar '{' expr ';' '}' /* $foo{bar();} */
728 { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
730 | term ARROW '{' expr ';' '}' /* somehref->{bar();} */
731 { $$ = newBINOP(OP_HELEM, 0,
732 ref(newHVREF($1),OP_RV2HV),
734 | subscripted '{' expr ';' '}' /* $foo->[bar]->{baz;} */
735 { $$ = newBINOP(OP_HELEM, 0,
736 ref(newHVREF($1),OP_RV2HV),
738 | term ARROW '(' ')' /* $subref->() */
739 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
740 newCVREF(0, scalar($1))); }
741 | term ARROW '(' expr ')' /* $subref->(@args) */
742 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
743 op_append_elem(OP_LIST, $4,
744 newCVREF(0, scalar($1)))); }
746 | subscripted '(' expr ')' /* $foo->{bar}->(@args) */
747 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
748 op_append_elem(OP_LIST, $3,
749 newCVREF(0, scalar($1)))); }
750 | subscripted '(' ')' /* $foo->{bar}->() */
751 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
752 newCVREF(0, scalar($1))); }
753 | '(' expr ')' '[' expr ']' /* list slice */
754 { $$ = newSLICEOP(0, $5, $2); }
755 | QWLIST '[' expr ']' /* list literal slice */
756 { $$ = newSLICEOP(0, $3, $1); }
757 | '(' ')' '[' expr ']' /* empty list slice! */
758 { $$ = newSLICEOP(0, $4, (OP*)NULL); }
761 /* Binary operators between terms */
762 termbinop: term ASSIGNOP term /* $x = $y */
763 { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); }
764 | term POWOP term /* $x ** $y */
765 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
766 | term MULOP term /* $x * $y, $x x $y */
767 { if ($2 != OP_REPEAT)
769 $$ = newBINOP($2, 0, $1, scalar($3));
771 | term ADDOP term /* $x + $y */
772 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
773 | term SHIFTOP term /* $x >> $y, $x << $y */
774 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
775 | term RELOP term /* $x > $y, etc. */
776 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
777 | term EQOP term /* $x == $y, $x eq $y */
778 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
779 | term BITANDOP term /* $x & $y */
780 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
781 | term BITOROP term /* $x | $y */
782 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
783 | term DOTDOT term /* $x..$y, $x...$y */
784 { $$ = newRANGE($2, scalar($1), scalar($3)); }
785 | term ANDAND term /* $x && $y */
786 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
787 | term OROR term /* $x || $y */
788 { $$ = newLOGOP(OP_OR, 0, $1, $3); }
789 | term DORDOR term /* $x // $y */
790 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
791 | term MATCHOP term /* $x =~ /$y/ */
792 { $$ = bind_match($2, $1, $3); }
795 /* Unary operators and terms */
796 termunop : '-' term %prec UMINUS /* -$x */
797 { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); }
798 | '+' term %prec UMINUS /* +$x */
802 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
804 { $$ = newUNOP(OP_COMPLEMENT, 0, scalar($2)); }
805 | term POSTINC /* $x++ */
806 { $$ = newUNOP(OP_POSTINC, 0,
807 op_lvalue(scalar($1), OP_POSTINC)); }
808 | term POSTDEC /* $x-- */
809 { $$ = newUNOP(OP_POSTDEC, 0,
810 op_lvalue(scalar($1), OP_POSTDEC));}
811 | term POSTJOIN /* implicit join after interpolated ->@ */
812 { $$ = op_convert_list(OP_JOIN, 0,
822 | PREINC term /* ++$x */
823 { $$ = newUNOP(OP_PREINC, 0,
824 op_lvalue(scalar($2), OP_PREINC)); }
825 | PREDEC term /* --$x */
826 { $$ = newUNOP(OP_PREDEC, 0,
827 op_lvalue(scalar($2), OP_PREDEC)); }
831 /* Constructors for anonymous data */
832 anonymous: '[' expr ']'
833 { $$ = newANONLIST($2); }
835 { $$ = newANONLIST((OP*)NULL);}
836 | HASHBRACK expr ';' '}' %prec '(' /* { foo => "Bar" } */
837 { $$ = newANONHASH($2); }
838 | HASHBRACK ';' '}' %prec '(' /* { } (';' by tokener) */
839 { $$ = newANONHASH((OP*)NULL); }
840 | ANONSUB startanonsub proto subattrlist realsubbody %prec '('
841 { SvREFCNT_inc_simple_void(PL_compcv);
842 $$ = newANONATTRSUB($2, $3, $4, $5); }
846 /* Things called with "do" */
847 termdo : DO term %prec UNIOP /* do $filename */
848 { $$ = dofile($2, $1);}
849 | DO block %prec '(' /* do { code */
850 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($2));}
857 | term '?' term ':' term
858 { $$ = newCONDOP(0, $1, $3, $5); }
859 | REFGEN term /* \$x, \@y, \%z */
860 { $$ = newUNOP(OP_REFGEN, 0, op_lvalue($2,OP_REFGEN)); }
861 | myattrterm %prec UNIOP
863 | LOCAL term %prec UNIOP
864 { $$ = localize($2,$1); }
866 { $$ = sawparens($2); }
870 { $$ = sawparens(newNULLLIST()); }
879 | arylen %prec '(' /* $#x, $#{ something } */
880 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
883 | sliceme '[' expr ']' /* array slice */
884 { $$ = op_prepend_elem(OP_ASLICE,
885 newOP(OP_PUSHMARK, 0),
886 newLISTOP(OP_ASLICE, 0,
888 ref($1, OP_ASLICE)));
891 $1->op_private & OPpSLICEWARNING;
893 | kvslice '[' expr ']' /* array key/value slice */
894 { $$ = op_prepend_elem(OP_KVASLICE,
895 newOP(OP_PUSHMARK, 0),
896 newLISTOP(OP_KVASLICE, 0,
898 ref(oopsAV($1), OP_KVASLICE)));
901 $1->op_private & OPpSLICEWARNING;
903 | sliceme '{' expr ';' '}' /* @hash{@keys} */
904 { $$ = op_prepend_elem(OP_HSLICE,
905 newOP(OP_PUSHMARK, 0),
906 newLISTOP(OP_HSLICE, 0,
908 ref(oopsHV($1), OP_HSLICE)));
911 $1->op_private & OPpSLICEWARNING;
913 | kvslice '{' expr ';' '}' /* %hash{@keys} */
914 { $$ = op_prepend_elem(OP_KVHSLICE,
915 newOP(OP_PUSHMARK, 0),
916 newLISTOP(OP_KVHSLICE, 0,
918 ref($1, OP_KVHSLICE)));
921 $1->op_private & OPpSLICEWARNING;
926 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
927 | amper '(' ')' /* &foo() or foo() */
928 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1));
930 | amper '(' expr ')' /* &foo(@args) or foo(@args) */
932 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
933 op_append_elem(OP_LIST, $3, scalar($1)));
935 | NOAMP subname optlistexpr /* foo @args (no parens) */
936 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
937 op_append_elem(OP_LIST, $3, scalar($2)));
940 { $$ = newSVREF($1); }
942 { $$ = newAVREF($1); }
944 { $$ = newHVREF($1); }
946 { $$ = newUNOP(OP_ENTERSUB, 0,
947 scalar(newCVREF($3,$1))); }
948 | term ARROW '*' '*' %prec '('
949 { $$ = newGVREF(0,$1); }
950 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
951 { $$ = newOP($1, OPf_SPECIAL);
952 PL_hints |= HINT_BLOCK_SCOPE; }
954 { $$ = newLOOPEX($1,$2); }
955 | NOTOP listexpr /* not $foo */
956 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
957 | UNIOP /* Unary op, $_ implied */
958 { $$ = newOP($1, 0); }
959 | UNIOP block /* eval { foo }* */
960 { $$ = newUNOP($1, 0, $2); }
961 | UNIOP term /* Unary op */
962 { $$ = newUNOP($1, 0, $2); }
963 | REQUIRE /* require, $_ implied */
964 { $$ = newOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0); }
965 | REQUIRE term /* require Foo */
966 { $$ = newUNOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0, $2); }
968 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
969 | UNIOPSUB term /* Sub treated as unop */
970 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
971 op_append_elem(OP_LIST, $2, scalar($1))); }
972 | FUNC0 /* Nullary operator */
973 { $$ = newOP($1, 0); }
975 { $$ = newOP($1, 0);}
976 | FUNC0OP /* Same as above, but op created in toke.c */
980 | FUNC0SUB /* Sub treated as nullop */
981 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
982 | FUNC1 '(' ')' /* not () */
983 { $$ = ($1 == OP_NOT)
984 ? newUNOP($1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
985 : newOP($1, OPf_SPECIAL); }
986 | FUNC1 '(' expr ')' /* not($foo) */
987 { $$ = newUNOP($1, 0, $3); }
988 | PMFUNC /* m//, s///, qr//, tr/// */
990 if ( $1->op_type != OP_TRANS
991 && $1->op_type != OP_TRANSR
992 && (((PMOP*)$1)->op_pmflags & PMf_HAS_CV))
994 $<ival>$ = start_subparse(FALSE, CVf_ANON);
995 SAVEFREESV(PL_compcv);
1000 { $$ = pmruntime($1, $4, 1, $<ival>2); }
1005 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
1006 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
1011 /* "my" declarations, with optional attributes */
1012 myattrterm: MY myterm myattrlist
1013 { $$ = my_attrs($2,$3); }
1015 { $$ = localize($2,$1); }
1018 /* Things that can be "my"'d */
1019 myterm : '(' expr ')'
1020 { $$ = sawparens($2); }
1022 { $$ = sawparens(newNULLLIST()); }
1032 /* Basic list expressions */
1033 optlistexpr: /* NULL */ %prec PREC_LOW
1035 | listexpr %prec PREC_LOW
1045 /* A little bit of trickery to make "for my $foo (@bar)" actually be
1048 { parser->in_my = 0; $$ = my($1); }
1056 refgen_topic: my_var
1061 { $$ = newCVREF($1,$2); }
1064 scalar : '$' indirob
1065 { $$ = newSVREF($2); }
1069 { $$ = newAVREF($2);
1070 if ($$) $$->op_private |= $1;
1075 { $$ = newHVREF($2);
1076 if ($$) $$->op_private |= $1;
1080 arylen : DOLSHARP indirob
1081 { $$ = newAVREF($2); }
1082 | term ARROW DOLSHARP '*'
1083 { $$ = newAVREF($1); }
1087 { $$ = newGVREF(0,$2); }
1092 { $$ = newAVREF($1); }
1097 { $$ = newHVREF($1); }
1102 { $$ = newGVREF(0,$1); }
1105 /* Indirect objects */
1107 { $$ = scalar($1); }
1108 | scalar %prec PREC_LOW
1109 { $$ = scalar($1); }
1111 { $$ = op_scope($1); }