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
73 %type <opval> optlistexpr optexpr optrepl 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> 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 | SUB subname startsub
302 if ($2->op_type == OP_CONST) {
303 const char *const name =
304 SvPV_nolen_const(((SVOP*)$2)->op_sv);
305 if (strEQ(name, "BEGIN") || strEQ(name, "END")
306 || strEQ(name, "INIT") || strEQ(name, "CHECK")
307 || strEQ(name, "UNITCHECK"))
308 CvSPECIAL_on(PL_compcv);
311 /* State subs inside anonymous subs need to be
312 clonable themselves. */
313 if (CvANON(CvOUTSIDE(PL_compcv))
314 || CvCLONE(CvOUTSIDE(PL_compcv))
315 || !PadnameIsSTATE(PadlistNAMESARRAY(CvPADLIST(
318 CvCLONE_on(PL_compcv);
320 parser->in_my_stash = NULL;
322 remember subsignature subattrlist '{' stmtseq '}'
325 if (parser->copline > (line_t)$8)
326 parser->copline = (line_t)$8;
328 op_append_list(OP_LINESEQ, $6, $9));
330 SvREFCNT_inc_simple_void(PL_compcv);
331 $2->op_type == OP_CONST
332 ? newATTRSUB($3, $2, NULL, $7, body)
333 : newMYSUB($3, $2, NULL, $7, body)
337 parser->parsed_sub = 1;
339 | PACKAGE WORD WORD ';'
347 { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
348 WORD WORD optlistexpr ';'
350 SvREFCNT_inc_simple_void(PL_compcv);
351 utilize($1, $2, $4, $5, $6);
352 parser->parsed_sub = 1;
355 | IF '(' remember mexpr ')' mblock else
358 newCONDOP(0, $4, op_scope($6), $7));
359 parser->copline = (line_t)$1;
361 | UNLESS '(' remember mexpr ')' mblock else
364 newCONDOP(0, $4, $7, op_scope($6)));
365 parser->copline = (line_t)$1;
367 | GIVEN '(' remember mexpr ')' mblock
369 $$ = block_end($3, newGIVENOP($4, op_scope($6), 0));
370 parser->copline = (line_t)$1;
372 | WHEN '(' remember mexpr ')' mblock
373 { $$ = block_end($3, newWHENOP($4, op_scope($6))); }
375 { $$ = newWHENOP(0, op_scope($2)); }
376 | WHILE '(' remember texpr ')' mintro mblock cont
379 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
381 parser->copline = (line_t)$1;
383 | UNTIL '(' remember iexpr ')' mintro mblock cont
386 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
388 parser->copline = (line_t)$1;
390 | FOR '(' remember mnexpr ';'
391 { parser->expect = XTERM; }
393 { parser->expect = XTERM; }
398 OP *forop = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
399 scalar($7), $13, $11, $10);
401 forop = op_prepend_elem(OP_LINESEQ, initop,
402 op_append_elem(OP_LINESEQ,
403 newOP(OP_UNSTACK, OPf_SPECIAL),
406 PL_hints |= HINT_BLOCK_SCOPE;
407 $$ = block_end($3, forop);
408 parser->copline = (line_t)$1;
410 | FOR MY remember my_scalar '(' mexpr ')' mblock cont
412 $$ = block_end($3, newFOROP(0, $4, $6, $8, $9));
413 parser->copline = (line_t)$1;
415 | FOR scalar '(' remember mexpr ')' mblock cont
417 $$ = block_end($4, newFOROP(0,
418 op_lvalue($2, OP_ENTERLOOP), $5, $7, $8));
419 parser->copline = (line_t)$1;
421 | FOR REFGEN MY remember my_var
422 { parser->in_my = 0; $<opval>$ = my($5); }
423 '(' mexpr ')' mblock cont
429 newUNOP(OP_REFGEN, 0,
434 parser->copline = (line_t)$1;
436 | FOR REFGEN refgen_topic '(' remember mexpr ')' mblock cont
438 $$ = block_end($5, newFOROP(
439 0, op_lvalue(newUNOP(OP_REFGEN, 0,
441 OP_ENTERLOOP), $6, $8, $9));
442 parser->copline = (line_t)$1;
444 | FOR '(' remember mexpr ')' mblock cont
447 newFOROP(0, (OP*)NULL, $4, $6, $7));
448 parser->copline = (line_t)$1;
452 /* a block is a loop that happens once */
453 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
454 (OP*)NULL, $1, $2, 0);
456 | PACKAGE WORD WORD '{' remember
465 /* a block is a loop that happens once */
466 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
467 (OP*)NULL, block_end($5, $7), (OP*)NULL, 0);
468 if (parser->copline > (line_t)$4)
469 parser->copline = (line_t)$4;
478 parser->copline = NOLINE;
483 formline: THING formarg
487 list = op_append_elem(OP_LIST, $1, term);
492 if (parser->copline == NOLINE)
493 parser->copline = CopLINE(PL_curcop)-1;
494 else parser->copline--;
495 $$ = newSTATEOP(0, NULL,
496 op_convert_list(OP_FORMLINE, 0, list));
502 | FORMLBRACK stmtseq FORMRBRACK
503 { $$ = op_unscope($2); }
506 /* An expression which may have a side-effect */
512 { $$ = newLOGOP(OP_AND, 0, $3, $1); }
514 { $$ = newLOGOP(OP_OR, 0, $3, $1); }
516 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); }
518 { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1); }
520 { $$ = newFOROP(0, (OP*)NULL, $3, $1, (OP*)NULL);
521 parser->copline = (line_t)$2; }
523 { $$ = newWHENOP($3, op_scope($1)); }
526 /* else and elsif blocks */
531 ($2)->op_flags |= OPf_PARENS;
534 | ELSIF '(' mexpr ')' mblock else
535 { parser->copline = (line_t)$1;
537 newSTATEOP(OPf_SPECIAL,NULL,$3),
539 PL_hints |= HINT_BLOCK_SCOPE;
543 /* Continue blocks */
547 { $$ = op_scope($2); }
550 /* determine whether there are any new my declarations */
552 { $$ = (PL_min_intro_pending &&
553 PL_max_intro_pending >= PL_min_intro_pending);
556 /* Normal expression */
562 /* Boolean expression */
563 texpr : /* NULL means true */
565 (void)scan_num("1", &tmplval);
566 $$ = tmplval.opval; }
570 /* Inverted boolean expression */
572 { $$ = invert(scalar($1)); }
575 /* Expression with its own lexical scope */
577 { $$ = $1; intro_my(); }
581 { $$ = $1; intro_my(); }
584 formname: WORD { $$ = $1; }
585 | /* NULL */ { $$ = (OP*)NULL; }
588 startsub: /* NULL */ /* start a regular subroutine scope */
589 { $$ = start_subparse(FALSE, 0);
590 SAVEFREESV(PL_compcv); }
594 startanonsub: /* NULL */ /* start an anonymous subroutine scope */
595 { $$ = start_subparse(FALSE, CVf_ANON);
596 SAVEFREESV(PL_compcv); }
599 startformsub: /* NULL */ /* start a format subroutine scope */
600 { $$ = start_subparse(TRUE, 0);
601 SAVEFREESV(PL_compcv); }
604 /* Name of a subroutine - must be a bareword, could be special */
609 /* Subroutine prototype */
615 /* Optional list of subroutine attributes */
616 subattrlist: /* NULL */
624 /* List of attributes for a "my" variable declaration */
625 myattrlist: COLONATTR THING
631 /* Subroutine signature */
634 /* We shouldn't get here otherwise */
635 assert(FEATURE_SIGNATURES_IS_ENABLED);
637 Perl_ck_warner_d(aTHX_
638 packWARN(WARN_EXPERIMENTAL__SIGNATURES),
639 "The signatures feature is experimental");
640 $<opval>$ = parse_subsignature();
644 $$ = op_append_list(OP_LINESEQ, $<opval>2,
645 newSTATEOP(0, NULL, sawparens(newNULLLIST())));
646 parser->expect = XATTRBLOCK;
650 /* Optional subroutine body, for named subroutine declaration */
652 | ';' { $$ = (OP*)NULL; }
655 /* Ordinary expressions; logical combinations */
656 expr : expr ANDOP expr
657 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
659 { $$ = newLOGOP($2, 0, $1, $3); }
661 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
662 | listexpr %prec PREC_LOW
665 /* Expressions are a list of terms joined by commas */
666 listexpr: listexpr ','
671 $$ = op_append_elem(OP_LIST, $1, term);
673 | term %prec PREC_LOW
677 listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
678 { $$ = op_convert_list($1, OPf_STACKED,
679 op_prepend_elem(OP_LIST, newGVREF($1,$2), $3) );
681 | FUNC '(' indirob expr ')' /* print ($fh @args */
682 { $$ = op_convert_list($1, OPf_STACKED,
683 op_prepend_elem(OP_LIST, newGVREF($1,$3), $4) );
685 | term ARROW method '(' optexpr ')' /* $foo->bar(list) */
686 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
687 op_append_elem(OP_LIST,
688 op_prepend_elem(OP_LIST, scalar($1), $5),
689 newMETHOP(OP_METHOD, 0, $3)));
691 | term ARROW method /* $foo->bar */
692 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
693 op_append_elem(OP_LIST, scalar($1),
694 newMETHOP(OP_METHOD, 0, $3)));
696 | METHOD indirob optlistexpr /* new Class @args */
697 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
698 op_append_elem(OP_LIST,
699 op_prepend_elem(OP_LIST, $2, $3),
700 newMETHOP(OP_METHOD, 0, $1)));
702 | FUNCMETH indirob '(' optexpr ')' /* method $object (@args) */
703 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
704 op_append_elem(OP_LIST,
705 op_prepend_elem(OP_LIST, $2, $4),
706 newMETHOP(OP_METHOD, 0, $1)));
708 | LSTOP optlistexpr /* print @args */
709 { $$ = op_convert_list($1, 0, $2); }
710 | FUNC '(' optexpr ')' /* print (@args) */
711 { $$ = op_convert_list($1, 0, $3); }
712 | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */
713 { SvREFCNT_inc_simple_void(PL_compcv);
714 $<opval>$ = newANONATTRSUB($2, 0, (OP*)NULL, $3); }
715 optlistexpr %prec LSTOP /* ... @bar */
716 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
717 op_append_elem(OP_LIST,
718 op_prepend_elem(OP_LIST, $<opval>4, $5), $1));
722 /* Names of methods. May use $object->$methodname */
727 /* Some kind of subscripted expression */
728 subscripted: gelem '{' expr ';' '}' /* *main::{something} */
729 /* In this and all the hash accessors, ';' is
730 * provided by the tokeniser */
731 { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); }
732 | scalar '[' expr ']' /* $array[$element] */
733 { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3));
735 | term ARROW '[' expr ']' /* somearef->[$element] */
736 { $$ = newBINOP(OP_AELEM, 0,
737 ref(newAVREF($1),OP_RV2AV),
740 | subscripted '[' expr ']' /* $foo->[$bar]->[$baz] */
741 { $$ = newBINOP(OP_AELEM, 0,
742 ref(newAVREF($1),OP_RV2AV),
745 | scalar '{' expr ';' '}' /* $foo{bar();} */
746 { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
748 | term ARROW '{' expr ';' '}' /* somehref->{bar();} */
749 { $$ = newBINOP(OP_HELEM, 0,
750 ref(newHVREF($1),OP_RV2HV),
752 | subscripted '{' expr ';' '}' /* $foo->[bar]->{baz;} */
753 { $$ = newBINOP(OP_HELEM, 0,
754 ref(newHVREF($1),OP_RV2HV),
756 | term ARROW '(' ')' /* $subref->() */
757 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
758 newCVREF(0, scalar($1))); }
759 | term ARROW '(' expr ')' /* $subref->(@args) */
760 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
761 op_append_elem(OP_LIST, $4,
762 newCVREF(0, scalar($1)))); }
764 | subscripted '(' expr ')' /* $foo->{bar}->(@args) */
765 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
766 op_append_elem(OP_LIST, $3,
767 newCVREF(0, scalar($1)))); }
768 | subscripted '(' ')' /* $foo->{bar}->() */
769 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
770 newCVREF(0, scalar($1))); }
771 | '(' expr ')' '[' expr ']' /* list slice */
772 { $$ = newSLICEOP(0, $5, $2); }
773 | QWLIST '[' expr ']' /* list literal slice */
774 { $$ = newSLICEOP(0, $3, $1); }
775 | '(' ')' '[' expr ']' /* empty list slice! */
776 { $$ = newSLICEOP(0, $4, (OP*)NULL); }
779 /* Binary operators between terms */
780 termbinop: term ASSIGNOP term /* $x = $y */
781 { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); }
782 | term POWOP term /* $x ** $y */
783 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
784 | term MULOP term /* $x * $y, $x x $y */
785 { if ($2 != OP_REPEAT)
787 $$ = newBINOP($2, 0, $1, scalar($3));
789 | term ADDOP term /* $x + $y */
790 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
791 | term SHIFTOP term /* $x >> $y, $x << $y */
792 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
793 | term RELOP term /* $x > $y, etc. */
794 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
795 | term EQOP term /* $x == $y, $x eq $y */
796 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
797 | term BITANDOP term /* $x & $y */
798 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
799 | term BITOROP term /* $x | $y */
800 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
801 | term DOTDOT term /* $x..$y, $x...$y */
802 { $$ = newRANGE($2, scalar($1), scalar($3)); }
803 | term ANDAND term /* $x && $y */
804 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
805 | term OROR term /* $x || $y */
806 { $$ = newLOGOP(OP_OR, 0, $1, $3); }
807 | term DORDOR term /* $x // $y */
808 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
809 | term MATCHOP term /* $x =~ /$y/ */
810 { $$ = bind_match($2, $1, $3); }
813 /* Unary operators and terms */
814 termunop : '-' term %prec UMINUS /* -$x */
815 { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); }
816 | '+' term %prec UMINUS /* +$x */
820 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
822 { $$ = newUNOP($1, 0, scalar($2)); }
823 | term POSTINC /* $x++ */
824 { $$ = newUNOP(OP_POSTINC, 0,
825 op_lvalue(scalar($1), OP_POSTINC)); }
826 | term POSTDEC /* $x-- */
827 { $$ = newUNOP(OP_POSTDEC, 0,
828 op_lvalue(scalar($1), OP_POSTDEC));}
829 | term POSTJOIN /* implicit join after interpolated ->@ */
830 { $$ = op_convert_list(OP_JOIN, 0,
840 | PREINC term /* ++$x */
841 { $$ = newUNOP(OP_PREINC, 0,
842 op_lvalue(scalar($2), OP_PREINC)); }
843 | PREDEC term /* --$x */
844 { $$ = newUNOP(OP_PREDEC, 0,
845 op_lvalue(scalar($2), OP_PREDEC)); }
849 /* Constructors for anonymous data */
850 anonymous: '[' expr ']'
851 { $$ = newANONLIST($2); }
853 { $$ = newANONLIST((OP*)NULL);}
854 | HASHBRACK expr ';' '}' %prec '(' /* { foo => "Bar" } */
855 { $$ = newANONHASH($2); }
856 | HASHBRACK ';' '}' %prec '(' /* { } (';' by tokener) */
857 { $$ = newANONHASH((OP*)NULL); }
858 | ANONSUB startanonsub proto subattrlist block %prec '('
859 { SvREFCNT_inc_simple_void(PL_compcv);
860 $$ = newANONATTRSUB($2, $3, $4, $5); }
861 | ANONSUB startanonsub remember subsignature subattrlist '{' stmtseq '}' %prec '('
864 if (parser->copline > (line_t)$6)
865 parser->copline = (line_t)$6;
867 op_append_list(OP_LINESEQ, $4, $7));
868 SvREFCNT_inc_simple_void(PL_compcv);
869 $$ = newANONATTRSUB($2, NULL, $5, body);
874 /* Things called with "do" */
875 termdo : DO term %prec UNIOP /* do $filename */
876 { $$ = dofile($2, $1);}
877 | DO block %prec '(' /* do { code */
878 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($2));}
885 | term '?' term ':' term
886 { $$ = newCONDOP(0, $1, $3, $5); }
887 | REFGEN term /* \$x, \@y, \%z */
888 { $$ = newUNOP(OP_REFGEN, 0, $2); }
889 | myattrterm %prec UNIOP
891 | LOCAL term %prec UNIOP
892 { $$ = localize($2,$1); }
894 { $$ = sawparens($2); }
898 { $$ = sawparens(newNULLLIST()); }
907 | arylen %prec '(' /* $#x, $#{ something } */
908 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
911 | sliceme '[' expr ']' /* array slice */
912 { $$ = op_prepend_elem(OP_ASLICE,
913 newOP(OP_PUSHMARK, 0),
914 newLISTOP(OP_ASLICE, 0,
916 ref($1, OP_ASLICE)));
919 $1->op_private & OPpSLICEWARNING;
921 | kvslice '[' expr ']' /* array key/value slice */
922 { $$ = op_prepend_elem(OP_KVASLICE,
923 newOP(OP_PUSHMARK, 0),
924 newLISTOP(OP_KVASLICE, 0,
926 ref(oopsAV($1), OP_KVASLICE)));
929 $1->op_private & OPpSLICEWARNING;
931 | sliceme '{' expr ';' '}' /* @hash{@keys} */
932 { $$ = op_prepend_elem(OP_HSLICE,
933 newOP(OP_PUSHMARK, 0),
934 newLISTOP(OP_HSLICE, 0,
936 ref(oopsHV($1), OP_HSLICE)));
939 $1->op_private & OPpSLICEWARNING;
941 | kvslice '{' expr ';' '}' /* %hash{@keys} */
942 { $$ = op_prepend_elem(OP_KVHSLICE,
943 newOP(OP_PUSHMARK, 0),
944 newLISTOP(OP_KVHSLICE, 0,
946 ref($1, OP_KVHSLICE)));
949 $1->op_private & OPpSLICEWARNING;
954 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
955 | amper '(' ')' /* &foo() or foo() */
956 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1));
958 | amper '(' expr ')' /* &foo(@args) or foo(@args) */
960 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
961 op_append_elem(OP_LIST, $3, scalar($1)));
963 | NOAMP subname optlistexpr /* foo @args (no parens) */
964 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
965 op_append_elem(OP_LIST, $3, scalar($2)));
968 { $$ = newSVREF($1); }
970 { $$ = newAVREF($1); }
972 { $$ = newHVREF($1); }
974 { $$ = newUNOP(OP_ENTERSUB, 0,
975 scalar(newCVREF($3,$1))); }
976 | term ARROW '*' '*' %prec '('
977 { $$ = newGVREF(0,$1); }
978 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
979 { $$ = newOP($1, OPf_SPECIAL);
980 PL_hints |= HINT_BLOCK_SCOPE; }
982 { $$ = newLOOPEX($1,$2); }
983 | NOTOP listexpr /* not $foo */
984 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
985 | UNIOP /* Unary op, $_ implied */
986 { $$ = newOP($1, 0); }
987 | UNIOP block /* eval { foo }* */
988 { $$ = newUNOP($1, 0, $2); }
989 | UNIOP term /* Unary op */
990 { $$ = newUNOP($1, 0, $2); }
991 | REQUIRE /* require, $_ implied */
992 { $$ = newOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0); }
993 | REQUIRE term /* require Foo */
994 { $$ = newUNOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0, $2); }
996 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
997 | UNIOPSUB term /* Sub treated as unop */
998 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
999 op_append_elem(OP_LIST, $2, scalar($1))); }
1000 | FUNC0 /* Nullary operator */
1001 { $$ = newOP($1, 0); }
1003 { $$ = newOP($1, 0);}
1004 | FUNC0OP /* Same as above, but op created in toke.c */
1008 | FUNC0SUB /* Sub treated as nullop */
1009 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
1010 | FUNC1 '(' ')' /* not () */
1011 { $$ = ($1 == OP_NOT)
1012 ? newUNOP($1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
1013 : newOP($1, OPf_SPECIAL); }
1014 | FUNC1 '(' expr ')' /* not($foo) */
1015 { $$ = newUNOP($1, 0, $3); }
1016 | PMFUNC /* m//, s///, qr//, tr/// */
1018 if ( $1->op_type != OP_TRANS
1019 && $1->op_type != OP_TRANSR
1020 && (((PMOP*)$1)->op_pmflags & PMf_HAS_CV))
1022 $<ival>$ = start_subparse(FALSE, CVf_ANON);
1023 SAVEFREESV(PL_compcv);
1027 '(' listexpr optrepl ')'
1028 { $$ = pmruntime($1, $4, $5, 1, $<ival>2); }
1033 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
1034 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
1039 /* "my" declarations, with optional attributes */
1040 myattrterm: MY myterm myattrlist
1041 { $$ = my_attrs($2,$3); }
1043 { $$ = localize($2,$1); }
1046 /* Things that can be "my"'d */
1047 myterm : '(' expr ')'
1048 { $$ = sawparens($2); }
1050 { $$ = sawparens(newNULLLIST()); }
1060 /* Basic list expressions */
1061 optlistexpr: /* NULL */ %prec PREC_LOW
1063 | listexpr %prec PREC_LOW
1079 /* A little bit of trickery to make "for my $foo (@bar)" actually be
1082 { parser->in_my = 0; $$ = my($1); }
1090 refgen_topic: my_var
1095 { $$ = newCVREF($1,$2); }
1098 scalar : '$' indirob
1099 { $$ = newSVREF($2); }
1103 { $$ = newAVREF($2);
1104 if ($$) $$->op_private |= $1;
1109 { $$ = newHVREF($2);
1110 if ($$) $$->op_private |= $1;
1114 arylen : DOLSHARP indirob
1115 { $$ = newAVREF($2); }
1116 | term ARROW DOLSHARP '*'
1117 { $$ = newAVREF($1); }
1121 { $$ = newGVREF(0,$2); }
1126 { $$ = newAVREF($1); }
1131 { $$ = newHVREF($1); }
1136 { $$ = newGVREF(0,$1); }
1139 /* Indirect objects */
1141 { $$ = scalar($1); }
1142 | scalar %prec PREC_LOW
1143 { $$ = scalar($1); }
1145 { $$ = op_scope($1); }