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 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 miexpr ')' mblock else
364 newCONDOP(0, $4, op_scope($6), $7));
365 parser->copline = (line_t)$1;
367 | GIVEN '(' remember mexpr ')' mblock
369 const PADOFFSET offset = pad_findmy_pvs("$_", 0);
371 newGIVENOP($4, op_scope($6),
373 || PAD_COMPNAME_FLAGS_isOUR(offset)
376 parser->copline = (line_t)$1;
378 | WHEN '(' remember mexpr ')' mblock
379 { $$ = block_end($3, newWHENOP($4, op_scope($6))); }
381 { $$ = newWHENOP(0, op_scope($2)); }
382 | WHILE '(' remember texpr ')' mintro mblock cont
385 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
387 parser->copline = (line_t)$1;
389 | UNTIL '(' remember iexpr ')' mintro mblock cont
392 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
394 parser->copline = (line_t)$1;
396 | FOR '(' remember mnexpr ';'
397 { parser->expect = XTERM; }
399 { parser->expect = XTERM; }
404 OP *forop = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
405 scalar($7), $13, $11, $10);
407 forop = op_prepend_elem(OP_LINESEQ, initop,
408 op_append_elem(OP_LINESEQ,
409 newOP(OP_UNSTACK, OPf_SPECIAL),
412 PL_hints |= HINT_BLOCK_SCOPE;
413 $$ = block_end($3, forop);
414 parser->copline = (line_t)$1;
416 | FOR MY remember my_scalar '(' mexpr ')' mblock cont
418 $$ = block_end($3, newFOROP(0, $4, $6, $8, $9));
419 parser->copline = (line_t)$1;
421 | FOR scalar '(' remember mexpr ')' mblock cont
423 $$ = block_end($4, newFOROP(0,
424 op_lvalue($2, OP_ENTERLOOP), $5, $7, $8));
425 parser->copline = (line_t)$1;
427 | FOR REFGEN MY remember my_var
428 { parser->in_my = 0; $<opval>$ = my($5); }
429 '(' mexpr ')' mblock cont
435 newUNOP(OP_REFGEN, 0,
440 parser->copline = (line_t)$1;
442 | FOR REFGEN refgen_topic '(' remember mexpr ')' mblock cont
444 $$ = block_end($5, newFOROP(
445 0, op_lvalue(newUNOP(OP_REFGEN, 0,
447 OP_ENTERLOOP), $6, $8, $9));
448 parser->copline = (line_t)$1;
450 | FOR '(' remember mexpr ')' mblock cont
453 newFOROP(0, (OP*)NULL, $4, $6, $7));
454 parser->copline = (line_t)$1;
458 /* a block is a loop that happens once */
459 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
460 (OP*)NULL, $1, $2, 0);
462 | PACKAGE WORD WORD '{' remember
471 /* a block is a loop that happens once */
472 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
473 (OP*)NULL, block_end($5, $7), (OP*)NULL, 0);
474 if (parser->copline > (line_t)$4)
475 parser->copline = (line_t)$4;
484 parser->copline = NOLINE;
489 formline: THING formarg
493 list = op_append_elem(OP_LIST, $1, term);
498 if (parser->copline == NOLINE)
499 parser->copline = CopLINE(PL_curcop)-1;
500 else parser->copline--;
501 $$ = newSTATEOP(0, NULL,
502 op_convert_list(OP_FORMLINE, 0, list));
508 | FORMLBRACK stmtseq FORMRBRACK
509 { $$ = op_unscope($2); }
512 /* An expression which may have a side-effect */
518 { $$ = newLOGOP(OP_AND, 0, $3, $1); }
520 { $$ = newLOGOP(OP_OR, 0, $3, $1); }
522 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); }
524 { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1); }
526 { $$ = newFOROP(0, (OP*)NULL, $3, $1, (OP*)NULL);
527 parser->copline = (line_t)$2; }
529 { $$ = newWHENOP($3, op_scope($1)); }
532 /* else and elsif blocks */
537 ($2)->op_flags |= OPf_PARENS;
540 | ELSIF '(' mexpr ')' mblock else
541 { parser->copline = (line_t)$1;
543 newSTATEOP(OPf_SPECIAL,NULL,$3),
545 PL_hints |= HINT_BLOCK_SCOPE;
549 /* Continue blocks */
553 { $$ = op_scope($2); }
556 /* determine whether there are any new my declarations */
558 { $$ = (PL_min_intro_pending &&
559 PL_max_intro_pending >= PL_min_intro_pending);
562 /* Normal expression */
568 /* Boolean expression */
569 texpr : /* NULL means true */
571 (void)scan_num("1", &tmplval);
572 $$ = tmplval.opval; }
576 /* Inverted boolean expression */
578 { $$ = invert(scalar($1)); }
581 /* Expression with its own lexical scope */
583 { $$ = $1; intro_my(); }
587 { $$ = $1; intro_my(); }
591 { $$ = $1; intro_my(); }
594 formname: WORD { $$ = $1; }
595 | /* NULL */ { $$ = (OP*)NULL; }
598 startsub: /* NULL */ /* start a regular subroutine scope */
599 { $$ = start_subparse(FALSE, 0);
600 SAVEFREESV(PL_compcv); }
604 startanonsub: /* NULL */ /* start an anonymous subroutine scope */
605 { $$ = start_subparse(FALSE, CVf_ANON);
606 SAVEFREESV(PL_compcv); }
609 startformsub: /* NULL */ /* start a format subroutine scope */
610 { $$ = start_subparse(TRUE, 0);
611 SAVEFREESV(PL_compcv); }
614 /* Name of a subroutine - must be a bareword, could be special */
619 /* Subroutine prototype */
625 /* Optional list of subroutine attributes */
626 subattrlist: /* NULL */
634 /* List of attributes for a "my" variable declaration */
635 myattrlist: COLONATTR THING
641 /* Subroutine signature */
644 /* We shouldn't get here otherwise */
645 assert(FEATURE_SIGNATURES_IS_ENABLED);
647 Perl_ck_warner_d(aTHX_
648 packWARN(WARN_EXPERIMENTAL__SIGNATURES),
649 "The signatures feature is experimental");
650 $<opval>$ = parse_subsignature();
654 $$ = op_append_list(OP_LINESEQ, $<opval>2,
655 newSTATEOP(0, NULL, sawparens(newNULLLIST())));
656 parser->expect = XATTRBLOCK;
660 /* Optional subroutine body, for named subroutine declaration */
662 | ';' { $$ = (OP*)NULL; }
665 /* Ordinary expressions; logical combinations */
666 expr : expr ANDOP expr
667 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
669 { $$ = newLOGOP($2, 0, $1, $3); }
671 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
672 | listexpr %prec PREC_LOW
675 /* Expressions are a list of terms joined by commas */
676 listexpr: listexpr ','
681 $$ = op_append_elem(OP_LIST, $1, term);
683 | term %prec PREC_LOW
687 listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
688 { $$ = op_convert_list($1, OPf_STACKED,
689 op_prepend_elem(OP_LIST, newGVREF($1,$2), $3) );
691 | FUNC '(' indirob expr ')' /* print ($fh @args */
692 { $$ = op_convert_list($1, OPf_STACKED,
693 op_prepend_elem(OP_LIST, newGVREF($1,$3), $4) );
695 | term ARROW method '(' optexpr ')' /* $foo->bar(list) */
696 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
697 op_append_elem(OP_LIST,
698 op_prepend_elem(OP_LIST, scalar($1), $5),
699 newMETHOP(OP_METHOD, 0, $3)));
701 | term ARROW method /* $foo->bar */
702 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
703 op_append_elem(OP_LIST, scalar($1),
704 newMETHOP(OP_METHOD, 0, $3)));
706 | METHOD indirob optlistexpr /* new Class @args */
707 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
708 op_append_elem(OP_LIST,
709 op_prepend_elem(OP_LIST, $2, $3),
710 newMETHOP(OP_METHOD, 0, $1)));
712 | FUNCMETH indirob '(' optexpr ')' /* method $object (@args) */
713 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
714 op_append_elem(OP_LIST,
715 op_prepend_elem(OP_LIST, $2, $4),
716 newMETHOP(OP_METHOD, 0, $1)));
718 | LSTOP optlistexpr /* print @args */
719 { $$ = op_convert_list($1, 0, $2); }
720 | FUNC '(' optexpr ')' /* print (@args) */
721 { $$ = op_convert_list($1, 0, $3); }
722 | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */
723 { SvREFCNT_inc_simple_void(PL_compcv);
724 $<opval>$ = newANONATTRSUB($2, 0, (OP*)NULL, $3); }
725 optlistexpr %prec LSTOP /* ... @bar */
726 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
727 op_append_elem(OP_LIST,
728 op_prepend_elem(OP_LIST, $<opval>4, $5), $1));
732 /* Names of methods. May use $object->$methodname */
737 /* Some kind of subscripted expression */
738 subscripted: gelem '{' expr ';' '}' /* *main::{something} */
739 /* In this and all the hash accessors, ';' is
740 * provided by the tokeniser */
741 { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); }
742 | scalar '[' expr ']' /* $array[$element] */
743 { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3));
745 | term ARROW '[' expr ']' /* somearef->[$element] */
746 { $$ = newBINOP(OP_AELEM, 0,
747 ref(newAVREF($1),OP_RV2AV),
750 | subscripted '[' expr ']' /* $foo->[$bar]->[$baz] */
751 { $$ = newBINOP(OP_AELEM, 0,
752 ref(newAVREF($1),OP_RV2AV),
755 | scalar '{' expr ';' '}' /* $foo{bar();} */
756 { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
758 | term ARROW '{' expr ';' '}' /* somehref->{bar();} */
759 { $$ = newBINOP(OP_HELEM, 0,
760 ref(newHVREF($1),OP_RV2HV),
762 | subscripted '{' expr ';' '}' /* $foo->[bar]->{baz;} */
763 { $$ = newBINOP(OP_HELEM, 0,
764 ref(newHVREF($1),OP_RV2HV),
766 | term ARROW '(' ')' /* $subref->() */
767 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
768 newCVREF(0, scalar($1))); }
769 | term ARROW '(' expr ')' /* $subref->(@args) */
770 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
771 op_append_elem(OP_LIST, $4,
772 newCVREF(0, scalar($1)))); }
774 | subscripted '(' expr ')' /* $foo->{bar}->(@args) */
775 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
776 op_append_elem(OP_LIST, $3,
777 newCVREF(0, scalar($1)))); }
778 | subscripted '(' ')' /* $foo->{bar}->() */
779 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
780 newCVREF(0, scalar($1))); }
781 | '(' expr ')' '[' expr ']' /* list slice */
782 { $$ = newSLICEOP(0, $5, $2); }
783 | QWLIST '[' expr ']' /* list literal slice */
784 { $$ = newSLICEOP(0, $3, $1); }
785 | '(' ')' '[' expr ']' /* empty list slice! */
786 { $$ = newSLICEOP(0, $4, (OP*)NULL); }
789 /* Binary operators between terms */
790 termbinop: term ASSIGNOP term /* $x = $y */
791 { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); }
792 | term POWOP term /* $x ** $y */
793 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
794 | term MULOP term /* $x * $y, $x x $y */
795 { if ($2 != OP_REPEAT)
797 $$ = newBINOP($2, 0, $1, scalar($3));
799 | term ADDOP term /* $x + $y */
800 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
801 | term SHIFTOP term /* $x >> $y, $x << $y */
802 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
803 | term RELOP term /* $x > $y, etc. */
804 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
805 | term EQOP term /* $x == $y, $x eq $y */
806 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
807 | term BITANDOP term /* $x & $y */
808 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
809 | term BITOROP term /* $x | $y */
810 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
811 | term DOTDOT term /* $x..$y, $x...$y */
812 { $$ = newRANGE($2, scalar($1), scalar($3)); }
813 | term ANDAND term /* $x && $y */
814 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
815 | term OROR term /* $x || $y */
816 { $$ = newLOGOP(OP_OR, 0, $1, $3); }
817 | term DORDOR term /* $x // $y */
818 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
819 | term MATCHOP term /* $x =~ /$y/ */
820 { $$ = bind_match($2, $1, $3); }
823 /* Unary operators and terms */
824 termunop : '-' term %prec UMINUS /* -$x */
825 { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); }
826 | '+' term %prec UMINUS /* +$x */
830 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
832 { $$ = newUNOP($1, 0, scalar($2)); }
833 | term POSTINC /* $x++ */
834 { $$ = newUNOP(OP_POSTINC, 0,
835 op_lvalue(scalar($1), OP_POSTINC)); }
836 | term POSTDEC /* $x-- */
837 { $$ = newUNOP(OP_POSTDEC, 0,
838 op_lvalue(scalar($1), OP_POSTDEC));}
839 | term POSTJOIN /* implicit join after interpolated ->@ */
840 { $$ = op_convert_list(OP_JOIN, 0,
850 | PREINC term /* ++$x */
851 { $$ = newUNOP(OP_PREINC, 0,
852 op_lvalue(scalar($2), OP_PREINC)); }
853 | PREDEC term /* --$x */
854 { $$ = newUNOP(OP_PREDEC, 0,
855 op_lvalue(scalar($2), OP_PREDEC)); }
859 /* Constructors for anonymous data */
860 anonymous: '[' expr ']'
861 { $$ = newANONLIST($2); }
863 { $$ = newANONLIST((OP*)NULL);}
864 | HASHBRACK expr ';' '}' %prec '(' /* { foo => "Bar" } */
865 { $$ = newANONHASH($2); }
866 | HASHBRACK ';' '}' %prec '(' /* { } (';' by tokener) */
867 { $$ = newANONHASH((OP*)NULL); }
868 | ANONSUB startanonsub proto subattrlist block %prec '('
869 { SvREFCNT_inc_simple_void(PL_compcv);
870 $$ = newANONATTRSUB($2, $3, $4, $5); }
871 | ANONSUB startanonsub remember subsignature subattrlist '{' stmtseq '}' %prec '('
874 if (parser->copline > (line_t)$6)
875 parser->copline = (line_t)$6;
877 op_append_list(OP_LINESEQ, $4, $7));
878 SvREFCNT_inc_simple_void(PL_compcv);
879 $$ = newANONATTRSUB($2, NULL, $5, body);
884 /* Things called with "do" */
885 termdo : DO term %prec UNIOP /* do $filename */
886 { $$ = dofile($2, $1);}
887 | DO block %prec '(' /* do { code */
888 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($2));}
895 | term '?' term ':' term
896 { $$ = newCONDOP(0, $1, $3, $5); }
897 | REFGEN term /* \$x, \@y, \%z */
898 { $$ = newUNOP(OP_REFGEN, 0, $2); }
899 | myattrterm %prec UNIOP
901 | LOCAL term %prec UNIOP
902 { $$ = localize($2,$1); }
904 { $$ = sawparens($2); }
908 { $$ = sawparens(newNULLLIST()); }
917 | arylen %prec '(' /* $#x, $#{ something } */
918 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
921 | sliceme '[' expr ']' /* array slice */
922 { $$ = op_prepend_elem(OP_ASLICE,
923 newOP(OP_PUSHMARK, 0),
924 newLISTOP(OP_ASLICE, 0,
926 ref($1, OP_ASLICE)));
929 $1->op_private & OPpSLICEWARNING;
931 | kvslice '[' expr ']' /* array key/value slice */
932 { $$ = op_prepend_elem(OP_KVASLICE,
933 newOP(OP_PUSHMARK, 0),
934 newLISTOP(OP_KVASLICE, 0,
936 ref(oopsAV($1), OP_KVASLICE)));
939 $1->op_private & OPpSLICEWARNING;
941 | sliceme '{' expr ';' '}' /* @hash{@keys} */
942 { $$ = op_prepend_elem(OP_HSLICE,
943 newOP(OP_PUSHMARK, 0),
944 newLISTOP(OP_HSLICE, 0,
946 ref(oopsHV($1), OP_HSLICE)));
949 $1->op_private & OPpSLICEWARNING;
951 | kvslice '{' expr ';' '}' /* %hash{@keys} */
952 { $$ = op_prepend_elem(OP_KVHSLICE,
953 newOP(OP_PUSHMARK, 0),
954 newLISTOP(OP_KVHSLICE, 0,
956 ref($1, OP_KVHSLICE)));
959 $1->op_private & OPpSLICEWARNING;
964 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
965 | amper '(' ')' /* &foo() or foo() */
966 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1));
968 | amper '(' expr ')' /* &foo(@args) or foo(@args) */
970 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
971 op_append_elem(OP_LIST, $3, scalar($1)));
973 | NOAMP subname optlistexpr /* foo @args (no parens) */
974 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
975 op_append_elem(OP_LIST, $3, scalar($2)));
978 { $$ = newSVREF($1); }
980 { $$ = newAVREF($1); }
982 { $$ = newHVREF($1); }
984 { $$ = newUNOP(OP_ENTERSUB, 0,
985 scalar(newCVREF($3,$1))); }
986 | term ARROW '*' '*' %prec '('
987 { $$ = newGVREF(0,$1); }
988 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
989 { $$ = newOP($1, OPf_SPECIAL);
990 PL_hints |= HINT_BLOCK_SCOPE; }
992 { $$ = newLOOPEX($1,$2); }
993 | NOTOP listexpr /* not $foo */
994 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
995 | UNIOP /* Unary op, $_ implied */
996 { $$ = newOP($1, 0); }
997 | UNIOP block /* eval { foo }* */
998 { $$ = newUNOP($1, 0, $2); }
999 | UNIOP term /* Unary op */
1000 { $$ = newUNOP($1, 0, $2); }
1001 | REQUIRE /* require, $_ implied */
1002 { $$ = newOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0); }
1003 | REQUIRE term /* require Foo */
1004 { $$ = newUNOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0, $2); }
1006 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
1007 | UNIOPSUB term /* Sub treated as unop */
1008 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1009 op_append_elem(OP_LIST, $2, scalar($1))); }
1010 | FUNC0 /* Nullary operator */
1011 { $$ = newOP($1, 0); }
1013 { $$ = newOP($1, 0);}
1014 | FUNC0OP /* Same as above, but op created in toke.c */
1018 | FUNC0SUB /* Sub treated as nullop */
1019 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
1020 | FUNC1 '(' ')' /* not () */
1021 { $$ = ($1 == OP_NOT)
1022 ? newUNOP($1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
1023 : newOP($1, OPf_SPECIAL); }
1024 | FUNC1 '(' expr ')' /* not($foo) */
1025 { $$ = newUNOP($1, 0, $3); }
1026 | PMFUNC /* m//, s///, qr//, tr/// */
1028 if ( $1->op_type != OP_TRANS
1029 && $1->op_type != OP_TRANSR
1030 && (((PMOP*)$1)->op_pmflags & PMf_HAS_CV))
1032 $<ival>$ = start_subparse(FALSE, CVf_ANON);
1033 SAVEFREESV(PL_compcv);
1037 '(' listexpr optrepl ')'
1038 { $$ = pmruntime($1, $4, $5, 1, $<ival>2); }
1043 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
1044 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
1049 /* "my" declarations, with optional attributes */
1050 myattrterm: MY myterm myattrlist
1051 { $$ = my_attrs($2,$3); }
1053 { $$ = localize($2,$1); }
1056 /* Things that can be "my"'d */
1057 myterm : '(' expr ')'
1058 { $$ = sawparens($2); }
1060 { $$ = sawparens(newNULLLIST()); }
1070 /* Basic list expressions */
1071 optlistexpr: /* NULL */ %prec PREC_LOW
1073 | listexpr %prec PREC_LOW
1089 /* A little bit of trickery to make "for my $foo (@bar)" actually be
1092 { parser->in_my = 0; $$ = my($1); }
1100 refgen_topic: my_var
1105 { $$ = newCVREF($1,$2); }
1108 scalar : '$' indirob
1109 { $$ = newSVREF($2); }
1113 { $$ = newAVREF($2);
1114 if ($$) $$->op_private |= $1;
1119 { $$ = newHVREF($2);
1120 if ($$) $$->op_private |= $1;
1124 arylen : DOLSHARP indirob
1125 { $$ = newAVREF($2); }
1126 | term ARROW DOLSHARP '*'
1127 { $$ = newAVREF($1); }
1131 { $$ = newGVREF(0,$2); }
1136 { $$ = newAVREF($1); }
1141 { $$ = newHVREF($1); }
1146 { $$ = newGVREF(0,$1); }
1149 /* Indirect objects */
1151 { $$ = scalar($1); }
1152 | scalar %prec PREC_LOW
1153 { $$ = scalar($1); }
1155 { $$ = op_scope($1); }