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 PL_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 (PL_parser->copline > (line_t)$1)
181 PL_parser->copline = (line_t)$1;
182 $$ = block_end($2, $3);
187 formblock: '=' remember ';' FORMRBRACK formstmtseq ';' '.'
188 { if (PL_parser->copline > (line_t)$1)
189 PL_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 (PL_parser->copline > (line_t)$1)
200 PL_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);
282 PL_parser->in_my = 0;
283 PL_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 PL_parser->copline = (line_t)$1;
316 | UNLESS '(' remember miexpr ')' mblock else
319 newCONDOP(0, $4, op_scope($6), $7));
320 PL_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 PL_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 PL_parser->copline = (line_t)$1;
344 | UNTIL '(' remember iexpr ')' mintro mblock cont
347 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
349 PL_parser->copline = (line_t)$1;
351 | FOR '(' remember mnexpr ';' texpr ';' mintro mnexpr ')'
355 OP *forop = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
356 scalar($6), $11, $9, $8);
358 forop = op_prepend_elem(OP_LINESEQ, initop,
359 op_append_elem(OP_LINESEQ,
360 newOP(OP_UNSTACK, OPf_SPECIAL),
363 $$ = block_end($3, forop);
364 PL_parser->copline = (line_t)$1;
366 | FOR MY remember my_scalar '(' mexpr ')' mblock cont
368 $$ = block_end($3, newFOROP(0, $4, $6, $8, $9));
369 PL_parser->copline = (line_t)$1;
371 | FOR scalar '(' remember mexpr ')' mblock cont
373 $$ = block_end($4, newFOROP(0,
374 op_lvalue($2, OP_ENTERLOOP), $5, $7, $8));
375 PL_parser->copline = (line_t)$1;
377 | FOR '(' remember mexpr ')' mblock cont
380 newFOROP(0, (OP*)NULL, $4, $6, $7));
381 PL_parser->copline = (line_t)$1;
385 /* a block is a loop that happens once */
386 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
387 (OP*)NULL, $1, $2, 0);
389 | PACKAGE WORD WORD '{' remember
398 /* a block is a loop that happens once */
399 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
400 (OP*)NULL, block_end($5, $7), (OP*)NULL, 0);
401 if (PL_parser->copline > (line_t)$4)
402 PL_parser->copline = (line_t)$4;
406 PL_parser->expect = XSTATE;
411 PL_parser->expect = XSTATE;
413 PL_parser->copline = NOLINE;
418 formline: THING formarg
422 list = op_append_elem(OP_LIST, $1, term);
427 if (PL_parser->copline == NOLINE)
428 PL_parser->copline = CopLINE(PL_curcop)-1;
429 else PL_parser->copline--;
430 $$ = newSTATEOP(0, NULL,
431 convert(OP_FORMLINE, 0, list));
437 | FORMLBRACK stmtseq FORMRBRACK
438 { $$ = op_unscope($2); }
441 /* An expression which may have a side-effect */
447 { $$ = newLOGOP(OP_AND, 0, $3, $1); }
449 { $$ = newLOGOP(OP_OR, 0, $3, $1); }
451 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); }
453 { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1); }
455 { $$ = newFOROP(0, (OP*)NULL, $3, $1, (OP*)NULL);
456 PL_parser->copline = (line_t)$2; }
458 { $$ = newWHENOP($3, op_scope($1)); }
461 /* else and elsif blocks */
466 ($2)->op_flags |= OPf_PARENS;
469 | ELSIF '(' mexpr ')' mblock else
470 { PL_parser->copline = (line_t)$1;
472 newSTATEOP(OPf_SPECIAL,NULL,$3),
474 PL_hints |= HINT_BLOCK_SCOPE;
478 /* Continue blocks */
482 { $$ = op_scope($2); }
485 /* determine whether there are any new my declarations */
487 { $$ = (PL_min_intro_pending &&
488 PL_max_intro_pending >= PL_min_intro_pending);
491 /* Normal expression */
497 /* Boolean expression */
498 texpr : /* NULL means true */
500 (void)scan_num("1", &tmplval);
501 $$ = tmplval.opval; }
505 /* Inverted boolean expression */
507 { $$ = invert(scalar($1)); }
510 /* Expression with its own lexical scope */
512 { $$ = $1; intro_my(); }
516 { $$ = $1; intro_my(); }
520 { $$ = $1; intro_my(); }
523 formname: WORD { $$ = $1; }
524 | /* NULL */ { $$ = (OP*)NULL; }
527 startsub: /* NULL */ /* start a regular subroutine scope */
528 { $$ = start_subparse(FALSE, 0);
529 SAVEFREESV(PL_compcv); }
533 startanonsub: /* NULL */ /* start an anonymous subroutine scope */
534 { $$ = start_subparse(FALSE, CVf_ANON);
535 SAVEFREESV(PL_compcv); }
538 startformsub: /* NULL */ /* start a format subroutine scope */
539 { $$ = start_subparse(TRUE, 0);
540 SAVEFREESV(PL_compcv); }
543 /* Name of a subroutine - must be a bareword, could be special */
548 /* Subroutine prototype */
554 /* Optional list of subroutine attributes */
555 subattrlist: /* NULL */
563 /* List of attributes for a "my" variable declaration */
564 myattrlist: COLONATTR THING
570 /* Optional subroutine signature */
571 subsignature: /* NULL */ { $$ = (OP*)NULL; }
574 if (!FEATURE_SIGNATURES_IS_ENABLED)
575 Perl_croak(aTHX_ "Experimental "
576 "subroutine signatures not enabled");
577 Perl_ck_warner_d(aTHX_
578 packWARN(WARN_EXPERIMENTAL__SIGNATURES),
579 "The signatures feature is experimental");
580 $<opval>$ = parse_subsignature();
584 $$ = op_append_list(OP_LINESEQ, $<opval>2,
585 newSTATEOP(0, NULL, sawparens(newNULLLIST())));
586 PL_parser->expect = XBLOCK;
590 /* Subroutine body - block with optional signature */
591 realsubbody: remember subsignature '{' stmtseq '}'
593 if (PL_parser->copline > (line_t)$3)
594 PL_parser->copline = (line_t)$3;
596 op_append_list(OP_LINESEQ, $2, $4));
600 /* Optional subroutine body, for named subroutine declaration */
601 optsubbody: realsubbody { $$ = $1; }
602 | ';' { $$ = (OP*)NULL;
603 PL_parser->expect = XSTATE;
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 PL_parser->expect = XOPERATOR;
686 | scalar '[' expr ']' /* $array[$element] */
687 { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3));
689 | term ARROW '[' expr ']' /* somearef->[$element] */
690 { $$ = newBINOP(OP_AELEM, 0,
691 ref(newAVREF($1),OP_RV2AV),
694 | subscripted '[' expr ']' /* $foo->[$bar]->[$baz] */
695 { $$ = newBINOP(OP_AELEM, 0,
696 ref(newAVREF($1),OP_RV2AV),
699 | scalar '{' expr ';' '}' /* $foo{bar();} */
700 { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
701 PL_parser->expect = XOPERATOR;
703 | term ARROW '{' expr ';' '}' /* somehref->{bar();} */
704 { $$ = newBINOP(OP_HELEM, 0,
705 ref(newHVREF($1),OP_RV2HV),
707 PL_parser->expect = XOPERATOR;
709 | subscripted '{' expr ';' '}' /* $foo->[bar]->{baz;} */
710 { $$ = newBINOP(OP_HELEM, 0,
711 ref(newHVREF($1),OP_RV2HV),
713 PL_parser->expect = XOPERATOR;
715 | term ARROW '(' ')' /* $subref->() */
716 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
717 newCVREF(0, scalar($1))); }
718 | term ARROW '(' expr ')' /* $subref->(@args) */
719 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
720 op_append_elem(OP_LIST, $4,
721 newCVREF(0, scalar($1)))); }
723 | subscripted '(' expr ')' /* $foo->{bar}->(@args) */
724 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
725 op_append_elem(OP_LIST, $3,
726 newCVREF(0, scalar($1)))); }
727 | subscripted '(' ')' /* $foo->{bar}->() */
728 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
729 newCVREF(0, scalar($1))); }
730 | '(' expr ')' '[' expr ']' /* list slice */
731 { $$ = newSLICEOP(0, $5, $2); }
732 | QWLIST '[' expr ']' /* list literal slice */
733 { $$ = newSLICEOP(0, $3, $1); }
734 | '(' ')' '[' expr ']' /* empty list slice! */
735 { $$ = newSLICEOP(0, $4, (OP*)NULL); }
738 /* Binary operators between terms */
739 termbinop: term ASSIGNOP term /* $x = $y */
740 { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); }
741 | term POWOP term /* $x ** $y */
742 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
743 | term MULOP term /* $x * $y, $x x $y */
744 { if ($2 != OP_REPEAT)
746 $$ = newBINOP($2, 0, $1, scalar($3));
748 | term ADDOP term /* $x + $y */
749 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
750 | term SHIFTOP term /* $x >> $y, $x << $y */
751 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
752 | term RELOP term /* $x > $y, etc. */
753 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
754 | term EQOP term /* $x == $y, $x eq $y */
755 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
756 | term BITANDOP term /* $x & $y */
757 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
758 | term BITOROP term /* $x | $y */
759 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
760 | term DOTDOT term /* $x..$y, $x...$y */
761 { $$ = newRANGE($2, scalar($1), scalar($3)); }
762 | term ANDAND term /* $x && $y */
763 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
764 | term OROR term /* $x || $y */
765 { $$ = newLOGOP(OP_OR, 0, $1, $3); }
766 | term DORDOR term /* $x // $y */
767 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
768 | term MATCHOP term /* $x =~ /$y/ */
769 { $$ = bind_match($2, $1, $3); }
772 /* Unary operators and terms */
773 termunop : '-' term %prec UMINUS /* -$x */
774 { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); }
775 | '+' term %prec UMINUS /* +$x */
779 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
781 { $$ = newUNOP(OP_COMPLEMENT, 0, scalar($2)); }
782 | term POSTINC /* $x++ */
783 { $$ = newUNOP(OP_POSTINC, 0,
784 op_lvalue(scalar($1), OP_POSTINC)); }
785 | term POSTDEC /* $x-- */
786 { $$ = newUNOP(OP_POSTDEC, 0,
787 op_lvalue(scalar($1), OP_POSTDEC));}
788 | term POSTJOIN /* implicit join after interpolated ->@ */
789 { $$ = convert(OP_JOIN, 0,
799 | PREINC term /* ++$x */
800 { $$ = newUNOP(OP_PREINC, 0,
801 op_lvalue(scalar($2), OP_PREINC)); }
802 | PREDEC term /* --$x */
803 { $$ = newUNOP(OP_PREDEC, 0,
804 op_lvalue(scalar($2), OP_PREDEC)); }
808 /* Constructors for anonymous data */
809 anonymous: '[' expr ']'
810 { $$ = newANONLIST($2); }
812 { $$ = newANONLIST((OP*)NULL);}
813 | HASHBRACK expr ';' '}' %prec '(' /* { foo => "Bar" } */
814 { $$ = newANONHASH($2); }
815 | HASHBRACK ';' '}' %prec '(' /* { } (';' by tokener) */
816 { $$ = newANONHASH((OP*)NULL); }
817 | ANONSUB startanonsub proto subattrlist realsubbody %prec '('
818 { SvREFCNT_inc_simple_void(PL_compcv);
819 $$ = newANONATTRSUB($2, $3, $4, $5); }
823 /* Things called with "do" */
824 termdo : DO term %prec UNIOP /* do $filename */
825 { $$ = dofile($2, $1);}
826 | DO block %prec '(' /* do { code */
827 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($2));}
834 | term '?' term ':' term
835 { $$ = newCONDOP(0, $1, $3, $5); }
836 | REFGEN term /* \$x, \@y, \%z */
837 { $$ = newUNOP(OP_REFGEN, 0, op_lvalue($2,OP_REFGEN)); }
838 | myattrterm %prec UNIOP
840 | LOCAL term %prec UNIOP
841 { $$ = localize($2,$1); }
843 { $$ = sawparens($2); }
847 { $$ = sawparens(newNULLLIST()); }
856 | arylen %prec '(' /* $#x, $#{ something } */
857 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
860 | sliceme '[' expr ']' /* array slice */
861 { $$ = op_prepend_elem(OP_ASLICE,
862 newOP(OP_PUSHMARK, 0),
863 newLISTOP(OP_ASLICE, 0,
865 ref($1, OP_ASLICE)));
868 $1->op_private & OPpSLICEWARNING;
870 | kvslice '[' expr ']' /* array key/value slice */
871 { $$ = op_prepend_elem(OP_KVASLICE,
872 newOP(OP_PUSHMARK, 0),
873 newLISTOP(OP_KVASLICE, 0,
875 ref(oopsAV($1), OP_KVASLICE)));
878 $1->op_private & OPpSLICEWARNING;
880 | sliceme '{' expr ';' '}' /* @hash{@keys} */
881 { $$ = op_prepend_elem(OP_HSLICE,
882 newOP(OP_PUSHMARK, 0),
883 newLISTOP(OP_HSLICE, 0,
885 ref(oopsHV($1), OP_HSLICE)));
888 $1->op_private & OPpSLICEWARNING;
889 PL_parser->expect = XOPERATOR;
891 | kvslice '{' expr ';' '}' /* %hash{@keys} */
892 { $$ = op_prepend_elem(OP_KVHSLICE,
893 newOP(OP_PUSHMARK, 0),
894 newLISTOP(OP_KVHSLICE, 0,
896 ref($1, OP_KVHSLICE)));
899 $1->op_private & OPpSLICEWARNING;
900 PL_parser->expect = XOPERATOR;
905 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
906 | amper '(' ')' /* &foo() or foo() */
907 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1));
909 | amper '(' expr ')' /* &foo(@args) or foo(@args) */
911 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
912 op_append_elem(OP_LIST, $3, scalar($1)));
914 | NOAMP subname optlistexpr /* foo @args (no parens) */
915 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
916 op_append_elem(OP_LIST, $3, scalar($2)));
919 { $$ = newSVREF($1); }
921 { $$ = newAVREF($1); }
923 { $$ = newHVREF($1); }
925 { $$ = newUNOP(OP_ENTERSUB, 0,
926 scalar(newCVREF($3,$1))); }
927 | term ARROW '*' '*' %prec '('
928 { $$ = newGVREF(0,$1); }
929 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
930 { $$ = newOP($1, OPf_SPECIAL);
931 PL_hints |= HINT_BLOCK_SCOPE; }
933 { $$ = newLOOPEX($1,$2); }
934 | NOTOP listexpr /* not $foo */
935 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
936 | UNIOP /* Unary op, $_ implied */
937 { $$ = newOP($1, 0); }
938 | UNIOP block /* eval { foo }* */
939 { $$ = newUNOP($1, 0, $2); }
940 | UNIOP term /* Unary op */
941 { $$ = newUNOP($1, 0, $2); }
942 | REQUIRE /* require, $_ implied */
943 { $$ = newOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0); }
944 | REQUIRE term /* require Foo */
945 { $$ = newUNOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0, $2); }
947 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
948 | UNIOPSUB term /* Sub treated as unop */
949 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
950 op_append_elem(OP_LIST, $2, scalar($1))); }
951 | FUNC0 /* Nullary operator */
952 { $$ = newOP($1, 0); }
954 { $$ = newOP($1, 0);}
955 | FUNC0OP /* Same as above, but op created in toke.c */
959 | FUNC0SUB /* Sub treated as nullop */
960 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
961 | FUNC1 '(' ')' /* not () */
962 { $$ = ($1 == OP_NOT)
963 ? newUNOP($1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
964 : newOP($1, OPf_SPECIAL); }
965 | FUNC1 '(' expr ')' /* not($foo) */
966 { $$ = newUNOP($1, 0, $3); }
967 | PMFUNC /* m//, s///, qr//, tr/// */
969 if ( $1->op_type != OP_TRANS
970 && $1->op_type != OP_TRANSR
971 && (((PMOP*)$1)->op_pmflags & PMf_HAS_CV))
973 $<ival>$ = start_subparse(FALSE, CVf_ANON);
974 SAVEFREESV(PL_compcv);
979 { $$ = pmruntime($1, $4, 1, $<ival>2); }
984 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
985 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
990 /* "my" declarations, with optional attributes */
991 myattrterm: MY myterm myattrlist
992 { $$ = my_attrs($2,$3); }
994 { $$ = localize($2,$1); }
997 /* Things that can be "my"'d */
998 myterm : '(' expr ')'
999 { $$ = sawparens($2); }
1001 { $$ = sawparens(newNULLLIST()); }
1011 /* Basic list expressions */
1012 optlistexpr: /* NULL */ %prec PREC_LOW
1014 | listexpr %prec PREC_LOW
1024 /* A little bit of trickery to make "for my $foo (@bar)" actually be
1027 { PL_parser->in_my = 0; $$ = my($1); }
1031 { $$ = newCVREF($1,$2); }
1034 scalar : '$' indirob
1035 { $$ = newSVREF($2); }
1039 { $$ = newAVREF($2);
1040 if ($$) $$->op_private |= $1;
1045 { $$ = newHVREF($2);
1046 if ($$) $$->op_private |= $1;
1050 arylen : DOLSHARP indirob
1051 { $$ = newAVREF($2); }
1052 | term ARROW DOLSHARP '*'
1053 { $$ = newAVREF($1); }
1057 { $$ = newGVREF(0,$2); }
1062 { $$ = newAVREF($1); }
1067 { $$ = newHVREF($1); }
1072 { $$ = newGVREF(0,$1); }
1075 /* Indirect objects */
1077 { $$ = scalar($1); }
1078 | scalar %prec PREC_LOW
1079 { $$ = scalar($1); }
1081 { $$ = op_scope($1); }