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
82 %type <ival> grammar remember mremember
83 %type <ival> startsub startanonsub startformsub
87 %type <opval> stmtseq fullstmt labfullstmt barestmt block mblock else
88 %type <opval> expr term subscripted scalar ary hsh arylen star amper sideff
89 %type <opval> condition
90 %type <opval> sliceme kvslice gelem
91 %type <opval> listexpr nexpr texpr iexpr mexpr mnexpr
92 %type <opval> optlistexpr optexpr optrepl indirob listop method
93 %type <opval> formname subname proto cont my_scalar my_var
94 %type <opval> refgen_topic formblock
95 %type <opval> subattrlist myattrlist myattrterm myterm
96 %type <opval> termbinop termunop anonymous termdo
97 %type <opval> termrelop relopchain termeqop eqopchain
98 %type <ival> sigslurpsigil
99 %type <opval> sigvarname sigdefault sigscalarelem sigslurpelem
100 %type <opval> sigelem siglist siglistornull subsigguts subsignature optsubsignature
101 %type <opval> subbody optsubbody sigsubbody optsigsubbody
102 %type <opval> formstmtseq formline formarg
104 %nonassoc <ival> PREC_LOW
110 %nonassoc LSTOP LSTOPSUB
112 %right <ival> ASSIGNOP
113 %right <ival> PERLY_QUESTION_MARK PERLY_COLON
115 %left <ival> OROR DORDOR
118 %left <ival> BITANDOP
119 %left <ival> CHEQOP NCEQOP
120 %left <ival> CHRELOP NCRELOP
121 %nonassoc UNIOP UNIOPSUB
127 %right <ival> PERLY_EXCLAMATION_MARK PERLY_TILDE UMINUS REFGEN
129 %nonassoc <ival> PREINC PREDEC POSTINC POSTDEC POSTJOIN
131 %nonassoc <ival> PERLY_PAREN_CLOSE
132 %left <ival> PERLY_PAREN_OPEN
133 %left PERLY_BRACKET_OPEN PERLY_BRACE_OPEN
137 /* Top-level choice of what kind of thing yyparse was called to parse */
140 parser->expect = XSTATE;
145 newPROG(block_end($remember,$stmtseq));
146 PL_compiling.cop_seq = 0;
151 parser->expect = XTERM;
156 PL_eval_root = $optexpr;
161 parser->expect = XBLOCK;
166 PL_pad_reset_pending = TRUE;
167 PL_eval_root = $block;
170 parser->yychar = yytoken = YYEOF;
174 parser->expect = XSTATE;
179 PL_pad_reset_pending = TRUE;
180 PL_eval_root = $barestmt;
183 parser->yychar = yytoken = YYEOF;
187 parser->expect = XSTATE;
192 PL_pad_reset_pending = TRUE;
193 PL_eval_root = $fullstmt;
196 parser->yychar = yytoken = YYEOF;
200 parser->expect = XSTATE;
205 PL_eval_root = $stmtseq;
210 parser->expect = XSTATE;
215 PL_eval_root = $subsigguts;
220 /* An ordinary block */
221 block : PERLY_BRACE_OPEN remember stmtseq PERLY_BRACE_CLOSE
222 { if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
223 parser->copline = (line_t)$PERLY_BRACE_OPEN;
224 $$ = block_end($remember, $stmtseq);
229 formblock: PERLY_EQUAL_SIGN remember PERLY_SEMICOLON FORMRBRACK formstmtseq PERLY_SEMICOLON PERLY_DOT
230 { if (parser->copline > (line_t)$PERLY_EQUAL_SIGN)
231 parser->copline = (line_t)$PERLY_EQUAL_SIGN;
232 $$ = block_end($remember, $formstmtseq);
236 remember: %empty /* start a full lexical scope */
237 { $$ = block_start(TRUE);
238 parser->parsed_sub = 0; }
241 mblock : PERLY_BRACE_OPEN mremember stmtseq PERLY_BRACE_CLOSE
242 { if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
243 parser->copline = (line_t)$PERLY_BRACE_OPEN;
244 $$ = block_end($mremember, $stmtseq);
248 mremember: %empty /* start a partial lexical scope */
249 { $$ = block_start(FALSE);
250 parser->parsed_sub = 0; }
253 /* A sequence of statements in the program */
256 | stmtseq[list] fullstmt
257 { $$ = op_append_list(OP_LINESEQ, $list, $fullstmt);
258 PL_pad_reset_pending = TRUE;
259 if ($list && $fullstmt)
260 PL_hints |= HINT_BLOCK_SCOPE;
264 /* A sequence of format lines */
267 | formstmtseq[list] formline
268 { $$ = op_append_list(OP_LINESEQ, $list, $formline);
269 PL_pad_reset_pending = TRUE;
270 if ($list && $formline)
271 PL_hints |= HINT_BLOCK_SCOPE;
275 /* A statement in the program, including optional labels */
278 $$ = $barestmt ? newSTATEOP(0, NULL, $barestmt) : NULL;
281 { $$ = $labfullstmt; }
284 labfullstmt: LABEL barestmt
286 SV *label = cSVOPx_sv($LABEL);
287 $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8,
288 savepv(SvPVX_const(label)), $barestmt);
291 | LABEL labfullstmt[list]
293 SV *label = cSVOPx_sv($LABEL);
294 $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8,
295 savepv(SvPVX_const(label)), $list);
300 /* A bare statement, lacking label and other aspects of state op */
303 | FORMAT startformsub formname formblock
305 CV *fmtcv = PL_compcv;
306 newFORM($startformsub, $formname, $formblock);
308 if (CvOUTSIDE(fmtcv) && !CvEVAL(CvOUTSIDE(fmtcv))) {
309 pad_add_weakref(fmtcv);
311 parser->parsed_sub = 1;
313 | SUB subname startsub
314 /* sub declaration or definition not within scope
315 of 'use feature "signatures"'*/
317 init_named_cv(PL_compcv, $subname);
319 parser->in_my_stash = NULL;
321 proto subattrlist optsubbody
323 SvREFCNT_inc_simple_void(PL_compcv);
324 $subname->op_type == OP_CONST
325 ? newATTRSUB($startsub, $subname, $proto, $subattrlist, $optsubbody)
326 : newMYSUB($startsub, $subname, $proto, $subattrlist, $optsubbody)
330 parser->parsed_sub = 1;
332 | SIGSUB subname startsub
333 /* sub declaration or definition under 'use feature
334 * "signatures"'. (Note that a signature isn't
335 * allowed in a declaration)
338 init_named_cv(PL_compcv, $subname);
340 parser->in_my_stash = NULL;
342 subattrlist optsigsubbody
344 SvREFCNT_inc_simple_void(PL_compcv);
345 $subname->op_type == OP_CONST
346 ? newATTRSUB($startsub, $subname, NULL, $subattrlist, $optsigsubbody)
347 : newMYSUB( $startsub, $subname, NULL, $subattrlist, $optsigsubbody)
351 parser->parsed_sub = 1;
353 | PACKAGE BAREWORD[version] BAREWORD[package] PERLY_SEMICOLON
357 package_version($version);
361 { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
362 BAREWORD[version] BAREWORD[module] optlistexpr PERLY_SEMICOLON
364 SvREFCNT_inc_simple_void(PL_compcv);
365 utilize($USE, $startsub, $version, $module, $optlistexpr);
366 parser->parsed_sub = 1;
369 | IF PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock else
371 $$ = block_end($remember,
372 newCONDOP(0, $mexpr, op_scope($mblock), $else));
373 parser->copline = (line_t)$IF;
375 | UNLESS PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock else
377 $$ = block_end($remember,
378 newCONDOP(0, $mexpr, $else, op_scope($mblock)));
379 parser->copline = (line_t)$UNLESS;
381 | GIVEN PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock
383 $$ = block_end($remember, newGIVENOP($mexpr, op_scope($mblock), 0));
384 parser->copline = (line_t)$GIVEN;
386 | WHEN PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock
387 { $$ = block_end($remember, newWHENOP($mexpr, op_scope($mblock))); }
389 { $$ = newWHENOP(0, op_scope($block)); }
390 | WHILE PERLY_PAREN_OPEN remember texpr PERLY_PAREN_CLOSE mintro mblock cont
392 $$ = block_end($remember,
393 newWHILEOP(0, 1, NULL,
394 $texpr, $mblock, $cont, $mintro));
395 parser->copline = (line_t)$WHILE;
397 | UNTIL PERLY_PAREN_OPEN remember iexpr PERLY_PAREN_CLOSE mintro mblock cont
399 $$ = block_end($remember,
400 newWHILEOP(0, 1, NULL,
401 $iexpr, $mblock, $cont, $mintro));
402 parser->copline = (line_t)$UNTIL;
404 | FOR PERLY_PAREN_OPEN remember mnexpr[init_mnexpr] PERLY_SEMICOLON
405 { parser->expect = XTERM; }
406 texpr PERLY_SEMICOLON
407 { parser->expect = XTERM; }
408 mintro mnexpr[iterate_mnexpr] PERLY_PAREN_CLOSE
411 OP *initop = $init_mnexpr;
412 OP *forop = newWHILEOP(0, 1, NULL,
413 scalar($texpr), $mblock, $iterate_mnexpr, $mintro);
415 forop = op_prepend_elem(OP_LINESEQ, initop,
416 op_append_elem(OP_LINESEQ,
417 newOP(OP_UNSTACK, OPf_SPECIAL),
420 PL_hints |= HINT_BLOCK_SCOPE;
421 $$ = block_end($remember, forop);
422 parser->copline = (line_t)$FOR;
424 | FOR MY remember my_scalar PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont
426 $$ = block_end($remember, newFOROP(0, $my_scalar, $mexpr, $mblock, $cont));
427 parser->copline = (line_t)$FOR;
429 | FOR scalar PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
431 $$ = block_end($remember, newFOROP(0,
432 op_lvalue($scalar, OP_ENTERLOOP), $mexpr, $mblock, $cont));
433 parser->copline = (line_t)$FOR;
435 | FOR my_refgen remember my_var
436 { parser->in_my = 0; $<opval>$ = my($my_var); }[variable]
437 PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont
443 newUNOP(OP_REFGEN, 0,
446 $mexpr, $mblock, $cont)
448 parser->copline = (line_t)$FOR;
450 | FOR REFGEN refgen_topic PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
452 $$ = block_end($remember, newFOROP(
453 0, op_lvalue(newUNOP(OP_REFGEN, 0,
455 OP_ENTERLOOP), $mexpr, $mblock, $cont));
456 parser->copline = (line_t)$FOR;
458 | FOR PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
460 $$ = block_end($remember,
461 newFOROP(0, NULL, $mexpr, $mblock, $cont));
462 parser->copline = (line_t)$FOR;
464 | TRY mblock[try] CATCH PERLY_PAREN_OPEN
465 { parser->in_my = 1; }
467 { parser->in_my = 0; intro_my(); }
468 PERLY_PAREN_CLOSE mblock[catch]
470 $$ = newTRYCATCHOP(0,
471 $try, $scalar, block_end($remember, op_scope($catch)));
475 /* a block is a loop that happens once */
476 $$ = newWHILEOP(0, 1, NULL,
477 NULL, $block, $cont, 0);
479 | PACKAGE BAREWORD[version] BAREWORD[package] PERLY_BRACE_OPEN remember
483 package_version($version);
486 stmtseq PERLY_BRACE_CLOSE
488 /* a block is a loop that happens once */
489 $$ = newWHILEOP(0, 1, NULL,
490 NULL, block_end($remember, $stmtseq), NULL, 0);
491 if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
492 parser->copline = (line_t)$PERLY_BRACE_OPEN;
494 | sideff PERLY_SEMICOLON
500 $$ = newDEFEROP(0, op_scope($2));
502 | YADAYADA PERLY_SEMICOLON
504 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
505 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
510 parser->copline = NOLINE;
515 formline: THING formarg
519 list = op_append_elem(OP_LIST, $THING, term);
524 if (parser->copline == NOLINE)
525 parser->copline = CopLINE(PL_curcop)-1;
526 else parser->copline--;
527 $$ = newSTATEOP(0, NULL,
528 op_convert_list(OP_FORMLINE, 0, list));
534 | FORMLBRACK stmtseq FORMRBRACK
535 { $$ = op_unscope($stmtseq); }
541 /* An expression which may have a side-effect */
546 | expr[body] IF condition
547 { $$ = newLOGOP(OP_AND, 0, $condition, $body); }
548 | expr[body] UNLESS condition
549 { $$ = newLOGOP(OP_OR, 0, $condition, $body); }
550 | expr[body] WHILE condition
551 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($condition), $body); }
552 | expr[body] UNTIL iexpr
553 { $$ = newLOOPOP(OPf_PARENS, 1, $iexpr, $body); }
554 | expr[body] FOR condition
555 { $$ = newFOROP(0, NULL, $condition, $body, NULL);
556 parser->copline = (line_t)$FOR; }
557 | expr[body] WHEN condition
558 { $$ = newWHENOP($condition, op_scope($body)); }
561 /* else and elsif blocks */
566 ($mblock)->op_flags |= OPf_PARENS;
567 $$ = op_scope($mblock);
569 | ELSIF PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock else[else.recurse]
570 { parser->copline = (line_t)$ELSIF;
572 newSTATEOP(OPf_SPECIAL,NULL,$mexpr),
573 op_scope($mblock), $[else.recurse]);
574 PL_hints |= HINT_BLOCK_SCOPE;
578 /* Continue blocks */
582 { $$ = op_scope($block); }
585 /* determine whether there are any new my declarations */
587 { $$ = (PL_min_intro_pending &&
588 PL_max_intro_pending >= PL_min_intro_pending);
591 /* Normal expression */
597 /* Boolean expression */
598 texpr : %empty /* NULL means true */
600 (void)scan_num("1", &tmplval);
601 $$ = tmplval.opval; }
605 /* Inverted boolean expression */
607 { $$ = invert(scalar($expr)); }
610 /* Expression with its own lexical scope */
612 { $$ = $expr; intro_my(); }
616 { $$ = $nexpr; intro_my(); }
619 formname: BAREWORD { $$ = $BAREWORD; }
620 | %empty { $$ = NULL; }
623 startsub: %empty /* start a regular subroutine scope */
624 { $$ = start_subparse(FALSE, 0);
625 SAVEFREESV(PL_compcv); }
629 startanonsub: %empty /* start an anonymous subroutine scope */
630 { $$ = start_subparse(FALSE, CVf_ANON);
631 SAVEFREESV(PL_compcv); }
634 startformsub: %empty /* start a format subroutine scope */
635 { $$ = start_subparse(TRUE, 0);
636 SAVEFREESV(PL_compcv); }
639 /* Name of a subroutine - must be a bareword, could be special */
644 /* Subroutine prototype */
650 /* Optional list of subroutine attributes */
659 /* List of attributes for a "my" variable declaration */
660 myattrlist: COLONATTR THING
668 /* --------------------------------------
669 * subroutine signature parsing
672 /* the '' or 'foo' part of a '$' or '@foo' etc signature variable */
674 { parser->in_my = 0; $$ = NULL; }
676 { parser->in_my = 0; $$ = $PRIVATEREF; }
685 /* @, %, @foo, %foo */
686 sigslurpelem: sigslurpsigil sigvarname sigdefault/* def only to catch errors */
688 I32 sigil = $sigslurpsigil;
689 OP *var = $sigvarname;
690 OP *defexpr = $sigdefault;
692 if (parser->sig_slurpy)
693 yyerror("Multiple slurpy parameters not allowed");
694 parser->sig_slurpy = (char)sigil;
697 yyerror("A slurpy parameter may not have "
700 $$ = var ? newSTATEOP(0, NULL, var) : NULL;
704 /* default part of sub signature scalar element: i.e. '= default_expr' */
708 { $$ = newOP(OP_NULL, 0); }
713 /* subroutine signature scalar element: e.g. '$x', '$=', '$x = $default' */
715 PERLY_DOLLAR sigvarname sigdefault
717 OP *var = $sigvarname;
718 OP *defexpr = $sigdefault;
720 if (parser->sig_slurpy)
721 yyerror("Slurpy parameter not last");
726 parser->sig_optelems++;
728 if ( defexpr->op_type == OP_NULL
729 && !(defexpr->op_flags & OPf_KIDS))
731 /* handle '$=' special case */
733 yyerror("Optional parameter "
734 "lacks default expression");
738 /* a normal '=default' expression */
739 OP *defop = (OP*)alloc_LOGOP(OP_ARGDEFELEM,
742 /* re-purpose op_targ to hold @_ index */
744 (PADOFFSET)(parser->sig_elems - 1);
747 var->op_flags |= OPf_STACKED;
748 (void)op_sibling_splice(var,
753 var = newUNOP(OP_NULL, 0, defop);
756 /* NB: normally the first child of a
757 * logop is executed before the logop,
758 * and it pushes a boolean result
759 * ready for the logop. For ARGDEFELEM,
760 * the op itself does the boolean
761 * calculation, so set the first op to
764 var->op_next = defop;
765 defexpr->op_next = var;
769 if (parser->sig_optelems)
770 yyerror("Mandatory parameter "
771 "follows optional parameter");
774 $$ = var ? newSTATEOP(0, NULL, var) : NULL;
779 /* subroutine signature element: e.g. '$x = $default' or '%h' */
780 sigelem: sigscalarelem
781 { parser->in_my = KEY_sigvar; $$ = $sigscalarelem; }
783 { parser->in_my = KEY_sigvar; $$ = $sigslurpelem; }
786 /* list of subroutine signature elements */
788 siglist[list] PERLY_COMMA
790 | siglist[list] PERLY_COMMA sigelem[element]
792 $$ = op_append_list(OP_LINESEQ, $list, $element);
794 | sigelem[element] %prec PREC_LOW
799 siglistornull: %empty
804 /* optional subroutine signature */
805 optsubsignature: %empty
808 { $$ = $subsignature; }
810 /* Subroutine signature */
811 subsignature: PERLY_PAREN_OPEN subsigguts PERLY_PAREN_CLOSE
812 { $$ = $subsigguts; }
817 SAVEIV(parser->sig_elems);
818 SAVEIV(parser->sig_optelems);
819 SAVEI8(parser->sig_slurpy);
820 parser->sig_elems = 0;
821 parser->sig_optelems = 0;
822 parser->sig_slurpy = 0;
823 parser->in_my = KEY_sigvar;
827 OP *sigops = $siglistornull;
828 struct op_argcheck_aux *aux;
831 if (!FEATURE_SIGNATURES_IS_ENABLED)
832 Perl_croak(aTHX_ "Experimental "
833 "subroutine signatures not enabled");
835 /* We shouldn't get here otherwise */
836 Perl_ck_warner_d(aTHX_
837 packWARN(WARN_EXPERIMENTAL__SIGNATURES),
838 "The signatures feature is experimental");
840 aux = (struct op_argcheck_aux*)
841 PerlMemShared_malloc(
842 sizeof(struct op_argcheck_aux));
843 aux->params = parser->sig_elems;
844 aux->opt_params = parser->sig_optelems;
845 aux->slurpy = parser->sig_slurpy;
846 check = newUNOP_AUX(OP_ARGCHECK, 0, NULL,
847 (UNOP_AUX_item *)aux);
848 sigops = op_prepend_elem(OP_LINESEQ, check, sigops);
849 sigops = op_prepend_elem(OP_LINESEQ,
850 newSTATEOP(0, NULL, NULL),
852 /* a nextstate at the end handles context
853 * correctly for an empty sub body */
854 sigops = op_append_elem(OP_LINESEQ,
856 newSTATEOP(0, NULL, NULL));
857 /* wrap the list of arg ops in a NULL aux op.
858 This serves two purposes. First, it makes
859 the arg list a separate subtree from the
860 body of the sub, and secondly the null op
861 may in future be upgraded to an OP_SIGNATURE
862 when implemented. For now leave it as
864 $$ = newUNOP_AUX(OP_ARGCHECK, 0, sigops, NULL);
868 /* tell the toker that attrributes can follow
869 * this sig, but only so that the toker
870 * can skip through any (illegal) trailing
871 * attribute text then give a useful error
872 * message about "attributes before sig",
873 * rather than falling over ina mess at
874 * unrecognised syntax.
876 parser->expect = XATTRBLOCK;
877 parser->sig_seen = TRUE;
882 /* Optional subroutine body (for named subroutine declaration) */
883 optsubbody: subbody { $$ = $subbody; }
884 | PERLY_SEMICOLON { $$ = NULL; }
888 /* Subroutine body (without signature) */
889 subbody: remember PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE
891 if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
892 parser->copline = (line_t)$PERLY_BRACE_OPEN;
893 $$ = block_end($remember, $stmtseq);
898 /* optional [ Subroutine body with optional signature ] (for named
899 * subroutine declaration) */
900 optsigsubbody: sigsubbody { $$ = $sigsubbody; }
901 | PERLY_SEMICOLON { $$ = NULL; }
903 /* Subroutine body with optional signature */
904 sigsubbody: remember optsubsignature PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE
906 if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
907 parser->copline = (line_t)$PERLY_BRACE_OPEN;
908 $$ = block_end($remember,
909 op_append_list(OP_LINESEQ, $optsubsignature, $stmtseq));
914 /* Ordinary expressions; logical combinations */
915 expr : expr[lhs] ANDOP expr[rhs]
916 { $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); }
917 | expr[lhs] OROP[operator] expr[rhs]
918 { $$ = newLOGOP($operator, 0, $lhs, $rhs); }
919 | listexpr %prec PREC_LOW
922 /* Expressions are a list of terms joined by commas */
923 listexpr: listexpr[list] PERLY_COMMA
925 | listexpr[list] PERLY_COMMA term
928 $$ = op_append_elem(OP_LIST, $list, term);
930 | term %prec PREC_LOW
934 listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
935 { $$ = op_convert_list($LSTOP, OPf_STACKED,
936 op_prepend_elem(OP_LIST, newGVREF($LSTOP,$indirob), $listexpr) );
938 | FUNC PERLY_PAREN_OPEN indirob expr PERLY_PAREN_CLOSE /* print ($fh @args */
939 { $$ = op_convert_list($FUNC, OPf_STACKED,
940 op_prepend_elem(OP_LIST, newGVREF($FUNC,$indirob), $expr) );
942 | term ARROW method PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* $foo->bar(list) */
943 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
944 op_append_elem(OP_LIST,
945 op_prepend_elem(OP_LIST, scalar($term), $optexpr),
946 newMETHOP(OP_METHOD, 0, $method)));
948 | term ARROW method /* $foo->bar */
949 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
950 op_append_elem(OP_LIST, scalar($term),
951 newMETHOP(OP_METHOD, 0, $method)));
953 | METHOD indirob optlistexpr /* new Class @args */
954 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
955 op_append_elem(OP_LIST,
956 op_prepend_elem(OP_LIST, $indirob, $optlistexpr),
957 newMETHOP(OP_METHOD, 0, $METHOD)));
959 | FUNCMETH indirob PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* method $object (@args) */
960 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
961 op_append_elem(OP_LIST,
962 op_prepend_elem(OP_LIST, $indirob, $optexpr),
963 newMETHOP(OP_METHOD, 0, $FUNCMETH)));
965 | LSTOP optlistexpr /* print @args */
966 { $$ = op_convert_list($LSTOP, 0, $optlistexpr); }
967 | FUNC PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* print (@args) */
968 { $$ = op_convert_list($FUNC, 0, $optexpr); }
969 | FUNC SUBLEXSTART optexpr SUBLEXEND /* uc($arg) from "\U..." */
970 { $$ = op_convert_list($FUNC, 0, $optexpr); }
971 | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */
972 { SvREFCNT_inc_simple_void(PL_compcv);
973 $<opval>$ = newANONATTRSUB($startanonsub, 0, NULL, $block); }[anonattrsub]
974 optlistexpr %prec LSTOP /* ... @bar */
975 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
976 op_append_elem(OP_LIST,
977 op_prepend_elem(OP_LIST, $<opval>anonattrsub, $optlistexpr), $LSTOPSUB));
981 /* Names of methods. May use $object->$methodname */
986 /* Some kind of subscripted expression */
987 subscripted: gelem PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* *main::{something} */
988 /* In this and all the hash accessors, PERLY_SEMICOLON is
989 * provided by the tokeniser */
990 { $$ = newBINOP(OP_GELEM, 0, $gelem, scalar($expr)); }
991 | scalar[array] PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* $array[$element] */
992 { $$ = newBINOP(OP_AELEM, 0, oopsAV($array), scalar($expr));
994 | term[array_reference] ARROW PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* somearef->[$element] */
995 { $$ = newBINOP(OP_AELEM, 0,
996 ref(newAVREF($array_reference),OP_RV2AV),
999 | subscripted[array_reference] PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* $foo->[$bar]->[$baz] */
1000 { $$ = newBINOP(OP_AELEM, 0,
1001 ref(newAVREF($array_reference),OP_RV2AV),
1004 | scalar[hash] PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* $foo{bar();} */
1005 { $$ = newBINOP(OP_HELEM, 0, oopsHV($hash), jmaybe($expr));
1007 | term[hash_reference] ARROW PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* somehref->{bar();} */
1008 { $$ = newBINOP(OP_HELEM, 0,
1009 ref(newHVREF($hash_reference),OP_RV2HV),
1011 | subscripted[hash_reference] PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* $foo->[bar]->{baz;} */
1012 { $$ = newBINOP(OP_HELEM, 0,
1013 ref(newHVREF($hash_reference),OP_RV2HV),
1015 | term[code_reference] ARROW PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* $subref->() */
1016 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1017 newCVREF(0, scalar($code_reference)));
1018 if (parser->expect == XBLOCK)
1019 parser->expect = XOPERATOR;
1021 | term[code_reference] ARROW PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* $subref->(@args) */
1022 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1023 op_append_elem(OP_LIST, $expr,
1024 newCVREF(0, scalar($code_reference))));
1025 if (parser->expect == XBLOCK)
1026 parser->expect = XOPERATOR;
1029 | subscripted[code_reference] PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* $foo->{bar}->(@args) */
1030 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1031 op_append_elem(OP_LIST, $expr,
1032 newCVREF(0, scalar($code_reference))));
1033 if (parser->expect == XBLOCK)
1034 parser->expect = XOPERATOR;
1036 | subscripted[code_reference] PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* $foo->{bar}->() */
1037 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1038 newCVREF(0, scalar($code_reference)));
1039 if (parser->expect == XBLOCK)
1040 parser->expect = XOPERATOR;
1042 | PERLY_PAREN_OPEN expr[list] PERLY_PAREN_CLOSE PERLY_BRACKET_OPEN expr[slice] PERLY_BRACKET_CLOSE /* list slice */
1043 { $$ = newSLICEOP(0, $slice, $list); }
1044 | QWLIST PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* list literal slice */
1045 { $$ = newSLICEOP(0, $expr, $QWLIST); }
1046 | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* empty list slice! */
1047 { $$ = newSLICEOP(0, $expr, NULL); }
1050 /* Binary operators between terms */
1051 termbinop: term[lhs] ASSIGNOP term[rhs] /* $x = $y, $x += $y */
1052 { $$ = newASSIGNOP(OPf_STACKED, $lhs, $ASSIGNOP, $rhs); }
1053 | term[lhs] POWOP term[rhs] /* $x ** $y */
1054 { $$ = newBINOP($POWOP, 0, scalar($lhs), scalar($rhs)); }
1055 | term[lhs] MULOP term[rhs] /* $x * $y, $x x $y */
1056 { if ($MULOP != OP_REPEAT)
1058 $$ = newBINOP($MULOP, 0, $lhs, scalar($rhs));
1060 | term[lhs] ADDOP term[rhs] /* $x + $y */
1061 { $$ = newBINOP($ADDOP, 0, scalar($lhs), scalar($rhs)); }
1062 | term[lhs] SHIFTOP term[rhs] /* $x >> $y, $x << $y */
1063 { $$ = newBINOP($SHIFTOP, 0, scalar($lhs), scalar($rhs)); }
1064 | termrelop %prec PREC_LOW /* $x > $y, etc. */
1065 { $$ = $termrelop; }
1066 | termeqop %prec PREC_LOW /* $x == $y, $x cmp $y */
1068 | term[lhs] BITANDOP term[rhs] /* $x & $y */
1069 { $$ = newBINOP($BITANDOP, 0, scalar($lhs), scalar($rhs)); }
1070 | term[lhs] BITOROP term[rhs] /* $x | $y */
1071 { $$ = newBINOP($BITOROP, 0, scalar($lhs), scalar($rhs)); }
1072 | term[lhs] DOTDOT term[rhs] /* $x..$y, $x...$y */
1073 { $$ = newRANGE($DOTDOT, scalar($lhs), scalar($rhs)); }
1074 | term[lhs] ANDAND term[rhs] /* $x && $y */
1075 { $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); }
1076 | term[lhs] OROR term[rhs] /* $x || $y */
1077 { $$ = newLOGOP(OP_OR, 0, $lhs, $rhs); }
1078 | term[lhs] DORDOR term[rhs] /* $x // $y */
1079 { $$ = newLOGOP(OP_DOR, 0, $lhs, $rhs); }
1080 | term[lhs] MATCHOP term[rhs] /* $x =~ /$y/ */
1081 { $$ = bind_match($MATCHOP, $lhs, $rhs); }
1084 termrelop: relopchain %prec PREC_LOW
1085 { $$ = cmpchain_finish($relopchain); }
1086 | term[lhs] NCRELOP term[rhs]
1087 { $$ = newBINOP($NCRELOP, 0, scalar($lhs), scalar($rhs)); }
1089 { yyerror("syntax error"); YYERROR; }
1091 { yyerror("syntax error"); YYERROR; }
1094 relopchain: term[lhs] CHRELOP term[rhs]
1095 { $$ = cmpchain_start($CHRELOP, $lhs, $rhs); }
1096 | relopchain[lhs] CHRELOP term[rhs]
1097 { $$ = cmpchain_extend($CHRELOP, $lhs, $rhs); }
1100 termeqop: eqopchain %prec PREC_LOW
1101 { $$ = cmpchain_finish($eqopchain); }
1102 | term[lhs] NCEQOP term[rhs]
1103 { $$ = newBINOP($NCEQOP, 0, scalar($lhs), scalar($rhs)); }
1105 { yyerror("syntax error"); YYERROR; }
1107 { yyerror("syntax error"); YYERROR; }
1110 eqopchain: term[lhs] CHEQOP term[rhs]
1111 { $$ = cmpchain_start($CHEQOP, $lhs, $rhs); }
1112 | eqopchain[lhs] CHEQOP term[rhs]
1113 { $$ = cmpchain_extend($CHEQOP, $lhs, $rhs); }
1116 /* Unary operators and terms */
1117 termunop : PERLY_MINUS term %prec UMINUS /* -$x */
1118 { $$ = newUNOP(OP_NEGATE, 0, scalar($term)); }
1119 | PERLY_PLUS term %prec UMINUS /* +$x */
1122 | PERLY_EXCLAMATION_MARK term /* !$x */
1123 { $$ = newUNOP(OP_NOT, 0, scalar($term)); }
1124 | PERLY_TILDE term /* ~$x */
1125 { $$ = newUNOP($PERLY_TILDE, 0, scalar($term)); }
1126 | term POSTINC /* $x++ */
1127 { $$ = newUNOP(OP_POSTINC, 0,
1128 op_lvalue(scalar($term), OP_POSTINC)); }
1129 | term POSTDEC /* $x-- */
1130 { $$ = newUNOP(OP_POSTDEC, 0,
1131 op_lvalue(scalar($term), OP_POSTDEC));}
1132 | term POSTJOIN /* implicit join after interpolated ->@ */
1133 { $$ = op_convert_list(OP_JOIN, 0,
1143 | PREINC term /* ++$x */
1144 { $$ = newUNOP(OP_PREINC, 0,
1145 op_lvalue(scalar($term), OP_PREINC)); }
1146 | PREDEC term /* --$x */
1147 { $$ = newUNOP(OP_PREDEC, 0,
1148 op_lvalue(scalar($term), OP_PREDEC)); }
1152 /* Constructors for anonymous data */
1153 anonymous: PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE
1154 { $$ = newANONLIST($expr); }
1155 | PERLY_BRACKET_OPEN PERLY_BRACKET_CLOSE
1156 { $$ = newANONLIST(NULL);}
1157 | HASHBRACK expr PERLY_SEMICOLON PERLY_BRACE_CLOSE %prec PERLY_PAREN_OPEN /* { foo => "Bar" } */
1158 { $$ = newANONHASH($expr); }
1159 | HASHBRACK PERLY_SEMICOLON PERLY_BRACE_CLOSE %prec PERLY_PAREN_OPEN /* { } (PERLY_SEMICOLON by tokener) */
1160 { $$ = newANONHASH(NULL); }
1161 | ANONSUB startanonsub proto subattrlist subbody %prec PERLY_PAREN_OPEN
1162 { SvREFCNT_inc_simple_void(PL_compcv);
1163 $$ = newANONATTRSUB($startanonsub, $proto, $subattrlist, $subbody); }
1164 | ANON_SIGSUB startanonsub subattrlist sigsubbody %prec PERLY_PAREN_OPEN
1165 { SvREFCNT_inc_simple_void(PL_compcv);
1166 $$ = newANONATTRSUB($startanonsub, NULL, $subattrlist, $sigsubbody); }
1169 /* Things called with "do" */
1170 termdo : DO term %prec UNIOP /* do $filename */
1171 { $$ = dofile($term, $DO);}
1172 | DO block %prec PERLY_PAREN_OPEN /* do { code */
1173 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($block));}
1176 term[product] : termbinop
1180 | term[condition] PERLY_QUESTION_MARK term[then] PERLY_COLON term[else]
1181 { $$ = newCONDOP(0, $condition, $then, $else); }
1182 | REFGEN term[operand] /* \$x, \@y, \%z */
1183 { $$ = newUNOP(OP_REFGEN, 0, $operand); }
1184 | MY REFGEN term[operand]
1185 { $$ = newUNOP(OP_REFGEN, 0, localize($operand,1)); }
1186 | myattrterm %prec UNIOP
1187 { $$ = $myattrterm; }
1188 | LOCAL term[operand] %prec UNIOP
1189 { $$ = localize($operand,0); }
1190 | PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE
1191 { $$ = sawparens($expr); }
1194 | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1195 { $$ = sawparens(newNULLLIST()); }
1196 | scalar %prec PERLY_PAREN_OPEN
1198 | star %prec PERLY_PAREN_OPEN
1200 | hsh %prec PERLY_PAREN_OPEN
1202 | ary %prec PERLY_PAREN_OPEN
1204 | arylen %prec PERLY_PAREN_OPEN /* $#x, $#{ something } */
1205 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($arylen, OP_AV2ARYLEN));}
1207 { $$ = $subscripted; }
1208 | sliceme PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* array slice */
1209 { $$ = op_prepend_elem(OP_ASLICE,
1210 newOP(OP_PUSHMARK, 0),
1211 newLISTOP(OP_ASLICE, 0,
1213 ref($sliceme, OP_ASLICE)));
1216 $sliceme->op_private & OPpSLICEWARNING;
1218 | kvslice PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* array key/value slice */
1219 { $$ = op_prepend_elem(OP_KVASLICE,
1220 newOP(OP_PUSHMARK, 0),
1221 newLISTOP(OP_KVASLICE, 0,
1223 ref(oopsAV($kvslice), OP_KVASLICE)));
1226 $kvslice->op_private & OPpSLICEWARNING;
1228 | sliceme PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* @hash{@keys} */
1229 { $$ = op_prepend_elem(OP_HSLICE,
1230 newOP(OP_PUSHMARK, 0),
1231 newLISTOP(OP_HSLICE, 0,
1233 ref(oopsHV($sliceme), OP_HSLICE)));
1236 $sliceme->op_private & OPpSLICEWARNING;
1238 | kvslice PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* %hash{@keys} */
1239 { $$ = op_prepend_elem(OP_KVHSLICE,
1240 newOP(OP_PUSHMARK, 0),
1241 newLISTOP(OP_KVHSLICE, 0,
1243 ref($kvslice, OP_KVHSLICE)));
1246 $kvslice->op_private & OPpSLICEWARNING;
1248 | THING %prec PERLY_PAREN_OPEN
1251 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($amper)); }
1252 | amper PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* &foo() or foo() */
1253 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($amper));
1255 | amper PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* &foo(@args) or foo(@args) */
1257 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1258 op_append_elem(OP_LIST, $expr, scalar($amper)));
1260 | NOAMP subname optlistexpr /* foo @args (no parens) */
1261 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1262 op_append_elem(OP_LIST, $optlistexpr, scalar($subname)));
1264 | term[operand] ARROW PERLY_DOLLAR PERLY_STAR
1265 { $$ = newSVREF($operand); }
1266 | term[operand] ARROW PERLY_SNAIL PERLY_STAR
1267 { $$ = newAVREF($operand); }
1268 | term[operand] ARROW PERLY_PERCENT_SIGN PERLY_STAR
1269 { $$ = newHVREF($operand); }
1270 | term[operand] ARROW PERLY_AMPERSAND PERLY_STAR
1271 { $$ = newUNOP(OP_ENTERSUB, 0,
1272 scalar(newCVREF($PERLY_AMPERSAND,$operand))); }
1273 | term[operand] ARROW PERLY_STAR PERLY_STAR %prec PERLY_PAREN_OPEN
1274 { $$ = newGVREF(0,$operand); }
1275 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
1276 { $$ = newOP($LOOPEX, OPf_SPECIAL);
1277 PL_hints |= HINT_BLOCK_SCOPE; }
1278 | LOOPEX term[operand]
1279 { $$ = newLOOPEX($LOOPEX,$operand); }
1280 | NOTOP listexpr /* not $foo */
1281 { $$ = newUNOP(OP_NOT, 0, scalar($listexpr)); }
1282 | UNIOP /* Unary op, $_ implied */
1283 { $$ = newOP($UNIOP, 0); }
1284 | UNIOP block /* eval { foo }* */
1285 { $$ = newUNOP($UNIOP, 0, $block); }
1286 | UNIOP term[operand] /* Unary op */
1287 { $$ = newUNOP($UNIOP, 0, $operand); }
1288 | REQUIRE /* require, $_ implied */
1289 { $$ = newOP(OP_REQUIRE, $REQUIRE ? OPf_SPECIAL : 0); }
1290 | REQUIRE term[operand] /* require Foo */
1291 { $$ = newUNOP(OP_REQUIRE, $REQUIRE ? OPf_SPECIAL : 0, $operand); }
1293 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($UNIOPSUB)); }
1294 | UNIOPSUB term[operand] /* Sub treated as unop */
1295 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1296 op_append_elem(OP_LIST, $operand, scalar($UNIOPSUB))); }
1297 | FUNC0 /* Nullary operator */
1298 { $$ = newOP($FUNC0, 0); }
1299 | FUNC0 PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1300 { $$ = newOP($FUNC0, 0);}
1301 | FUNC0OP /* Same as above, but op created in toke.c */
1303 | FUNC0OP PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1305 | FUNC0SUB /* Sub treated as nullop */
1306 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($FUNC0SUB)); }
1307 | FUNC1 PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* not () */
1308 { $$ = ($FUNC1 == OP_NOT)
1309 ? newUNOP($FUNC1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
1310 : newOP($FUNC1, OPf_SPECIAL); }
1311 | FUNC1 PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* not($foo) */
1312 { $$ = newUNOP($FUNC1, 0, $expr); }
1313 | PMFUNC /* m//, s///, qr//, tr/// */
1315 if ( $PMFUNC->op_type != OP_TRANS
1316 && $PMFUNC->op_type != OP_TRANSR
1317 && (((PMOP*)$PMFUNC)->op_pmflags & PMf_HAS_CV))
1319 $<ival>$ = start_subparse(FALSE, CVf_ANON);
1320 SAVEFREESV(PL_compcv);
1324 SUBLEXSTART listexpr optrepl SUBLEXEND
1325 { $$ = pmruntime($PMFUNC, $listexpr, $optrepl, 1, $<ival>2); }
1331 /* "my" declarations, with optional attributes */
1332 myattrterm: MY myterm myattrlist
1333 { $$ = my_attrs($myterm,$myattrlist); }
1335 { $$ = localize($myterm,1); }
1336 | MY REFGEN myterm myattrlist
1337 { $$ = newUNOP(OP_REFGEN, 0, my_attrs($myterm,$myattrlist)); }
1340 /* Things that can be "my"'d */
1341 myterm : PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE
1342 { $$ = sawparens($expr); }
1343 | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1344 { $$ = sawparens(newNULLLIST()); }
1346 | scalar %prec PERLY_PAREN_OPEN
1348 | hsh %prec PERLY_PAREN_OPEN
1350 | ary %prec PERLY_PAREN_OPEN
1354 /* Basic list expressions */
1355 optlistexpr: %empty %prec PREC_LOW
1357 | listexpr %prec PREC_LOW
1373 /* A little bit of trickery to make "for my $foo (@bar)" actually be
1376 { parser->in_my = 0; $$ = my($scalar); }
1384 refgen_topic: my_var
1388 my_refgen: MY REFGEN
1392 amper : PERLY_AMPERSAND indirob
1393 { $$ = newCVREF($PERLY_AMPERSAND,$indirob); }
1396 scalar : PERLY_DOLLAR indirob
1397 { $$ = newSVREF($indirob); }
1400 ary : PERLY_SNAIL indirob
1401 { $$ = newAVREF($indirob);
1402 if ($$) $$->op_private |= $PERLY_SNAIL;
1406 hsh : PERLY_PERCENT_SIGN indirob
1407 { $$ = newHVREF($indirob);
1408 if ($$) $$->op_private |= $PERLY_PERCENT_SIGN;
1412 arylen : DOLSHARP indirob
1413 { $$ = newAVREF($indirob); }
1414 | term ARROW DOLSHARP PERLY_STAR
1415 { $$ = newAVREF($term); }
1418 star : PERLY_STAR indirob
1419 { $$ = newGVREF(0,$indirob); }
1423 | term ARROW PERLY_SNAIL
1424 { $$ = newAVREF($term); }
1428 | term ARROW PERLY_PERCENT_SIGN
1429 { $$ = newHVREF($term); }
1433 | term ARROW PERLY_STAR
1434 { $$ = newGVREF(0,$term); }
1437 /* Indirect objects */
1439 { $$ = scalar($BAREWORD); }
1440 | scalar %prec PREC_LOW
1441 { $$ = scalar($scalar); }
1443 { $$ = op_scope($block); }
1446 { $$ = $PRIVATEREF; }