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 /* Tokens emitted by toke.c for simple punctiation characters - &, {, }, etc... */
49 %token <ival> PERLY_AMPERSAND
50 %token <ival> PERLY_BRACE_OPEN
51 %token <ival> PERLY_BRACE_CLOSE
52 %token <ival> PERLY_BRACKET_OPEN
53 %token <ival> PERLY_BRACKET_CLOSE
54 %token <ival> PERLY_COMMA
55 %token <ival> PERLY_DOLLAR
56 %token <ival> PERLY_DOT
57 %token <ival> PERLY_EQUAL_SIGN
58 %token <ival> PERLY_MINUS
59 %token <ival> PERLY_PERCENT_SIGN
60 %token <ival> PERLY_PLUS
61 %token <ival> PERLY_SEMICOLON
62 %token <ival> PERLY_SLASH
63 %token <ival> PERLY_SNAIL
64 %token <ival> PERLY_STAR
66 /* Tokens emitted by toke.c on simple keywords */
67 %token <ival> KW_FORMAT KW_PACKAGE
68 %token <ival> KW_LOCAL KW_MY
69 %token <ival> KW_IF KW_ELSE KW_ELSIF KW_UNLESS
70 %token <ival> KW_FOR KW_UNTIL KW_WHILE KW_CONTINUE
71 %token <ival> KW_GIVEN KW_WHEN KW_DEFAULT
72 %token <ival> KW_TRY KW_CATCH KW_FINALLY KW_DEFER
73 %token <ival> KW_REQUIRE KW_DO
75 /* The 'use' and 'no' keywords both emit this */
76 %token <ival> KW_USE_or_NO
78 /* The 'sub' keyword is a bit special; four different tokens depending on
79 * named-vs-anon, and whether signatures are in effect */
80 %token <ival> KW_SUB_named KW_SUB_named_sig KW_SUB_anon KW_SUB_anon_sig
82 /* Tokens emitted in other situations */
83 %token <opval> BAREWORD METHCALL0 METHCALL THING PMFUNC PRIVATEREF QWLIST
84 %token <opval> FUNC0OP FUNC0SUB UNIOPSUB LSTOPSUB
85 %token <opval> PLUGEXPR PLUGSTMT
87 %token <ival> LOOPEX DOTDOT YADAYADA
88 %token <ival> FUNC0 FUNC1 FUNC UNIOP LSTOP
89 %token <ival> MULOP ADDOP
90 %token <ival> DOLSHARP HASHBRACK NOAMP
91 %token <ival> COLONATTR FORMLBRACK FORMRBRACK
92 %token <ival> SUBLEXSTART SUBLEXEND
94 %type <ival> grammar remember mremember
95 %type <ival> startsub startanonsub startformsub
99 %type <opval> stmtseq fullstmt labfullstmt barestmt block mblock else finally
100 %type <opval> expr term subscripted scalar ary hsh arylen star amper sideff
101 %type <opval> condition
102 %type <opval> catch_paren
104 %type <opval> sliceme kvslice gelem
105 %type <opval> listexpr nexpr texpr iexpr mexpr mnexpr
106 %type <opval> optlistexpr optexpr optrepl indirob listop methodname
107 %type <opval> formname subname proto cont my_scalar my_var
108 %type <opval> list_of_scalars my_list_of_scalars refgen_topic formblock
109 %type <opval> subattrlist myattrlist myattrterm myterm
110 %type <opval> termbinop termunop anonymous termdo
111 %type <opval> termrelop relopchain termeqop eqopchain
112 %type <ival> sigslurpsigil
113 %type <opval> sigvarname sigdefault sigscalarelem sigslurpelem
114 %type <opval> sigelem siglist optsiglist subsigguts subsignature optsubsignature
115 %type <opval> subbody optsubbody sigsubbody optsigsubbody
116 %type <opval> formstmtseq formline formarg
118 %nonassoc <ival> PREC_LOW
124 %nonassoc LSTOP LSTOPSUB
126 %right <ival> ASSIGNOP
127 %right <ival> PERLY_QUESTION_MARK PERLY_COLON
129 %left <ival> OROR DORDOR
132 %left <ival> BITANDOP
133 %left <ival> CHEQOP NCEQOP
134 %left <ival> CHRELOP NCRELOP
135 %nonassoc UNIOP UNIOPSUB
141 %right <ival> PERLY_EXCLAMATION_MARK PERLY_TILDE UMINUS REFGEN
143 %nonassoc <ival> PREINC PREDEC POSTINC POSTDEC POSTJOIN
145 %nonassoc <ival> PERLY_PAREN_CLOSE
146 %left <ival> PERLY_PAREN_OPEN
147 %left PERLY_BRACKET_OPEN PERLY_BRACE_OPEN
151 /* Top-level choice of what kind of thing yyparse was called to parse */
154 parser->expect = XSTATE;
159 newPROG(block_end($remember,$stmtseq));
160 PL_compiling.cop_seq = 0;
165 parser->expect = XTERM;
170 PL_eval_root = $optexpr;
175 parser->expect = XBLOCK;
180 PL_pad_reset_pending = TRUE;
181 PL_eval_root = $block;
184 parser->yychar = yytoken = YYEOF;
188 parser->expect = XSTATE;
193 PL_pad_reset_pending = TRUE;
194 PL_eval_root = $barestmt;
197 parser->yychar = yytoken = YYEOF;
201 parser->expect = XSTATE;
206 PL_pad_reset_pending = TRUE;
207 PL_eval_root = $fullstmt;
210 parser->yychar = yytoken = YYEOF;
214 parser->expect = XSTATE;
219 PL_eval_root = $stmtseq;
224 parser->expect = XSTATE;
229 PL_eval_root = $subsigguts;
234 /* An ordinary block */
235 block : PERLY_BRACE_OPEN remember stmtseq PERLY_BRACE_CLOSE
236 { if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
237 parser->copline = (line_t)$PERLY_BRACE_OPEN;
238 $$ = block_end($remember, $stmtseq);
243 : %empty { $$ = NULL; }
247 formblock: PERLY_EQUAL_SIGN remember PERLY_SEMICOLON FORMRBRACK formstmtseq PERLY_SEMICOLON PERLY_DOT
248 { if (parser->copline > (line_t)$PERLY_EQUAL_SIGN)
249 parser->copline = (line_t)$PERLY_EQUAL_SIGN;
250 $$ = block_end($remember, $formstmtseq);
254 remember: %empty /* start a full lexical scope */
255 { $$ = block_start(TRUE);
256 parser->parsed_sub = 0; }
259 mblock : PERLY_BRACE_OPEN mremember stmtseq PERLY_BRACE_CLOSE
260 { if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
261 parser->copline = (line_t)$PERLY_BRACE_OPEN;
262 $$ = block_end($mremember, $stmtseq);
266 mremember: %empty /* start a partial lexical scope */
267 { $$ = block_start(FALSE);
268 parser->parsed_sub = 0; }
271 /* The parenthesized variable of a catch block */
273 /* not really valid grammar but we detect it in the
274 * action block to throw a nicer error message */
276 { parser->in_my = 1; }
278 { parser->in_my = 0; intro_my(); }
283 /* A sequence of statements in the program */
286 | stmtseq[list] fullstmt
287 { $$ = op_append_list(OP_LINESEQ, $list, $fullstmt);
288 PL_pad_reset_pending = TRUE;
289 if ($list && $fullstmt)
290 PL_hints |= HINT_BLOCK_SCOPE;
294 /* A sequence of format lines */
297 | formstmtseq[list] formline
298 { $$ = op_append_list(OP_LINESEQ, $list, $formline);
299 PL_pad_reset_pending = TRUE;
300 if ($list && $formline)
301 PL_hints |= HINT_BLOCK_SCOPE;
305 /* A statement in the program, including optional labels */
308 $$ = $barestmt ? newSTATEOP(0, NULL, $barestmt) : NULL;
311 { $$ = $labfullstmt; }
314 labfullstmt: LABEL barestmt
316 SV *label = cSVOPx_sv($LABEL);
317 $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8,
318 savepv(SvPVX_const(label)), $barestmt);
321 | LABEL labfullstmt[list]
323 SV *label = cSVOPx_sv($LABEL);
324 $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8,
325 savepv(SvPVX_const(label)), $list);
330 /* A bare statement, lacking label and other aspects of state op */
333 | KW_FORMAT startformsub formname formblock
335 CV *fmtcv = PL_compcv;
336 newFORM($startformsub, $formname, $formblock);
338 if (CvOUTSIDE(fmtcv) && !CvEVAL(CvOUTSIDE(fmtcv))) {
339 pad_add_weakref(fmtcv);
341 parser->parsed_sub = 1;
343 | KW_SUB_named subname startsub
344 /* sub declaration or definition not within scope
345 of 'use feature "signatures"'*/
347 init_named_cv(PL_compcv, $subname);
349 parser->in_my_stash = NULL;
351 proto subattrlist optsubbody
353 SvREFCNT_inc_simple_void(PL_compcv);
354 $subname->op_type == OP_CONST
355 ? newATTRSUB($startsub, $subname, $proto, $subattrlist, $optsubbody)
356 : newMYSUB($startsub, $subname, $proto, $subattrlist, $optsubbody)
360 parser->parsed_sub = 1;
362 | KW_SUB_named_sig subname startsub
363 /* sub declaration or definition under 'use feature
364 * "signatures"'. (Note that a signature isn't
365 * allowed in a declaration)
368 init_named_cv(PL_compcv, $subname);
370 parser->in_my_stash = NULL;
372 subattrlist optsigsubbody
374 SvREFCNT_inc_simple_void(PL_compcv);
375 $subname->op_type == OP_CONST
376 ? newATTRSUB($startsub, $subname, NULL, $subattrlist, $optsigsubbody)
377 : newMYSUB( $startsub, $subname, NULL, $subattrlist, $optsigsubbody)
381 parser->parsed_sub = 1;
383 | KW_PACKAGE BAREWORD[version] BAREWORD[package] PERLY_SEMICOLON
387 package_version($version);
390 | KW_USE_or_NO startsub
391 { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
392 BAREWORD[version] BAREWORD[module] optlistexpr PERLY_SEMICOLON
394 SvREFCNT_inc_simple_void(PL_compcv);
395 utilize($KW_USE_or_NO, $startsub, $version, $module, $optlistexpr);
396 parser->parsed_sub = 1;
399 | KW_IF PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock else
401 $$ = block_end($remember,
402 newCONDOP(0, $mexpr, op_scope($mblock), $else));
403 parser->copline = (line_t)$KW_IF;
405 | KW_UNLESS PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock else
407 $$ = block_end($remember,
408 newCONDOP(0, $mexpr, $else, op_scope($mblock)));
409 parser->copline = (line_t)$KW_UNLESS;
411 | KW_GIVEN PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock
413 $$ = block_end($remember, newGIVENOP($mexpr, op_scope($mblock), 0));
414 parser->copline = (line_t)$KW_GIVEN;
416 | KW_WHEN PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock
417 { $$ = block_end($remember, newWHENOP($mexpr, op_scope($mblock))); }
419 { $$ = newWHENOP(0, op_scope($block)); }
420 | KW_WHILE PERLY_PAREN_OPEN remember texpr PERLY_PAREN_CLOSE mintro mblock cont
422 $$ = block_end($remember,
423 newWHILEOP(0, 1, NULL,
424 $texpr, $mblock, $cont, $mintro));
425 parser->copline = (line_t)$KW_WHILE;
427 | KW_UNTIL PERLY_PAREN_OPEN remember iexpr PERLY_PAREN_CLOSE mintro mblock cont
429 $$ = block_end($remember,
430 newWHILEOP(0, 1, NULL,
431 $iexpr, $mblock, $cont, $mintro));
432 parser->copline = (line_t)$KW_UNTIL;
434 | KW_FOR PERLY_PAREN_OPEN remember mnexpr[init_mnexpr] PERLY_SEMICOLON
435 { parser->expect = XTERM; }
436 texpr PERLY_SEMICOLON
437 { parser->expect = XTERM; }
438 mintro mnexpr[iterate_mnexpr] PERLY_PAREN_CLOSE
441 OP *initop = $init_mnexpr;
442 OP *forop = newWHILEOP(0, 1, NULL,
443 scalar($texpr), $mblock, $iterate_mnexpr, $mintro);
445 forop = op_prepend_elem(OP_LINESEQ, initop,
446 op_append_elem(OP_LINESEQ,
447 newOP(OP_UNSTACK, OPf_SPECIAL),
450 PL_hints |= HINT_BLOCK_SCOPE;
451 $$ = block_end($remember, forop);
452 parser->copline = (line_t)$KW_FOR;
454 | KW_FOR KW_MY remember my_scalar PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont
456 $$ = block_end($remember, newFOROP(0, $my_scalar, $mexpr, $mblock, $cont));
457 parser->copline = (line_t)$KW_FOR;
459 | KW_FOR KW_MY remember PERLY_PAREN_OPEN my_list_of_scalars PERLY_PAREN_CLOSE PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont
461 if ($my_list_of_scalars->op_type == OP_PADSV)
462 /* degenerate case of 1 var: for my ($x) ....
463 Flag it so it can be special-cased in newFOROP */
464 $my_list_of_scalars->op_flags |= OPf_PARENS;
465 $$ = block_end($remember, newFOROP(0, $my_list_of_scalars, $mexpr, $mblock, $cont));
466 parser->copline = (line_t)$KW_FOR;
468 | KW_FOR scalar PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
470 $$ = block_end($remember, newFOROP(0,
471 op_lvalue($scalar, OP_ENTERLOOP), $mexpr, $mblock, $cont));
472 parser->copline = (line_t)$KW_FOR;
474 | KW_FOR my_refgen remember my_var
475 { parser->in_my = 0; $<opval>$ = my($my_var); }[variable]
476 PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont
482 newUNOP(OP_REFGEN, 0,
485 $mexpr, $mblock, $cont)
487 parser->copline = (line_t)$KW_FOR;
489 | KW_FOR REFGEN refgen_topic PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
491 $$ = block_end($remember, newFOROP(
492 0, op_lvalue(newUNOP(OP_REFGEN, 0,
494 OP_ENTERLOOP), $mexpr, $mblock, $cont));
495 parser->copline = (line_t)$KW_FOR;
497 | KW_FOR PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
499 $$ = block_end($remember,
500 newFOROP(0, NULL, $mexpr, $mblock, $cont));
501 parser->copline = (line_t)$KW_FOR;
503 | KW_TRY mblock[try] KW_CATCH remember catch_paren[scalar]
506 yyerror("catch block requires a (VAR)");
510 mblock[catch] finally
512 $$ = newTRYCATCHOP(0,
513 $try, $scalar, block_end($remember, op_scope($catch)));
515 $$ = op_wrap_finally($$, $finally);
516 parser->copline = (line_t)$KW_TRY;
520 /* a block is a loop that happens once */
521 $$ = newWHILEOP(0, 1, NULL,
522 NULL, $block, $cont, 0);
524 | KW_PACKAGE BAREWORD[version] BAREWORD[package] PERLY_BRACE_OPEN remember
528 package_version($version);
531 stmtseq PERLY_BRACE_CLOSE
533 /* a block is a loop that happens once */
534 $$ = newWHILEOP(0, 1, NULL,
535 NULL, block_end($remember, $stmtseq), NULL, 0);
536 if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
537 parser->copline = (line_t)$PERLY_BRACE_OPEN;
539 | sideff PERLY_SEMICOLON
545 $$ = newDEFEROP(0, op_scope($2));
547 | YADAYADA PERLY_SEMICOLON
549 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
550 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
555 parser->copline = NOLINE;
560 formline: THING formarg
564 list = op_append_elem(OP_LIST, $THING, term);
569 if (parser->copline == NOLINE)
570 parser->copline = CopLINE(PL_curcop)-1;
571 else parser->copline--;
572 $$ = newSTATEOP(0, NULL,
573 op_convert_list(OP_FORMLINE, 0, list));
579 | FORMLBRACK stmtseq FORMRBRACK
580 { $$ = op_unscope($stmtseq); }
586 /* An expression which may have a side-effect */
591 | expr[body] KW_IF condition
592 { $$ = newLOGOP(OP_AND, 0, $condition, $body); }
593 | expr[body] KW_UNLESS condition
594 { $$ = newLOGOP(OP_OR, 0, $condition, $body); }
595 | expr[body] KW_WHILE condition
596 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($condition), $body); }
597 | expr[body] KW_UNTIL iexpr
598 { $$ = newLOOPOP(OPf_PARENS, 1, $iexpr, $body); }
599 | expr[body] KW_FOR condition
600 { $$ = newFOROP(0, NULL, $condition, $body, NULL);
601 parser->copline = (line_t)$KW_FOR; }
602 | expr[body] KW_WHEN condition
603 { $$ = newWHENOP($condition, op_scope($body)); }
606 /* else and elsif blocks */
611 ($mblock)->op_flags |= OPf_PARENS;
612 $$ = op_scope($mblock);
614 | KW_ELSIF PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock else[else.recurse]
615 { parser->copline = (line_t)$KW_ELSIF;
617 newSTATEOP(OPf_SPECIAL,NULL,$mexpr),
618 op_scope($mblock), $[else.recurse]);
619 PL_hints |= HINT_BLOCK_SCOPE;
623 /* Continue blocks */
627 { $$ = op_scope($block); }
634 { $$ = op_scope($block); }
637 /* determine whether there are any new my declarations */
639 { $$ = (PL_min_intro_pending &&
640 PL_max_intro_pending >= PL_min_intro_pending);
643 /* Normal expression */
649 /* Boolean expression */
650 texpr : %empty /* NULL means true */
652 (void)scan_num("1", &tmplval);
653 $$ = tmplval.opval; }
657 /* Inverted boolean expression */
659 { $$ = invert(scalar($expr)); }
662 /* Expression with its own lexical scope */
664 { $$ = $expr; intro_my(); }
668 { $$ = $nexpr; intro_my(); }
671 formname: BAREWORD { $$ = $BAREWORD; }
675 startsub: %empty /* start a regular subroutine scope */
676 { $$ = start_subparse(FALSE, 0);
677 SAVEFREESV(PL_compcv); }
681 startanonsub: %empty /* start an anonymous subroutine scope */
682 { $$ = start_subparse(FALSE, CVf_ANON);
683 SAVEFREESV(PL_compcv); }
686 startformsub: %empty /* start a format subroutine scope */
687 { $$ = start_subparse(TRUE, 0);
688 SAVEFREESV(PL_compcv); }
691 /* Name of a subroutine - must be a bareword, could be special */
696 /* Subroutine prototype */
702 /* Optional list of subroutine attributes */
711 /* List of attributes for a "my" variable declaration */
712 myattrlist: COLONATTR THING
720 /* --------------------------------------
721 * subroutine signature parsing
724 /* the '' or 'foo' part of a '$' or '@foo' etc signature variable */
726 { parser->in_my = 0; $$ = NULL; }
728 { parser->in_my = 0; $$ = $PRIVATEREF; }
737 /* @, %, @foo, %foo */
738 sigslurpelem: sigslurpsigil sigvarname sigdefault/* def only to catch errors */
740 I32 sigil = $sigslurpsigil;
741 OP *var = $sigvarname;
742 OP *defexpr = $sigdefault;
744 if (parser->sig_slurpy)
745 yyerror("Multiple slurpy parameters not allowed");
746 parser->sig_slurpy = (char)sigil;
749 yyerror("A slurpy parameter may not have "
752 $$ = var ? newSTATEOP(0, NULL, var) : NULL;
756 /* default part of sub signature scalar element: i.e. '= default_expr' */
760 { $$ = newOP(OP_NULL, 0); }
765 /* subroutine signature scalar element: e.g. '$x', '$=', '$x = $default' */
767 PERLY_DOLLAR sigvarname sigdefault
769 OP *var = $sigvarname;
770 OP *defexpr = $sigdefault;
772 if (parser->sig_slurpy)
773 yyerror("Slurpy parameter not last");
778 parser->sig_optelems++;
780 if ( defexpr->op_type == OP_NULL
781 && !(defexpr->op_flags & OPf_KIDS))
783 /* handle '$=' special case */
785 yyerror("Optional parameter "
786 "lacks default expression");
790 /* a normal '=default' expression */
791 OP *defop = (OP*)alloc_LOGOP(OP_ARGDEFELEM,
794 /* re-purpose op_targ to hold @_ index */
796 (PADOFFSET)(parser->sig_elems - 1);
799 var->op_flags |= OPf_STACKED;
800 (void)op_sibling_splice(var,
805 var = newUNOP(OP_NULL, 0, defop);
808 /* NB: normally the first child of a
809 * logop is executed before the logop,
810 * and it pushes a boolean result
811 * ready for the logop. For ARGDEFELEM,
812 * the op itself does the boolean
813 * calculation, so set the first op to
816 var->op_next = defop;
817 defexpr->op_next = var;
821 if (parser->sig_optelems)
822 yyerror("Mandatory parameter "
823 "follows optional parameter");
826 $$ = var ? newSTATEOP(0, NULL, var) : NULL;
831 /* subroutine signature element: e.g. '$x = $default' or '%h' */
832 sigelem: sigscalarelem
833 { parser->in_my = KEY_sigvar; $$ = $sigscalarelem; }
835 { parser->in_my = KEY_sigvar; $$ = $sigslurpelem; }
838 /* list of subroutine signature elements */
840 siglist[list] PERLY_COMMA
842 | siglist[list] PERLY_COMMA sigelem[element]
844 $$ = op_append_list(OP_LINESEQ, $list, $element);
846 | sigelem[element] %prec PREC_LOW
856 /* optional subroutine signature */
862 /* Subroutine signature */
863 subsignature: PERLY_PAREN_OPEN subsigguts PERLY_PAREN_CLOSE
864 { $$ = $subsigguts; }
869 SAVEIV(parser->sig_elems);
870 SAVEIV(parser->sig_optelems);
871 SAVEI8(parser->sig_slurpy);
872 parser->sig_elems = 0;
873 parser->sig_optelems = 0;
874 parser->sig_slurpy = 0;
875 parser->in_my = KEY_sigvar;
879 OP *sigops = $optsiglist;
880 struct op_argcheck_aux *aux;
883 if (!FEATURE_SIGNATURES_IS_ENABLED)
884 Perl_croak(aTHX_ "Experimental "
885 "subroutine signatures not enabled");
887 /* We shouldn't get here otherwise */
888 aux = (struct op_argcheck_aux*)
889 PerlMemShared_malloc(
890 sizeof(struct op_argcheck_aux));
891 aux->params = parser->sig_elems;
892 aux->opt_params = parser->sig_optelems;
893 aux->slurpy = parser->sig_slurpy;
894 check = newUNOP_AUX(OP_ARGCHECK, 0, NULL,
895 (UNOP_AUX_item *)aux);
896 sigops = op_prepend_elem(OP_LINESEQ, check, sigops);
897 sigops = op_prepend_elem(OP_LINESEQ,
898 newSTATEOP(0, NULL, NULL),
900 /* a nextstate at the end handles context
901 * correctly for an empty sub body */
902 sigops = op_append_elem(OP_LINESEQ,
904 newSTATEOP(0, NULL, NULL));
905 /* wrap the list of arg ops in a NULL aux op.
906 This serves two purposes. First, it makes
907 the arg list a separate subtree from the
908 body of the sub, and secondly the null op
909 may in future be upgraded to an OP_SIGNATURE
910 when implemented. For now leave it as
912 $$ = newUNOP_AUX(OP_ARGCHECK, 0, sigops, NULL);
915 CvSIGNATURE_on(PL_compcv);
918 /* tell the toker that attrributes can follow
919 * this sig, but only so that the toker
920 * can skip through any (illegal) trailing
921 * attribute text then give a useful error
922 * message about "attributes before sig",
923 * rather than falling over ina mess at
924 * unrecognised syntax.
926 parser->expect = XATTRBLOCK;
927 parser->sig_seen = TRUE;
932 /* Optional subroutine body (for named subroutine declaration) */
935 | PERLY_SEMICOLON { $$ = NULL; }
939 /* Subroutine body (without signature) */
940 subbody: remember PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE
942 if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
943 parser->copline = (line_t)$PERLY_BRACE_OPEN;
944 $$ = block_end($remember, $stmtseq);
949 /* optional [ Subroutine body with optional signature ] (for named
950 * subroutine declaration) */
953 | PERLY_SEMICOLON { $$ = NULL; }
956 /* Subroutine body with optional signature */
957 sigsubbody: remember optsubsignature PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE
959 if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
960 parser->copline = (line_t)$PERLY_BRACE_OPEN;
961 $$ = block_end($remember,
962 op_append_list(OP_LINESEQ, $optsubsignature, $stmtseq));
967 /* Ordinary expressions; logical combinations */
968 expr : expr[lhs] ANDOP expr[rhs]
969 { $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); }
970 | expr[lhs] OROP[operator] expr[rhs]
971 { $$ = newLOGOP($operator, 0, $lhs, $rhs); }
972 | listexpr %prec PREC_LOW
975 /* Expressions are a list of terms joined by commas */
976 listexpr: listexpr[list] PERLY_COMMA
978 | listexpr[list] PERLY_COMMA term
981 $$ = op_append_elem(OP_LIST, $list, term);
983 | term %prec PREC_LOW
987 listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
988 { $$ = op_convert_list($LSTOP, OPf_STACKED,
989 op_prepend_elem(OP_LIST, newGVREF($LSTOP,$indirob), $listexpr) );
991 | FUNC PERLY_PAREN_OPEN indirob expr PERLY_PAREN_CLOSE /* print ($fh @args */
992 { $$ = op_convert_list($FUNC, OPf_STACKED,
993 op_prepend_elem(OP_LIST, newGVREF($FUNC,$indirob), $expr) );
995 | term ARROW methodname PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* $foo->bar(list) */
996 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
997 op_append_elem(OP_LIST,
998 op_prepend_elem(OP_LIST, scalar($term), $optexpr),
999 newMETHOP(OP_METHOD, 0, $methodname)));
1001 | term ARROW methodname /* $foo->bar */
1002 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
1003 op_append_elem(OP_LIST, scalar($term),
1004 newMETHOP(OP_METHOD, 0, $methodname)));
1006 | METHCALL0 indirob optlistexpr /* new Class @args */
1007 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
1008 op_append_elem(OP_LIST,
1009 op_prepend_elem(OP_LIST, $indirob, $optlistexpr),
1010 newMETHOP(OP_METHOD, 0, $METHCALL0)));
1012 | METHCALL indirob PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* method $object (@args) */
1013 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
1014 op_append_elem(OP_LIST,
1015 op_prepend_elem(OP_LIST, $indirob, $optexpr),
1016 newMETHOP(OP_METHOD, 0, $METHCALL)));
1018 | LSTOP optlistexpr /* print @args */
1019 { $$ = op_convert_list($LSTOP, 0, $optlistexpr); }
1020 | FUNC PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* print (@args) */
1021 { $$ = op_convert_list($FUNC, 0, $optexpr); }
1022 | FUNC SUBLEXSTART optexpr SUBLEXEND /* uc($arg) from "\U..." */
1023 { $$ = op_convert_list($FUNC, 0, $optexpr); }
1024 | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */
1025 { SvREFCNT_inc_simple_void(PL_compcv);
1026 $<opval>$ = newANONATTRSUB($startanonsub, 0, NULL, $block); }[anonattrsub]
1027 optlistexpr %prec LSTOP /* ... @bar */
1028 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1029 op_append_elem(OP_LIST,
1030 op_prepend_elem(OP_LIST, $<opval>anonattrsub, $optlistexpr), $LSTOPSUB));
1034 /* Names of methods. May use $object->$methodname */
1035 methodname: METHCALL0
1039 /* Some kind of subscripted expression */
1040 subscripted: gelem PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* *main::{something} */
1041 /* In this and all the hash accessors, PERLY_SEMICOLON is
1042 * provided by the tokeniser */
1043 { $$ = newBINOP(OP_GELEM, 0, $gelem, scalar($expr)); }
1044 | scalar[array] PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* $array[$element] */
1045 { $$ = newBINOP(OP_AELEM, 0, oopsAV($array), scalar($expr));
1047 | term[array_reference] ARROW PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* somearef->[$element] */
1048 { $$ = newBINOP(OP_AELEM, 0,
1049 ref(newAVREF($array_reference),OP_RV2AV),
1052 | subscripted[array_reference] PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* $foo->[$bar]->[$baz] */
1053 { $$ = newBINOP(OP_AELEM, 0,
1054 ref(newAVREF($array_reference),OP_RV2AV),
1057 | scalar[hash] PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* $foo{bar();} */
1058 { $$ = newBINOP(OP_HELEM, 0, oopsHV($hash), jmaybe($expr));
1060 | term[hash_reference] ARROW PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* somehref->{bar();} */
1061 { $$ = newBINOP(OP_HELEM, 0,
1062 ref(newHVREF($hash_reference),OP_RV2HV),
1064 | subscripted[hash_reference] PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* $foo->[bar]->{baz;} */
1065 { $$ = newBINOP(OP_HELEM, 0,
1066 ref(newHVREF($hash_reference),OP_RV2HV),
1068 | term[code_reference] ARROW PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* $subref->() */
1069 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1070 newCVREF(0, scalar($code_reference)));
1071 if (parser->expect == XBLOCK)
1072 parser->expect = XOPERATOR;
1074 | term[code_reference] ARROW PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* $subref->(@args) */
1075 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1076 op_append_elem(OP_LIST, $expr,
1077 newCVREF(0, scalar($code_reference))));
1078 if (parser->expect == XBLOCK)
1079 parser->expect = XOPERATOR;
1082 | subscripted[code_reference] PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* $foo->{bar}->(@args) */
1083 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1084 op_append_elem(OP_LIST, $expr,
1085 newCVREF(0, scalar($code_reference))));
1086 if (parser->expect == XBLOCK)
1087 parser->expect = XOPERATOR;
1089 | subscripted[code_reference] PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* $foo->{bar}->() */
1090 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1091 newCVREF(0, scalar($code_reference)));
1092 if (parser->expect == XBLOCK)
1093 parser->expect = XOPERATOR;
1095 | PERLY_PAREN_OPEN expr[list] PERLY_PAREN_CLOSE PERLY_BRACKET_OPEN expr[slice] PERLY_BRACKET_CLOSE /* list slice */
1096 { $$ = newSLICEOP(0, $slice, $list); }
1097 | QWLIST PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* list literal slice */
1098 { $$ = newSLICEOP(0, $expr, $QWLIST); }
1099 | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* empty list slice! */
1100 { $$ = newSLICEOP(0, $expr, NULL); }
1103 /* Binary operators between terms */
1104 termbinop: term[lhs] ASSIGNOP term[rhs] /* $x = $y, $x += $y */
1105 { $$ = newASSIGNOP(OPf_STACKED, $lhs, $ASSIGNOP, $rhs); }
1106 | term[lhs] POWOP term[rhs] /* $x ** $y */
1107 { $$ = newBINOP($POWOP, 0, scalar($lhs), scalar($rhs)); }
1108 | term[lhs] MULOP term[rhs] /* $x * $y, $x x $y */
1109 { if ($MULOP != OP_REPEAT)
1111 $$ = newBINOP($MULOP, 0, $lhs, scalar($rhs));
1113 | term[lhs] ADDOP term[rhs] /* $x + $y */
1114 { $$ = newBINOP($ADDOP, 0, scalar($lhs), scalar($rhs)); }
1115 | term[lhs] SHIFTOP term[rhs] /* $x >> $y, $x << $y */
1116 { $$ = newBINOP($SHIFTOP, 0, scalar($lhs), scalar($rhs)); }
1117 | termrelop %prec PREC_LOW /* $x > $y, etc. */
1118 { $$ = $termrelop; }
1119 | termeqop %prec PREC_LOW /* $x == $y, $x cmp $y */
1121 | term[lhs] BITANDOP term[rhs] /* $x & $y */
1122 { $$ = newBINOP($BITANDOP, 0, scalar($lhs), scalar($rhs)); }
1123 | term[lhs] BITOROP term[rhs] /* $x | $y */
1124 { $$ = newBINOP($BITOROP, 0, scalar($lhs), scalar($rhs)); }
1125 | term[lhs] DOTDOT term[rhs] /* $x..$y, $x...$y */
1126 { $$ = newRANGE($DOTDOT, scalar($lhs), scalar($rhs)); }
1127 | term[lhs] ANDAND term[rhs] /* $x && $y */
1128 { $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); }
1129 | term[lhs] OROR term[rhs] /* $x || $y */
1130 { $$ = newLOGOP(OP_OR, 0, $lhs, $rhs); }
1131 | term[lhs] DORDOR term[rhs] /* $x // $y */
1132 { $$ = newLOGOP(OP_DOR, 0, $lhs, $rhs); }
1133 | term[lhs] MATCHOP term[rhs] /* $x =~ /$y/ */
1134 { $$ = bind_match($MATCHOP, $lhs, $rhs); }
1137 termrelop: relopchain %prec PREC_LOW
1138 { $$ = cmpchain_finish($relopchain); }
1139 | term[lhs] NCRELOP term[rhs]
1140 { $$ = newBINOP($NCRELOP, 0, scalar($lhs), scalar($rhs)); }
1142 { yyerror("syntax error"); YYERROR; }
1144 { yyerror("syntax error"); YYERROR; }
1147 relopchain: term[lhs] CHRELOP term[rhs]
1148 { $$ = cmpchain_start($CHRELOP, $lhs, $rhs); }
1149 | relopchain[lhs] CHRELOP term[rhs]
1150 { $$ = cmpchain_extend($CHRELOP, $lhs, $rhs); }
1153 termeqop: eqopchain %prec PREC_LOW
1154 { $$ = cmpchain_finish($eqopchain); }
1155 | term[lhs] NCEQOP term[rhs]
1156 { $$ = newBINOP($NCEQOP, 0, scalar($lhs), scalar($rhs)); }
1158 { yyerror("syntax error"); YYERROR; }
1160 { yyerror("syntax error"); YYERROR; }
1163 eqopchain: term[lhs] CHEQOP term[rhs]
1164 { $$ = cmpchain_start($CHEQOP, $lhs, $rhs); }
1165 | eqopchain[lhs] CHEQOP term[rhs]
1166 { $$ = cmpchain_extend($CHEQOP, $lhs, $rhs); }
1169 /* Unary operators and terms */
1170 termunop : PERLY_MINUS term %prec UMINUS /* -$x */
1171 { $$ = newUNOP(OP_NEGATE, 0, scalar($term)); }
1172 | PERLY_PLUS term %prec UMINUS /* +$x */
1175 | PERLY_EXCLAMATION_MARK term /* !$x */
1176 { $$ = newUNOP(OP_NOT, 0, scalar($term)); }
1177 | PERLY_TILDE term /* ~$x */
1178 { $$ = newUNOP($PERLY_TILDE, 0, scalar($term)); }
1179 | term POSTINC /* $x++ */
1180 { $$ = newUNOP(OP_POSTINC, 0,
1181 op_lvalue(scalar($term), OP_POSTINC)); }
1182 | term POSTDEC /* $x-- */
1183 { $$ = newUNOP(OP_POSTDEC, 0,
1184 op_lvalue(scalar($term), OP_POSTDEC));}
1185 | term POSTJOIN /* implicit join after interpolated ->@ */
1186 { $$ = op_convert_list(OP_JOIN, 0,
1196 | PREINC term /* ++$x */
1197 { $$ = newUNOP(OP_PREINC, 0,
1198 op_lvalue(scalar($term), OP_PREINC)); }
1199 | PREDEC term /* --$x */
1200 { $$ = newUNOP(OP_PREDEC, 0,
1201 op_lvalue(scalar($term), OP_PREDEC)); }
1205 /* Constructors for anonymous data */
1207 : PERLY_BRACKET_OPEN optexpr PERLY_BRACKET_CLOSE
1208 { $$ = newANONLIST($optexpr); }
1209 | HASHBRACK optexpr PERLY_SEMICOLON PERLY_BRACE_CLOSE %prec PERLY_PAREN_OPEN /* { foo => "Bar" } */
1210 { $$ = newANONHASH($optexpr); }
1211 | KW_SUB_anon startanonsub proto subattrlist subbody %prec PERLY_PAREN_OPEN
1212 { SvREFCNT_inc_simple_void(PL_compcv);
1213 $$ = newANONATTRSUB($startanonsub, $proto, $subattrlist, $subbody); }
1214 | KW_SUB_anon_sig startanonsub subattrlist sigsubbody %prec PERLY_PAREN_OPEN
1215 { SvREFCNT_inc_simple_void(PL_compcv);
1216 $$ = newANONATTRSUB($startanonsub, NULL, $subattrlist, $sigsubbody); }
1219 /* Things called with "do" */
1220 termdo : KW_DO term %prec UNIOP /* do $filename */
1221 { $$ = dofile($term, $KW_DO);}
1222 | KW_DO block %prec PERLY_PAREN_OPEN /* do { code */
1223 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($block));}
1226 term[product] : termbinop
1230 | term[condition] PERLY_QUESTION_MARK term[then] PERLY_COLON term[else]
1231 { $$ = newCONDOP(0, $condition, $then, $else); }
1232 | REFGEN term[operand] /* \$x, \@y, \%z */
1233 { $$ = newUNOP(OP_REFGEN, 0, $operand); }
1234 | myattrterm %prec UNIOP
1235 { $$ = $myattrterm; }
1236 | KW_LOCAL term[operand] %prec UNIOP
1237 { $$ = localize($operand,0); }
1238 | PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE
1239 { $$ = sawparens($expr); }
1242 | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1243 { $$ = sawparens(newNULLLIST()); }
1244 | scalar %prec PERLY_PAREN_OPEN
1246 | star %prec PERLY_PAREN_OPEN
1248 | hsh %prec PERLY_PAREN_OPEN
1250 | ary %prec PERLY_PAREN_OPEN
1252 | arylen %prec PERLY_PAREN_OPEN /* $#x, $#{ something } */
1253 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($arylen, OP_AV2ARYLEN));}
1255 { $$ = $subscripted; }
1256 | sliceme PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* array slice */
1257 { $$ = op_prepend_elem(OP_ASLICE,
1258 newOP(OP_PUSHMARK, 0),
1259 newLISTOP(OP_ASLICE, 0,
1261 ref($sliceme, OP_ASLICE)));
1264 $sliceme->op_private & OPpSLICEWARNING;
1266 | kvslice PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* array key/value slice */
1267 { $$ = op_prepend_elem(OP_KVASLICE,
1268 newOP(OP_PUSHMARK, 0),
1269 newLISTOP(OP_KVASLICE, 0,
1271 ref(oopsAV($kvslice), OP_KVASLICE)));
1274 $kvslice->op_private & OPpSLICEWARNING;
1276 | sliceme PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* @hash{@keys} */
1277 { $$ = op_prepend_elem(OP_HSLICE,
1278 newOP(OP_PUSHMARK, 0),
1279 newLISTOP(OP_HSLICE, 0,
1281 ref(oopsHV($sliceme), OP_HSLICE)));
1284 $sliceme->op_private & OPpSLICEWARNING;
1286 | kvslice PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* %hash{@keys} */
1287 { $$ = op_prepend_elem(OP_KVHSLICE,
1288 newOP(OP_PUSHMARK, 0),
1289 newLISTOP(OP_KVHSLICE, 0,
1291 ref($kvslice, OP_KVHSLICE)));
1294 $kvslice->op_private & OPpSLICEWARNING;
1296 | THING %prec PERLY_PAREN_OPEN
1299 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($amper)); }
1300 | amper PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* &foo() or foo() */
1301 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($amper));
1303 | amper PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* &foo(@args) or foo(@args) */
1305 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1306 op_append_elem(OP_LIST, $expr, scalar($amper)));
1308 | NOAMP subname optlistexpr /* foo @args (no parens) */
1309 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1310 op_append_elem(OP_LIST, $optlistexpr, scalar($subname)));
1312 | term[operand] ARROW PERLY_DOLLAR PERLY_STAR
1313 { $$ = newSVREF($operand); }
1314 | term[operand] ARROW PERLY_SNAIL PERLY_STAR
1315 { $$ = newAVREF($operand); }
1316 | term[operand] ARROW PERLY_PERCENT_SIGN PERLY_STAR
1317 { $$ = newHVREF($operand); }
1318 | term[operand] ARROW PERLY_AMPERSAND PERLY_STAR
1319 { $$ = newUNOP(OP_ENTERSUB, 0,
1320 scalar(newCVREF($PERLY_AMPERSAND,$operand))); }
1321 | term[operand] ARROW PERLY_STAR PERLY_STAR %prec PERLY_PAREN_OPEN
1322 { $$ = newGVREF(0,$operand); }
1323 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
1324 { $$ = newOP($LOOPEX, OPf_SPECIAL);
1325 PL_hints |= HINT_BLOCK_SCOPE; }
1326 | LOOPEX term[operand]
1327 { $$ = newLOOPEX($LOOPEX,$operand); }
1328 | NOTOP listexpr /* not $foo */
1329 { $$ = newUNOP(OP_NOT, 0, scalar($listexpr)); }
1330 | UNIOP /* Unary op, $_ implied */
1331 { $$ = newOP($UNIOP, 0); }
1332 | UNIOP block /* eval { foo }* */
1333 { $$ = newUNOP($UNIOP, 0, $block); }
1334 | UNIOP term[operand] /* Unary op */
1335 { $$ = newUNOP($UNIOP, 0, $operand); }
1336 | KW_REQUIRE /* require, $_ implied */
1337 { $$ = newOP(OP_REQUIRE, $KW_REQUIRE ? OPf_SPECIAL : 0); }
1338 | KW_REQUIRE term[operand] /* require Foo */
1339 { $$ = newUNOP(OP_REQUIRE, $KW_REQUIRE ? OPf_SPECIAL : 0, $operand); }
1341 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($UNIOPSUB)); }
1342 | UNIOPSUB term[operand] /* Sub treated as unop */
1343 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1344 op_append_elem(OP_LIST, $operand, scalar($UNIOPSUB))); }
1345 | FUNC0 /* Nullary operator */
1346 { $$ = newOP($FUNC0, 0); }
1347 | FUNC0 PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1348 { $$ = newOP($FUNC0, 0);}
1349 | FUNC0OP /* Same as above, but op created in toke.c */
1351 | FUNC0OP PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1353 | FUNC0SUB /* Sub treated as nullop */
1354 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($FUNC0SUB)); }
1355 | FUNC1 PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* not () */
1356 { $$ = ($FUNC1 == OP_NOT)
1357 ? newUNOP($FUNC1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
1358 : newOP($FUNC1, OPf_SPECIAL); }
1359 | FUNC1 PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* not($foo) */
1360 { $$ = newUNOP($FUNC1, 0, $expr); }
1361 | PMFUNC /* m//, s///, qr//, tr/// */
1363 if ( $PMFUNC->op_type != OP_TRANS
1364 && $PMFUNC->op_type != OP_TRANSR
1365 && (((PMOP*)$PMFUNC)->op_pmflags & PMf_HAS_CV))
1367 $<ival>$ = start_subparse(FALSE, CVf_ANON);
1368 SAVEFREESV(PL_compcv);
1372 SUBLEXSTART listexpr optrepl SUBLEXEND
1373 { $$ = pmruntime($PMFUNC, $listexpr, $optrepl, 1, $<ival>2); }
1379 /* "my" declarations, with optional attributes */
1381 : KW_MY myterm myattrlist
1382 { $$ = my_attrs($myterm,$myattrlist); }
1384 { $$ = localize($myterm,1); }
1385 | KW_MY REFGEN myterm myattrlist
1386 { $$ = newUNOP(OP_REFGEN, 0, my_attrs($myterm,$myattrlist)); }
1387 | KW_MY REFGEN term[operand]
1388 { $$ = newUNOP(OP_REFGEN, 0, localize($operand,1)); }
1391 /* Things that can be "my"'d */
1392 myterm : PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE
1393 { $$ = sawparens($expr); }
1394 | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1395 { $$ = sawparens(newNULLLIST()); }
1397 | scalar %prec PERLY_PAREN_OPEN
1399 | hsh %prec PERLY_PAREN_OPEN
1401 | ary %prec PERLY_PAREN_OPEN
1405 /* Basic list expressions */
1407 : empty %prec PREC_LOW
1408 | listexpr %prec PREC_LOW
1418 | PERLY_SLASH expr { $$ = $expr; }
1421 /* A little bit of trickery to make "for my $foo (@bar)" actually be
1424 { parser->in_my = 0; $$ = my($scalar); }
1427 /* A list of scalars for "for my ($foo, $bar) (@baz)" */
1428 list_of_scalars: list_of_scalars[list] PERLY_COMMA
1430 | list_of_scalars[list] PERLY_COMMA scalar
1432 $$ = op_append_elem(OP_LIST, $list, $scalar);
1434 | scalar %prec PREC_LOW
1437 my_list_of_scalars: list_of_scalars
1438 { parser->in_my = 0; $$ = $list_of_scalars; }
1446 refgen_topic: my_var
1450 my_refgen: KW_MY REFGEN
1454 amper : PERLY_AMPERSAND indirob
1455 { $$ = newCVREF($PERLY_AMPERSAND,$indirob); }
1458 scalar : PERLY_DOLLAR indirob
1459 { $$ = newSVREF($indirob); }
1462 ary : PERLY_SNAIL indirob
1463 { $$ = newAVREF($indirob);
1464 if ($$) $$->op_private |= $PERLY_SNAIL;
1468 hsh : PERLY_PERCENT_SIGN indirob
1469 { $$ = newHVREF($indirob);
1470 if ($$) $$->op_private |= $PERLY_PERCENT_SIGN;
1474 arylen : DOLSHARP indirob
1475 { $$ = newAVREF($indirob); }
1476 | term ARROW DOLSHARP PERLY_STAR
1477 { $$ = newAVREF($term); }
1480 star : PERLY_STAR indirob
1481 { $$ = newGVREF(0,$indirob); }
1485 | term ARROW PERLY_SNAIL
1486 { $$ = newAVREF($term); }
1490 | term ARROW PERLY_PERCENT_SIGN
1491 { $$ = newHVREF($term); }
1495 | term ARROW PERLY_STAR
1496 { $$ = newGVREF(0,$term); }
1499 /* Indirect objects */
1501 { $$ = scalar($BAREWORD); }
1502 | scalar %prec PREC_LOW
1503 { $$ = scalar($scalar); }
1505 { $$ = op_scope($block); }
1508 { $$ = $PRIVATEREF; }