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 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 GRAMSUBSIGNATURE
48 %token <ival> PERLY_AMPERSAND
49 %token <ival> PERLY_BRACE_OPEN
50 %token <ival> PERLY_BRACE_CLOSE
51 %token <ival> PERLY_BRACKET_OPEN
52 %token <ival> PERLY_BRACKET_CLOSE
53 %token <ival> PERLY_COMMA
54 %token <ival> PERLY_DOLLAR
55 %token <ival> PERLY_DOT
56 %token <ival> PERLY_EQUAL_SIGN
57 %token <ival> PERLY_MINUS
58 %token <ival> PERLY_PERCENT_SIGN
59 %token <ival> PERLY_PLUS
60 %token <ival> PERLY_SEMICOLON
61 %token <ival> PERLY_SLASH
62 %token <ival> PERLY_SNAIL
63 %token <ival> PERLY_STAR
65 %token <opval> BAREWORD METHOD FUNCMETH THING PMFUNC PRIVATEREF QWLIST
66 %token <opval> FUNC0OP FUNC0SUB UNIOPSUB LSTOPSUB
67 %token <opval> PLUGEXPR PLUGSTMT
69 %token <ival> FORMAT SUB SIGSUB ANONSUB ANON_SIGSUB PACKAGE USE
70 %token <ival> WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE FOR
71 %token <ival> GIVEN WHEN DEFAULT
72 %token <ival> TRY CATCH
73 %token <ival> LOOPEX DOTDOT YADAYADA
74 %token <ival> FUNC0 FUNC1 FUNC UNIOP LSTOP
75 %token <ival> MULOP ADDOP
76 %token <ival> DOLSHARP DO HASHBRACK NOAMP
77 %token <ival> LOCAL MY REQUIRE
78 %token <ival> COLONATTR FORMLBRACK FORMRBRACK
79 %token <ival> SUBLEXSTART SUBLEXEND
81 %type <ival> grammar remember mremember
82 %type <ival> startsub startanonsub startformsub
86 %type <opval> stmtseq fullstmt labfullstmt barestmt block mblock else
87 %type <opval> expr term subscripted scalar ary hsh arylen star amper sideff
88 %type <opval> condition
89 %type <opval> sliceme kvslice gelem
90 %type <opval> listexpr nexpr texpr iexpr mexpr mnexpr
91 %type <opval> optlistexpr optexpr optrepl indirob listop method
92 %type <opval> formname subname proto cont my_scalar my_var
93 %type <opval> refgen_topic formblock
94 %type <opval> subattrlist myattrlist myattrterm myterm
95 %type <opval> termbinop termunop anonymous termdo
96 %type <opval> termrelop relopchain termeqop eqopchain
97 %type <ival> sigslurpsigil
98 %type <opval> sigvarname sigdefault sigscalarelem sigslurpelem
99 %type <opval> sigelem siglist siglistornull subsigguts subsignature optsubsignature
100 %type <opval> subbody optsubbody sigsubbody optsigsubbody
101 %type <opval> formstmtseq formline formarg
103 %nonassoc <ival> PREC_LOW
109 %nonassoc LSTOP LSTOPSUB
111 %right <ival> ASSIGNOP
112 %right <ival> PERLY_QUESTION_MARK PERLY_COLON
114 %left <ival> OROR DORDOR
117 %left <ival> BITANDOP
118 %left <ival> CHEQOP NCEQOP
119 %left <ival> CHRELOP NCRELOP
120 %nonassoc UNIOP UNIOPSUB
126 %right <ival> PERLY_EXCLAMATION_MARK PERLY_TILDE UMINUS REFGEN
128 %nonassoc <ival> PREINC PREDEC POSTINC POSTDEC POSTJOIN
130 %nonassoc <ival> PERLY_PAREN_CLOSE
131 %left <ival> PERLY_PAREN_OPEN
132 %left PERLY_BRACKET_OPEN PERLY_BRACE_OPEN
136 /* Top-level choice of what kind of thing yyparse was called to parse */
139 parser->expect = XSTATE;
144 newPROG(block_end($remember,$stmtseq));
145 PL_compiling.cop_seq = 0;
150 parser->expect = XTERM;
155 PL_eval_root = $optexpr;
160 parser->expect = XBLOCK;
165 PL_pad_reset_pending = TRUE;
166 PL_eval_root = $block;
169 parser->yychar = yytoken = YYEOF;
173 parser->expect = XSTATE;
178 PL_pad_reset_pending = TRUE;
179 PL_eval_root = $barestmt;
182 parser->yychar = yytoken = YYEOF;
186 parser->expect = XSTATE;
191 PL_pad_reset_pending = TRUE;
192 PL_eval_root = $fullstmt;
195 parser->yychar = yytoken = YYEOF;
199 parser->expect = XSTATE;
204 PL_eval_root = $stmtseq;
209 parser->expect = XSTATE;
214 PL_eval_root = $subsigguts;
219 /* An ordinary block */
220 block : PERLY_BRACE_OPEN remember stmtseq PERLY_BRACE_CLOSE
221 { if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
222 parser->copline = (line_t)$PERLY_BRACE_OPEN;
223 $$ = block_end($remember, $stmtseq);
228 formblock: PERLY_EQUAL_SIGN remember PERLY_SEMICOLON FORMRBRACK formstmtseq PERLY_SEMICOLON PERLY_DOT
229 { if (parser->copline > (line_t)$PERLY_EQUAL_SIGN)
230 parser->copline = (line_t)$PERLY_EQUAL_SIGN;
231 $$ = block_end($remember, $formstmtseq);
235 remember: %empty /* start a full lexical scope */
236 { $$ = block_start(TRUE);
237 parser->parsed_sub = 0; }
240 mblock : PERLY_BRACE_OPEN mremember stmtseq PERLY_BRACE_CLOSE
241 { if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
242 parser->copline = (line_t)$PERLY_BRACE_OPEN;
243 $$ = block_end($mremember, $stmtseq);
247 mremember: %empty /* start a partial lexical scope */
248 { $$ = block_start(FALSE);
249 parser->parsed_sub = 0; }
252 /* A sequence of statements in the program */
255 | stmtseq[list] fullstmt
256 { $$ = op_append_list(OP_LINESEQ, $list, $fullstmt);
257 PL_pad_reset_pending = TRUE;
258 if ($list && $fullstmt)
259 PL_hints |= HINT_BLOCK_SCOPE;
263 /* A sequence of format lines */
266 | formstmtseq[list] formline
267 { $$ = op_append_list(OP_LINESEQ, $list, $formline);
268 PL_pad_reset_pending = TRUE;
269 if ($list && $formline)
270 PL_hints |= HINT_BLOCK_SCOPE;
274 /* A statement in the program, including optional labels */
277 $$ = $barestmt ? newSTATEOP(0, NULL, $barestmt) : NULL;
280 { $$ = $labfullstmt; }
283 labfullstmt: LABEL barestmt
285 SV *label = cSVOPx_sv($LABEL);
286 $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8,
287 savepv(SvPVX_const(label)), $barestmt);
290 | LABEL labfullstmt[list]
292 SV *label = cSVOPx_sv($LABEL);
293 $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8,
294 savepv(SvPVX_const(label)), $list);
299 /* A bare statement, lacking label and other aspects of state op */
302 | FORMAT startformsub formname formblock
304 CV *fmtcv = PL_compcv;
305 newFORM($startformsub, $formname, $formblock);
307 if (CvOUTSIDE(fmtcv) && !CvEVAL(CvOUTSIDE(fmtcv))) {
308 pad_add_weakref(fmtcv);
310 parser->parsed_sub = 1;
312 | SUB subname startsub
313 /* sub declaration or definition not within scope
314 of 'use feature "signatures"'*/
316 init_named_cv(PL_compcv, $subname);
318 parser->in_my_stash = NULL;
320 proto subattrlist optsubbody
322 SvREFCNT_inc_simple_void(PL_compcv);
323 $subname->op_type == OP_CONST
324 ? newATTRSUB($startsub, $subname, $proto, $subattrlist, $optsubbody)
325 : newMYSUB($startsub, $subname, $proto, $subattrlist, $optsubbody)
329 parser->parsed_sub = 1;
331 | SIGSUB subname startsub
332 /* sub declaration or definition under 'use feature
333 * "signatures"'. (Note that a signature isn't
334 * allowed in a declaration)
337 init_named_cv(PL_compcv, $subname);
339 parser->in_my_stash = NULL;
341 subattrlist optsigsubbody
343 SvREFCNT_inc_simple_void(PL_compcv);
344 $subname->op_type == OP_CONST
345 ? newATTRSUB($startsub, $subname, NULL, $subattrlist, $optsigsubbody)
346 : newMYSUB( $startsub, $subname, NULL, $subattrlist, $optsigsubbody)
350 parser->parsed_sub = 1;
352 | PACKAGE BAREWORD[version] BAREWORD[package] PERLY_SEMICOLON
356 package_version($version);
360 { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
361 BAREWORD[version] BAREWORD[module] optlistexpr PERLY_SEMICOLON
363 SvREFCNT_inc_simple_void(PL_compcv);
364 utilize($USE, $startsub, $version, $module, $optlistexpr);
365 parser->parsed_sub = 1;
368 | IF PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock else
370 $$ = block_end($remember,
371 newCONDOP(0, $mexpr, op_scope($mblock), $else));
372 parser->copline = (line_t)$IF;
374 | UNLESS PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock else
376 $$ = block_end($remember,
377 newCONDOP(0, $mexpr, $else, op_scope($mblock)));
378 parser->copline = (line_t)$UNLESS;
380 | GIVEN PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock
382 $$ = block_end($remember, newGIVENOP($mexpr, op_scope($mblock), 0));
383 parser->copline = (line_t)$GIVEN;
385 | WHEN PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock
386 { $$ = block_end($remember, newWHENOP($mexpr, op_scope($mblock))); }
388 { $$ = newWHENOP(0, op_scope($block)); }
389 | WHILE PERLY_PAREN_OPEN remember texpr PERLY_PAREN_CLOSE mintro mblock cont
391 $$ = block_end($remember,
392 newWHILEOP(0, 1, NULL,
393 $texpr, $mblock, $cont, $mintro));
394 parser->copline = (line_t)$WHILE;
396 | UNTIL PERLY_PAREN_OPEN remember iexpr PERLY_PAREN_CLOSE mintro mblock cont
398 $$ = block_end($remember,
399 newWHILEOP(0, 1, NULL,
400 $iexpr, $mblock, $cont, $mintro));
401 parser->copline = (line_t)$UNTIL;
403 | FOR PERLY_PAREN_OPEN remember mnexpr[init_mnexpr] PERLY_SEMICOLON
404 { parser->expect = XTERM; }
405 texpr PERLY_SEMICOLON
406 { parser->expect = XTERM; }
407 mintro mnexpr[iterate_mnexpr] PERLY_PAREN_CLOSE
410 OP *initop = $init_mnexpr;
411 OP *forop = newWHILEOP(0, 1, NULL,
412 scalar($texpr), $mblock, $iterate_mnexpr, $mintro);
414 forop = op_prepend_elem(OP_LINESEQ, initop,
415 op_append_elem(OP_LINESEQ,
416 newOP(OP_UNSTACK, OPf_SPECIAL),
419 PL_hints |= HINT_BLOCK_SCOPE;
420 $$ = block_end($remember, forop);
421 parser->copline = (line_t)$FOR;
423 | FOR MY remember my_scalar PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont
425 $$ = block_end($remember, newFOROP(0, $my_scalar, $mexpr, $mblock, $cont));
426 parser->copline = (line_t)$FOR;
428 | FOR scalar PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
430 $$ = block_end($remember, newFOROP(0,
431 op_lvalue($scalar, OP_ENTERLOOP), $mexpr, $mblock, $cont));
432 parser->copline = (line_t)$FOR;
434 | FOR my_refgen remember my_var
435 { parser->in_my = 0; $<opval>$ = my($my_var); }[variable]
436 PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont
442 newUNOP(OP_REFGEN, 0,
445 $mexpr, $mblock, $cont)
447 parser->copline = (line_t)$FOR;
449 | FOR REFGEN refgen_topic PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
451 $$ = block_end($remember, newFOROP(
452 0, op_lvalue(newUNOP(OP_REFGEN, 0,
454 OP_ENTERLOOP), $mexpr, $mblock, $cont));
455 parser->copline = (line_t)$FOR;
457 | FOR PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
459 $$ = block_end($remember,
460 newFOROP(0, NULL, $mexpr, $mblock, $cont));
461 parser->copline = (line_t)$FOR;
463 | TRY mblock[try] CATCH PERLY_PAREN_OPEN
464 { parser->in_my = 1; }
466 { parser->in_my = 0; intro_my(); }
467 PERLY_PAREN_CLOSE mblock[catch]
469 OP *tryblock, *catchblock;
471 tryblock = newUNOP(OP_ENTERTRY, OPf_SPECIAL, $try);
473 catchblock = newLOGOP(OP_CATCH, 0,
474 newOP(OP_NULL, 0), /* LOGOP always needs an op_first */
475 block_end($remember, op_scope($catch)));
477 /* catchblock itself is an OP_NULL; the real OP_CATCH is
479 assert(cUNOPx(catchblock)->op_first->op_type == OP_CATCH);
480 cUNOPx(catchblock)->op_first->op_targ = $scalar->op_targ;
483 $$ = op_append_list(OP_LEAVE,
485 op_append_list(OP_LINESEQ,
486 tryblock, catchblock));
490 /* a block is a loop that happens once */
491 $$ = newWHILEOP(0, 1, NULL,
492 NULL, $block, $cont, 0);
494 | PACKAGE BAREWORD[version] BAREWORD[package] PERLY_BRACE_OPEN remember
498 package_version($version);
501 stmtseq PERLY_BRACE_CLOSE
503 /* a block is a loop that happens once */
504 $$ = newWHILEOP(0, 1, NULL,
505 NULL, block_end($remember, $stmtseq), NULL, 0);
506 if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
507 parser->copline = (line_t)$PERLY_BRACE_OPEN;
509 | sideff PERLY_SEMICOLON
513 | YADAYADA PERLY_SEMICOLON
515 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
516 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
521 parser->copline = NOLINE;
526 formline: THING formarg
530 list = op_append_elem(OP_LIST, $THING, term);
535 if (parser->copline == NOLINE)
536 parser->copline = CopLINE(PL_curcop)-1;
537 else parser->copline--;
538 $$ = newSTATEOP(0, NULL,
539 op_convert_list(OP_FORMLINE, 0, list));
545 | FORMLBRACK stmtseq FORMRBRACK
546 { $$ = op_unscope($stmtseq); }
552 /* An expression which may have a side-effect */
557 | expr[body] IF condition
558 { $$ = newLOGOP(OP_AND, 0, $condition, $body); }
559 | expr[body] UNLESS condition
560 { $$ = newLOGOP(OP_OR, 0, $condition, $body); }
561 | expr[body] WHILE condition
562 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($condition), $body); }
563 | expr[body] UNTIL iexpr
564 { $$ = newLOOPOP(OPf_PARENS, 1, $iexpr, $body); }
565 | expr[body] FOR condition
566 { $$ = newFOROP(0, NULL, $condition, $body, NULL);
567 parser->copline = (line_t)$FOR; }
568 | expr[body] WHEN condition
569 { $$ = newWHENOP($condition, op_scope($body)); }
572 /* else and elsif blocks */
577 ($mblock)->op_flags |= OPf_PARENS;
578 $$ = op_scope($mblock);
580 | ELSIF PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock else[else.recurse]
581 { parser->copline = (line_t)$ELSIF;
583 newSTATEOP(OPf_SPECIAL,NULL,$mexpr),
584 op_scope($mblock), $[else.recurse]);
585 PL_hints |= HINT_BLOCK_SCOPE;
589 /* Continue blocks */
593 { $$ = op_scope($block); }
596 /* determine whether there are any new my declarations */
598 { $$ = (PL_min_intro_pending &&
599 PL_max_intro_pending >= PL_min_intro_pending);
602 /* Normal expression */
608 /* Boolean expression */
609 texpr : %empty /* NULL means true */
611 (void)scan_num("1", &tmplval);
612 $$ = tmplval.opval; }
616 /* Inverted boolean expression */
618 { $$ = invert(scalar($expr)); }
621 /* Expression with its own lexical scope */
623 { $$ = $expr; intro_my(); }
627 { $$ = $nexpr; intro_my(); }
630 formname: BAREWORD { $$ = $BAREWORD; }
631 | %empty { $$ = NULL; }
634 startsub: %empty /* start a regular subroutine scope */
635 { $$ = start_subparse(FALSE, 0);
636 SAVEFREESV(PL_compcv); }
640 startanonsub: %empty /* start an anonymous subroutine scope */
641 { $$ = start_subparse(FALSE, CVf_ANON);
642 SAVEFREESV(PL_compcv); }
645 startformsub: %empty /* start a format subroutine scope */
646 { $$ = start_subparse(TRUE, 0);
647 SAVEFREESV(PL_compcv); }
650 /* Name of a subroutine - must be a bareword, could be special */
655 /* Subroutine prototype */
661 /* Optional list of subroutine attributes */
670 /* List of attributes for a "my" variable declaration */
671 myattrlist: COLONATTR THING
679 /* --------------------------------------
680 * subroutine signature parsing
683 /* the '' or 'foo' part of a '$' or '@foo' etc signature variable */
685 { parser->in_my = 0; $$ = NULL; }
687 { parser->in_my = 0; $$ = $PRIVATEREF; }
696 /* @, %, @foo, %foo */
697 sigslurpelem: sigslurpsigil sigvarname sigdefault/* def only to catch errors */
699 I32 sigil = $sigslurpsigil;
700 OP *var = $sigvarname;
701 OP *defexpr = $sigdefault;
703 if (parser->sig_slurpy)
704 yyerror("Multiple slurpy parameters not allowed");
705 parser->sig_slurpy = (char)sigil;
708 yyerror("A slurpy parameter may not have "
711 $$ = var ? newSTATEOP(0, NULL, var) : NULL;
715 /* default part of sub signature scalar element: i.e. '= default_expr' */
719 { $$ = newOP(OP_NULL, 0); }
724 /* subroutine signature scalar element: e.g. '$x', '$=', '$x = $default' */
726 PERLY_DOLLAR sigvarname sigdefault
728 OP *var = $sigvarname;
729 OP *defexpr = $sigdefault;
731 if (parser->sig_slurpy)
732 yyerror("Slurpy parameter not last");
737 parser->sig_optelems++;
739 if ( defexpr->op_type == OP_NULL
740 && !(defexpr->op_flags & OPf_KIDS))
742 /* handle '$=' special case */
744 yyerror("Optional parameter "
745 "lacks default expression");
749 /* a normal '=default' expression */
750 OP *defop = (OP*)alloc_LOGOP(OP_ARGDEFELEM,
753 /* re-purpose op_targ to hold @_ index */
755 (PADOFFSET)(parser->sig_elems - 1);
758 var->op_flags |= OPf_STACKED;
759 (void)op_sibling_splice(var,
764 var = newUNOP(OP_NULL, 0, defop);
767 /* NB: normally the first child of a
768 * logop is executed before the logop,
769 * and it pushes a boolean result
770 * ready for the logop. For ARGDEFELEM,
771 * the op itself does the boolean
772 * calculation, so set the first op to
775 var->op_next = defop;
776 defexpr->op_next = var;
780 if (parser->sig_optelems)
781 yyerror("Mandatory parameter "
782 "follows optional parameter");
785 $$ = var ? newSTATEOP(0, NULL, var) : NULL;
790 /* subroutine signature element: e.g. '$x = $default' or '%h' */
791 sigelem: sigscalarelem
792 { parser->in_my = KEY_sigvar; $$ = $sigscalarelem; }
794 { parser->in_my = KEY_sigvar; $$ = $sigslurpelem; }
797 /* list of subroutine signature elements */
799 siglist[list] PERLY_COMMA
801 | siglist[list] PERLY_COMMA sigelem[element]
803 $$ = op_append_list(OP_LINESEQ, $list, $element);
805 | sigelem[element] %prec PREC_LOW
810 siglistornull: %empty
815 /* optional subroutine signature */
816 optsubsignature: %empty
819 { $$ = $subsignature; }
821 /* Subroutine signature */
822 subsignature: PERLY_PAREN_OPEN subsigguts PERLY_PAREN_CLOSE
823 { $$ = $subsigguts; }
828 SAVEIV(parser->sig_elems);
829 SAVEIV(parser->sig_optelems);
830 SAVEI8(parser->sig_slurpy);
831 parser->sig_elems = 0;
832 parser->sig_optelems = 0;
833 parser->sig_slurpy = 0;
834 parser->in_my = KEY_sigvar;
838 OP *sigops = $siglistornull;
839 struct op_argcheck_aux *aux;
842 if (!FEATURE_SIGNATURES_IS_ENABLED)
843 Perl_croak(aTHX_ "Experimental "
844 "subroutine signatures not enabled");
846 /* We shouldn't get here otherwise */
847 Perl_ck_warner_d(aTHX_
848 packWARN(WARN_EXPERIMENTAL__SIGNATURES),
849 "The signatures feature is experimental");
851 aux = (struct op_argcheck_aux*)
852 PerlMemShared_malloc(
853 sizeof(struct op_argcheck_aux));
854 aux->params = parser->sig_elems;
855 aux->opt_params = parser->sig_optelems;
856 aux->slurpy = parser->sig_slurpy;
857 check = newUNOP_AUX(OP_ARGCHECK, 0, NULL,
858 (UNOP_AUX_item *)aux);
859 sigops = op_prepend_elem(OP_LINESEQ, check, sigops);
860 sigops = op_prepend_elem(OP_LINESEQ,
861 newSTATEOP(0, NULL, NULL),
863 /* a nextstate at the end handles context
864 * correctly for an empty sub body */
865 sigops = op_append_elem(OP_LINESEQ,
867 newSTATEOP(0, NULL, NULL));
868 /* wrap the list of arg ops in a NULL aux op.
869 This serves two purposes. First, it makes
870 the arg list a separate subtree from the
871 body of the sub, and secondly the null op
872 may in future be upgraded to an OP_SIGNATURE
873 when implemented. For now leave it as
875 $$ = newUNOP_AUX(OP_ARGCHECK, 0, sigops, NULL);
879 /* tell the toker that attrributes can follow
880 * this sig, but only so that the toker
881 * can skip through any (illegal) trailing
882 * attribute text then give a useful error
883 * message about "attributes before sig",
884 * rather than falling over ina mess at
885 * unrecognised syntax.
887 parser->expect = XATTRBLOCK;
888 parser->sig_seen = TRUE;
893 /* Optional subroutine body (for named subroutine declaration) */
894 optsubbody: subbody { $$ = $subbody; }
895 | PERLY_SEMICOLON { $$ = NULL; }
899 /* Subroutine body (without signature) */
900 subbody: remember PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE
902 if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
903 parser->copline = (line_t)$PERLY_BRACE_OPEN;
904 $$ = block_end($remember, $stmtseq);
909 /* optional [ Subroutine body with optional signature ] (for named
910 * subroutine declaration) */
911 optsigsubbody: sigsubbody { $$ = $sigsubbody; }
912 | PERLY_SEMICOLON { $$ = NULL; }
914 /* Subroutine body with optional signature */
915 sigsubbody: remember optsubsignature PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE
917 if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
918 parser->copline = (line_t)$PERLY_BRACE_OPEN;
919 $$ = block_end($remember,
920 op_append_list(OP_LINESEQ, $optsubsignature, $stmtseq));
925 /* Ordinary expressions; logical combinations */
926 expr : expr[lhs] ANDOP expr[rhs]
927 { $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); }
928 | expr[lhs] OROP[operator] expr[rhs]
929 { $$ = newLOGOP($operator, 0, $lhs, $rhs); }
930 | listexpr %prec PREC_LOW
933 /* Expressions are a list of terms joined by commas */
934 listexpr: listexpr[list] PERLY_COMMA
936 | listexpr[list] PERLY_COMMA term
939 $$ = op_append_elem(OP_LIST, $list, term);
941 | term %prec PREC_LOW
945 listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
946 { $$ = op_convert_list($LSTOP, OPf_STACKED,
947 op_prepend_elem(OP_LIST, newGVREF($LSTOP,$indirob), $listexpr) );
949 | FUNC PERLY_PAREN_OPEN indirob expr PERLY_PAREN_CLOSE /* print ($fh @args */
950 { $$ = op_convert_list($FUNC, OPf_STACKED,
951 op_prepend_elem(OP_LIST, newGVREF($FUNC,$indirob), $expr) );
953 | term ARROW method PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* $foo->bar(list) */
954 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
955 op_append_elem(OP_LIST,
956 op_prepend_elem(OP_LIST, scalar($term), $optexpr),
957 newMETHOP(OP_METHOD, 0, $method)));
959 | term ARROW method /* $foo->bar */
960 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
961 op_append_elem(OP_LIST, scalar($term),
962 newMETHOP(OP_METHOD, 0, $method)));
964 | METHOD indirob optlistexpr /* new Class @args */
965 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
966 op_append_elem(OP_LIST,
967 op_prepend_elem(OP_LIST, $indirob, $optlistexpr),
968 newMETHOP(OP_METHOD, 0, $METHOD)));
970 | FUNCMETH indirob PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* method $object (@args) */
971 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
972 op_append_elem(OP_LIST,
973 op_prepend_elem(OP_LIST, $indirob, $optexpr),
974 newMETHOP(OP_METHOD, 0, $FUNCMETH)));
976 | LSTOP optlistexpr /* print @args */
977 { $$ = op_convert_list($LSTOP, 0, $optlistexpr); }
978 | FUNC PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* print (@args) */
979 { $$ = op_convert_list($FUNC, 0, $optexpr); }
980 | FUNC SUBLEXSTART optexpr SUBLEXEND /* uc($arg) from "\U..." */
981 { $$ = op_convert_list($FUNC, 0, $optexpr); }
982 | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */
983 { SvREFCNT_inc_simple_void(PL_compcv);
984 $<opval>$ = newANONATTRSUB($startanonsub, 0, NULL, $block); }[anonattrsub]
985 optlistexpr %prec LSTOP /* ... @bar */
986 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
987 op_append_elem(OP_LIST,
988 op_prepend_elem(OP_LIST, $<opval>anonattrsub, $optlistexpr), $LSTOPSUB));
992 /* Names of methods. May use $object->$methodname */
997 /* Some kind of subscripted expression */
998 subscripted: gelem PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* *main::{something} */
999 /* In this and all the hash accessors, PERLY_SEMICOLON is
1000 * provided by the tokeniser */
1001 { $$ = newBINOP(OP_GELEM, 0, $gelem, scalar($expr)); }
1002 | scalar[array] PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* $array[$element] */
1003 { $$ = newBINOP(OP_AELEM, 0, oopsAV($array), scalar($expr));
1005 | term[array_reference] ARROW PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* somearef->[$element] */
1006 { $$ = newBINOP(OP_AELEM, 0,
1007 ref(newAVREF($array_reference),OP_RV2AV),
1010 | subscripted[array_reference] PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* $foo->[$bar]->[$baz] */
1011 { $$ = newBINOP(OP_AELEM, 0,
1012 ref(newAVREF($array_reference),OP_RV2AV),
1015 | scalar[hash] PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* $foo{bar();} */
1016 { $$ = newBINOP(OP_HELEM, 0, oopsHV($hash), jmaybe($expr));
1018 | term[hash_reference] ARROW PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* somehref->{bar();} */
1019 { $$ = newBINOP(OP_HELEM, 0,
1020 ref(newHVREF($hash_reference),OP_RV2HV),
1022 | subscripted[hash_reference] PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* $foo->[bar]->{baz;} */
1023 { $$ = newBINOP(OP_HELEM, 0,
1024 ref(newHVREF($hash_reference),OP_RV2HV),
1026 | term[code_reference] ARROW PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* $subref->() */
1027 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1028 newCVREF(0, scalar($code_reference)));
1029 if (parser->expect == XBLOCK)
1030 parser->expect = XOPERATOR;
1032 | term[code_reference] ARROW PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* $subref->(@args) */
1033 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1034 op_append_elem(OP_LIST, $expr,
1035 newCVREF(0, scalar($code_reference))));
1036 if (parser->expect == XBLOCK)
1037 parser->expect = XOPERATOR;
1040 | subscripted[code_reference] PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* $foo->{bar}->(@args) */
1041 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1042 op_append_elem(OP_LIST, $expr,
1043 newCVREF(0, scalar($code_reference))));
1044 if (parser->expect == XBLOCK)
1045 parser->expect = XOPERATOR;
1047 | subscripted[code_reference] PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* $foo->{bar}->() */
1048 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1049 newCVREF(0, scalar($code_reference)));
1050 if (parser->expect == XBLOCK)
1051 parser->expect = XOPERATOR;
1053 | PERLY_PAREN_OPEN expr[list] PERLY_PAREN_CLOSE PERLY_BRACKET_OPEN expr[slice] PERLY_BRACKET_CLOSE /* list slice */
1054 { $$ = newSLICEOP(0, $slice, $list); }
1055 | QWLIST PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* list literal slice */
1056 { $$ = newSLICEOP(0, $expr, $QWLIST); }
1057 | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* empty list slice! */
1058 { $$ = newSLICEOP(0, $expr, NULL); }
1061 /* Binary operators between terms */
1062 termbinop: term[lhs] ASSIGNOP term[rhs] /* $x = $y, $x += $y */
1063 { $$ = newASSIGNOP(OPf_STACKED, $lhs, $ASSIGNOP, $rhs); }
1064 | term[lhs] POWOP term[rhs] /* $x ** $y */
1065 { $$ = newBINOP($POWOP, 0, scalar($lhs), scalar($rhs)); }
1066 | term[lhs] MULOP term[rhs] /* $x * $y, $x x $y */
1067 { if ($MULOP != OP_REPEAT)
1069 $$ = newBINOP($MULOP, 0, $lhs, scalar($rhs));
1071 | term[lhs] ADDOP term[rhs] /* $x + $y */
1072 { $$ = newBINOP($ADDOP, 0, scalar($lhs), scalar($rhs)); }
1073 | term[lhs] SHIFTOP term[rhs] /* $x >> $y, $x << $y */
1074 { $$ = newBINOP($SHIFTOP, 0, scalar($lhs), scalar($rhs)); }
1075 | termrelop %prec PREC_LOW /* $x > $y, etc. */
1076 { $$ = $termrelop; }
1077 | termeqop %prec PREC_LOW /* $x == $y, $x cmp $y */
1079 | term[lhs] BITANDOP term[rhs] /* $x & $y */
1080 { $$ = newBINOP($BITANDOP, 0, scalar($lhs), scalar($rhs)); }
1081 | term[lhs] BITOROP term[rhs] /* $x | $y */
1082 { $$ = newBINOP($BITOROP, 0, scalar($lhs), scalar($rhs)); }
1083 | term[lhs] DOTDOT term[rhs] /* $x..$y, $x...$y */
1084 { $$ = newRANGE($DOTDOT, scalar($lhs), scalar($rhs)); }
1085 | term[lhs] ANDAND term[rhs] /* $x && $y */
1086 { $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); }
1087 | term[lhs] OROR term[rhs] /* $x || $y */
1088 { $$ = newLOGOP(OP_OR, 0, $lhs, $rhs); }
1089 | term[lhs] DORDOR term[rhs] /* $x // $y */
1090 { $$ = newLOGOP(OP_DOR, 0, $lhs, $rhs); }
1091 | term[lhs] MATCHOP term[rhs] /* $x =~ /$y/ */
1092 { $$ = bind_match($MATCHOP, $lhs, $rhs); }
1095 termrelop: relopchain %prec PREC_LOW
1096 { $$ = cmpchain_finish($relopchain); }
1097 | term[lhs] NCRELOP term[rhs]
1098 { $$ = newBINOP($NCRELOP, 0, scalar($lhs), scalar($rhs)); }
1100 { yyerror("syntax error"); YYERROR; }
1102 { yyerror("syntax error"); YYERROR; }
1105 relopchain: term[lhs] CHRELOP term[rhs]
1106 { $$ = cmpchain_start($CHRELOP, $lhs, $rhs); }
1107 | relopchain[lhs] CHRELOP term[rhs]
1108 { $$ = cmpchain_extend($CHRELOP, $lhs, $rhs); }
1111 termeqop: eqopchain %prec PREC_LOW
1112 { $$ = cmpchain_finish($eqopchain); }
1113 | term[lhs] NCEQOP term[rhs]
1114 { $$ = newBINOP($NCEQOP, 0, scalar($lhs), scalar($rhs)); }
1116 { yyerror("syntax error"); YYERROR; }
1118 { yyerror("syntax error"); YYERROR; }
1121 eqopchain: term[lhs] CHEQOP term[rhs]
1122 { $$ = cmpchain_start($CHEQOP, $lhs, $rhs); }
1123 | eqopchain[lhs] CHEQOP term[rhs]
1124 { $$ = cmpchain_extend($CHEQOP, $lhs, $rhs); }
1127 /* Unary operators and terms */
1128 termunop : PERLY_MINUS term %prec UMINUS /* -$x */
1129 { $$ = newUNOP(OP_NEGATE, 0, scalar($term)); }
1130 | PERLY_PLUS term %prec UMINUS /* +$x */
1133 | PERLY_EXCLAMATION_MARK term /* !$x */
1134 { $$ = newUNOP(OP_NOT, 0, scalar($term)); }
1135 | PERLY_TILDE term /* ~$x */
1136 { $$ = newUNOP($PERLY_TILDE, 0, scalar($term)); }
1137 | term POSTINC /* $x++ */
1138 { $$ = newUNOP(OP_POSTINC, 0,
1139 op_lvalue(scalar($term), OP_POSTINC)); }
1140 | term POSTDEC /* $x-- */
1141 { $$ = newUNOP(OP_POSTDEC, 0,
1142 op_lvalue(scalar($term), OP_POSTDEC));}
1143 | term POSTJOIN /* implicit join after interpolated ->@ */
1144 { $$ = op_convert_list(OP_JOIN, 0,
1154 | PREINC term /* ++$x */
1155 { $$ = newUNOP(OP_PREINC, 0,
1156 op_lvalue(scalar($term), OP_PREINC)); }
1157 | PREDEC term /* --$x */
1158 { $$ = newUNOP(OP_PREDEC, 0,
1159 op_lvalue(scalar($term), OP_PREDEC)); }
1163 /* Constructors for anonymous data */
1164 anonymous: PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE
1165 { $$ = newANONLIST($expr); }
1166 | PERLY_BRACKET_OPEN PERLY_BRACKET_CLOSE
1167 { $$ = newANONLIST(NULL);}
1168 | HASHBRACK expr PERLY_SEMICOLON PERLY_BRACE_CLOSE %prec PERLY_PAREN_OPEN /* { foo => "Bar" } */
1169 { $$ = newANONHASH($expr); }
1170 | HASHBRACK PERLY_SEMICOLON PERLY_BRACE_CLOSE %prec PERLY_PAREN_OPEN /* { } (PERLY_SEMICOLON by tokener) */
1171 { $$ = newANONHASH(NULL); }
1172 | ANONSUB startanonsub proto subattrlist subbody %prec PERLY_PAREN_OPEN
1173 { SvREFCNT_inc_simple_void(PL_compcv);
1174 $$ = newANONATTRSUB($startanonsub, $proto, $subattrlist, $subbody); }
1175 | ANON_SIGSUB startanonsub subattrlist sigsubbody %prec PERLY_PAREN_OPEN
1176 { SvREFCNT_inc_simple_void(PL_compcv);
1177 $$ = newANONATTRSUB($startanonsub, NULL, $subattrlist, $sigsubbody); }
1180 /* Things called with "do" */
1181 termdo : DO term %prec UNIOP /* do $filename */
1182 { $$ = dofile($term, $DO);}
1183 | DO block %prec PERLY_PAREN_OPEN /* do { code */
1184 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($block));}
1187 term[product] : termbinop
1191 | term[condition] PERLY_QUESTION_MARK term[then] PERLY_COLON term[else]
1192 { $$ = newCONDOP(0, $condition, $then, $else); }
1193 | REFGEN term[operand] /* \$x, \@y, \%z */
1194 { $$ = newUNOP(OP_REFGEN, 0, $operand); }
1195 | MY REFGEN term[operand]
1196 { $$ = newUNOP(OP_REFGEN, 0, localize($operand,1)); }
1197 | myattrterm %prec UNIOP
1198 { $$ = $myattrterm; }
1199 | LOCAL term[operand] %prec UNIOP
1200 { $$ = localize($operand,0); }
1201 | PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE
1202 { $$ = sawparens($expr); }
1205 | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1206 { $$ = sawparens(newNULLLIST()); }
1207 | scalar %prec PERLY_PAREN_OPEN
1209 | star %prec PERLY_PAREN_OPEN
1211 | hsh %prec PERLY_PAREN_OPEN
1213 | ary %prec PERLY_PAREN_OPEN
1215 | arylen %prec PERLY_PAREN_OPEN /* $#x, $#{ something } */
1216 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($arylen, OP_AV2ARYLEN));}
1218 { $$ = $subscripted; }
1219 | sliceme PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* array slice */
1220 { $$ = op_prepend_elem(OP_ASLICE,
1221 newOP(OP_PUSHMARK, 0),
1222 newLISTOP(OP_ASLICE, 0,
1224 ref($sliceme, OP_ASLICE)));
1227 $sliceme->op_private & OPpSLICEWARNING;
1229 | kvslice PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* array key/value slice */
1230 { $$ = op_prepend_elem(OP_KVASLICE,
1231 newOP(OP_PUSHMARK, 0),
1232 newLISTOP(OP_KVASLICE, 0,
1234 ref(oopsAV($kvslice), OP_KVASLICE)));
1237 $kvslice->op_private & OPpSLICEWARNING;
1239 | sliceme PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* @hash{@keys} */
1240 { $$ = op_prepend_elem(OP_HSLICE,
1241 newOP(OP_PUSHMARK, 0),
1242 newLISTOP(OP_HSLICE, 0,
1244 ref(oopsHV($sliceme), OP_HSLICE)));
1247 $sliceme->op_private & OPpSLICEWARNING;
1249 | kvslice PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* %hash{@keys} */
1250 { $$ = op_prepend_elem(OP_KVHSLICE,
1251 newOP(OP_PUSHMARK, 0),
1252 newLISTOP(OP_KVHSLICE, 0,
1254 ref($kvslice, OP_KVHSLICE)));
1257 $kvslice->op_private & OPpSLICEWARNING;
1259 | THING %prec PERLY_PAREN_OPEN
1262 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($amper)); }
1263 | amper PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* &foo() or foo() */
1264 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($amper));
1266 | amper PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* &foo(@args) or foo(@args) */
1268 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1269 op_append_elem(OP_LIST, $expr, scalar($amper)));
1271 | NOAMP subname optlistexpr /* foo @args (no parens) */
1272 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1273 op_append_elem(OP_LIST, $optlistexpr, scalar($subname)));
1275 | term[operand] ARROW PERLY_DOLLAR PERLY_STAR
1276 { $$ = newSVREF($operand); }
1277 | term[operand] ARROW PERLY_SNAIL PERLY_STAR
1278 { $$ = newAVREF($operand); }
1279 | term[operand] ARROW PERLY_PERCENT_SIGN PERLY_STAR
1280 { $$ = newHVREF($operand); }
1281 | term[operand] ARROW PERLY_AMPERSAND PERLY_STAR
1282 { $$ = newUNOP(OP_ENTERSUB, 0,
1283 scalar(newCVREF($PERLY_AMPERSAND,$operand))); }
1284 | term[operand] ARROW PERLY_STAR PERLY_STAR %prec PERLY_PAREN_OPEN
1285 { $$ = newGVREF(0,$operand); }
1286 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
1287 { $$ = newOP($LOOPEX, OPf_SPECIAL);
1288 PL_hints |= HINT_BLOCK_SCOPE; }
1289 | LOOPEX term[operand]
1290 { $$ = newLOOPEX($LOOPEX,$operand); }
1291 | NOTOP listexpr /* not $foo */
1292 { $$ = newUNOP(OP_NOT, 0, scalar($listexpr)); }
1293 | UNIOP /* Unary op, $_ implied */
1294 { $$ = newOP($UNIOP, 0); }
1295 | UNIOP block /* eval { foo }* */
1296 { $$ = newUNOP($UNIOP, 0, $block); }
1297 | UNIOP term[operand] /* Unary op */
1298 { $$ = newUNOP($UNIOP, 0, $operand); }
1299 | REQUIRE /* require, $_ implied */
1300 { $$ = newOP(OP_REQUIRE, $REQUIRE ? OPf_SPECIAL : 0); }
1301 | REQUIRE term[operand] /* require Foo */
1302 { $$ = newUNOP(OP_REQUIRE, $REQUIRE ? OPf_SPECIAL : 0, $operand); }
1304 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($UNIOPSUB)); }
1305 | UNIOPSUB term[operand] /* Sub treated as unop */
1306 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1307 op_append_elem(OP_LIST, $operand, scalar($UNIOPSUB))); }
1308 | FUNC0 /* Nullary operator */
1309 { $$ = newOP($FUNC0, 0); }
1310 | FUNC0 PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1311 { $$ = newOP($FUNC0, 0);}
1312 | FUNC0OP /* Same as above, but op created in toke.c */
1314 | FUNC0OP PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1316 | FUNC0SUB /* Sub treated as nullop */
1317 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($FUNC0SUB)); }
1318 | FUNC1 PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* not () */
1319 { $$ = ($FUNC1 == OP_NOT)
1320 ? newUNOP($FUNC1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
1321 : newOP($FUNC1, OPf_SPECIAL); }
1322 | FUNC1 PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* not($foo) */
1323 { $$ = newUNOP($FUNC1, 0, $expr); }
1324 | PMFUNC /* m//, s///, qr//, tr/// */
1326 if ( $PMFUNC->op_type != OP_TRANS
1327 && $PMFUNC->op_type != OP_TRANSR
1328 && (((PMOP*)$PMFUNC)->op_pmflags & PMf_HAS_CV))
1330 $<ival>$ = start_subparse(FALSE, CVf_ANON);
1331 SAVEFREESV(PL_compcv);
1335 SUBLEXSTART listexpr optrepl SUBLEXEND
1336 { $$ = pmruntime($PMFUNC, $listexpr, $optrepl, 1, $<ival>2); }
1342 /* "my" declarations, with optional attributes */
1343 myattrterm: MY myterm myattrlist
1344 { $$ = my_attrs($myterm,$myattrlist); }
1346 { $$ = localize($myterm,1); }
1347 | MY REFGEN myterm myattrlist
1348 { $$ = newUNOP(OP_REFGEN, 0, my_attrs($myterm,$myattrlist)); }
1351 /* Things that can be "my"'d */
1352 myterm : PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE
1353 { $$ = sawparens($expr); }
1354 | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1355 { $$ = sawparens(newNULLLIST()); }
1357 | scalar %prec PERLY_PAREN_OPEN
1359 | hsh %prec PERLY_PAREN_OPEN
1361 | ary %prec PERLY_PAREN_OPEN
1365 /* Basic list expressions */
1366 optlistexpr: %empty %prec PREC_LOW
1368 | listexpr %prec PREC_LOW
1384 /* A little bit of trickery to make "for my $foo (@bar)" actually be
1387 { parser->in_my = 0; $$ = my($scalar); }
1395 refgen_topic: my_var
1399 my_refgen: MY REFGEN
1403 amper : PERLY_AMPERSAND indirob
1404 { $$ = newCVREF($PERLY_AMPERSAND,$indirob); }
1407 scalar : PERLY_DOLLAR indirob
1408 { $$ = newSVREF($indirob); }
1411 ary : PERLY_SNAIL indirob
1412 { $$ = newAVREF($indirob);
1413 if ($$) $$->op_private |= $PERLY_SNAIL;
1417 hsh : PERLY_PERCENT_SIGN indirob
1418 { $$ = newHVREF($indirob);
1419 if ($$) $$->op_private |= $PERLY_PERCENT_SIGN;
1423 arylen : DOLSHARP indirob
1424 { $$ = newAVREF($indirob); }
1425 | term ARROW DOLSHARP PERLY_STAR
1426 { $$ = newAVREF($term); }
1429 star : PERLY_STAR indirob
1430 { $$ = newGVREF(0,$indirob); }
1434 | term ARROW PERLY_SNAIL
1435 { $$ = newAVREF($term); }
1439 | term ARROW PERLY_PERCENT_SIGN
1440 { $$ = newHVREF($term); }
1444 | term ARROW PERLY_STAR
1445 { $$ = newGVREF(0,$term); }
1448 /* Indirect objects */
1450 { $$ = scalar($BAREWORD); }
1451 | scalar %prec PREC_LOW
1452 { $$ = scalar($scalar); }
1454 { $$ = op_scope($block); }
1457 { $$ = $PRIVATEREF; }