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> POWOP MULOP ADDOP
90 %token <ival> DOLSHARP HASHBRACK NOAMP
91 %token <ival> COLONATTR FORMLBRACK FORMRBRACK
92 %token <ival> SUBLEXSTART SUBLEXEND
94 /* Pluggable infix operators */
95 %token <pval> PLUGLOWOP PLUGRELOP PLUGADDOP PLUGMULOP PLUGPOWOP PLUGHIGHOP
97 %type <ival> grammar remember mremember
98 %type <ival> startsub startanonsub startformsub
102 %type <opval> stmtseq fullstmt labfullstmt barestmt block mblock else finally
103 %type <opval> expr term subscripted scalar ary hsh arylen star amper sideff
104 %type <opval> condition
105 %type <opval> catch_paren
107 %type <opval> sliceme kvslice gelem
108 %type <opval> listexpr nexpr texpr iexpr mexpr mnexpr
109 %type <opval> optlistexpr optexpr optrepl indirob listop methodname
110 %type <opval> formname subname proto cont my_scalar my_var
111 %type <opval> list_of_scalars my_list_of_scalars refgen_topic formblock
112 %type <opval> subattrlist myattrlist myattrterm myterm
113 %type <opval> termbinop termunop anonymous termdo
114 %type <opval> termrelop relopchain termeqop eqopchain
115 %type <ival> sigslurpsigil
116 %type <opval> sigvarname sigdefault sigscalarelem sigslurpelem
117 %type <opval> sigelem siglist optsiglist subsigguts subsignature optsubsignature
118 %type <opval> subbody optsubbody sigsubbody optsigsubbody
119 %type <opval> formstmtseq formline formarg
121 %nonassoc <ival> PREC_LOW
128 %nonassoc LSTOP LSTOPSUB
130 %right <ival> ASSIGNOP
131 %right <ival> PERLY_QUESTION_MARK PERLY_COLON
133 %left <ival> OROR DORDOR
136 %left <ival> BITANDOP
137 %left <ival> CHEQOP NCEQOP
138 %left <ival> CHRELOP NCRELOP
140 %nonassoc UNIOP UNIOPSUB
143 %left ADDOP PLUGADDOP
144 %left MULOP PLUGMULOP
146 %right <ival> PERLY_EXCLAMATION_MARK PERLY_TILDE UMINUS REFGEN
147 %right POWOP PLUGPOWOP
148 %nonassoc <ival> PREINC PREDEC POSTINC POSTDEC POSTJOIN
151 %nonassoc <ival> PERLY_PAREN_CLOSE
152 %left <ival> PERLY_PAREN_OPEN
153 %left PERLY_BRACKET_OPEN PERLY_BRACE_OPEN
157 /* Top-level choice of what kind of thing yyparse was called to parse */
160 parser->expect = XSTATE;
165 newPROG(block_end($remember,$stmtseq));
166 PL_compiling.cop_seq = 0;
171 parser->expect = XTERM;
176 PL_eval_root = $optexpr;
181 parser->expect = XBLOCK;
186 PL_pad_reset_pending = TRUE;
187 PL_eval_root = $block;
190 parser->yychar = yytoken = YYEOF;
194 parser->expect = XSTATE;
199 PL_pad_reset_pending = TRUE;
200 PL_eval_root = $barestmt;
203 parser->yychar = yytoken = YYEOF;
207 parser->expect = XSTATE;
212 PL_pad_reset_pending = TRUE;
213 PL_eval_root = $fullstmt;
216 parser->yychar = yytoken = YYEOF;
220 parser->expect = XSTATE;
225 PL_eval_root = $stmtseq;
230 parser->expect = XSTATE;
235 PL_eval_root = $subsigguts;
240 /* An ordinary block */
241 block : PERLY_BRACE_OPEN remember stmtseq PERLY_BRACE_CLOSE
242 { if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
243 parser->copline = (line_t)$PERLY_BRACE_OPEN;
244 $$ = block_end($remember, $stmtseq);
249 : %empty { $$ = NULL; }
253 formblock: PERLY_EQUAL_SIGN remember PERLY_SEMICOLON FORMRBRACK formstmtseq PERLY_SEMICOLON PERLY_DOT
254 { if (parser->copline > (line_t)$PERLY_EQUAL_SIGN)
255 parser->copline = (line_t)$PERLY_EQUAL_SIGN;
256 $$ = block_end($remember, $formstmtseq);
260 remember: %empty /* start a full lexical scope */
261 { $$ = block_start(TRUE);
262 parser->parsed_sub = 0; }
265 mblock : PERLY_BRACE_OPEN mremember stmtseq PERLY_BRACE_CLOSE
266 { if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
267 parser->copline = (line_t)$PERLY_BRACE_OPEN;
268 $$ = block_end($mremember, $stmtseq);
272 mremember: %empty /* start a partial lexical scope */
273 { $$ = block_start(FALSE);
274 parser->parsed_sub = 0; }
277 /* The parenthesized variable of a catch block */
279 /* not really valid grammar but we detect it in the
280 * action block to throw a nicer error message */
282 { parser->in_my = 1; }
284 { parser->in_my = 0; intro_my(); }
289 /* A sequence of statements in the program */
292 | stmtseq[list] fullstmt
293 { $$ = op_append_list(OP_LINESEQ, $list, $fullstmt);
294 PL_pad_reset_pending = TRUE;
295 if ($list && $fullstmt)
296 PL_hints |= HINT_BLOCK_SCOPE;
300 /* A sequence of format lines */
303 | formstmtseq[list] formline
304 { $$ = op_append_list(OP_LINESEQ, $list, $formline);
305 PL_pad_reset_pending = TRUE;
306 if ($list && $formline)
307 PL_hints |= HINT_BLOCK_SCOPE;
311 /* A statement in the program, including optional labels */
314 $$ = $barestmt ? newSTATEOP(0, NULL, $barestmt) : NULL;
317 { $$ = $labfullstmt; }
320 labfullstmt: LABEL barestmt
322 SV *label = cSVOPx_sv($LABEL);
323 $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8,
324 savepv(SvPVX_const(label)), $barestmt);
327 | LABEL labfullstmt[list]
329 SV *label = cSVOPx_sv($LABEL);
330 $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8,
331 savepv(SvPVX_const(label)), $list);
336 /* A bare statement, lacking label and other aspects of state op */
339 | KW_FORMAT startformsub formname formblock
341 CV *fmtcv = PL_compcv;
342 newFORM($startformsub, $formname, $formblock);
344 if (CvOUTSIDE(fmtcv) && !CvEVAL(CvOUTSIDE(fmtcv))) {
345 pad_add_weakref(fmtcv);
347 parser->parsed_sub = 1;
349 | KW_SUB_named subname startsub
350 /* sub declaration or definition not within scope
351 of 'use feature "signatures"'*/
353 init_named_cv(PL_compcv, $subname);
355 parser->in_my_stash = NULL;
357 proto subattrlist optsubbody
359 SvREFCNT_inc_simple_void(PL_compcv);
360 $subname->op_type == OP_CONST
361 ? newATTRSUB($startsub, $subname, $proto, $subattrlist, $optsubbody)
362 : newMYSUB($startsub, $subname, $proto, $subattrlist, $optsubbody)
366 parser->parsed_sub = 1;
368 | KW_SUB_named_sig subname startsub
369 /* sub declaration or definition under 'use feature
370 * "signatures"'. (Note that a signature isn't
371 * allowed in a declaration)
374 init_named_cv(PL_compcv, $subname);
376 parser->in_my_stash = NULL;
378 subattrlist optsigsubbody
380 SvREFCNT_inc_simple_void(PL_compcv);
381 $subname->op_type == OP_CONST
382 ? newATTRSUB($startsub, $subname, NULL, $subattrlist, $optsigsubbody)
383 : newMYSUB( $startsub, $subname, NULL, $subattrlist, $optsigsubbody)
387 parser->parsed_sub = 1;
389 | KW_PACKAGE BAREWORD[version] BAREWORD[package] PERLY_SEMICOLON
390 /* version and package appear in the reverse order to what may be
391 * expected, because toke.c has already pushed both of them to a stack
392 * by calling force_next() from within force_version().
393 * When the parser pops them back out again they appear swapped */
397 package_version($version);
400 | KW_USE_or_NO startsub
401 { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
402 BAREWORD[version] BAREWORD[module] optlistexpr PERLY_SEMICOLON
403 /* version and package appear in reverse order for the same reason as
404 * KW_PACKAGE; see comment above */
406 SvREFCNT_inc_simple_void(PL_compcv);
407 utilize($KW_USE_or_NO, $startsub, $version, $module, $optlistexpr);
408 parser->parsed_sub = 1;
411 | KW_IF PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock else
413 $$ = block_end($remember,
414 newCONDOP(0, $mexpr, op_scope($mblock), $else));
415 parser->copline = (line_t)$KW_IF;
417 | KW_UNLESS PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock else
419 $$ = block_end($remember,
420 newCONDOP(0, $mexpr, $else, op_scope($mblock)));
421 parser->copline = (line_t)$KW_UNLESS;
423 | KW_GIVEN PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock
425 $$ = block_end($remember, newGIVENOP($mexpr, op_scope($mblock), 0));
426 parser->copline = (line_t)$KW_GIVEN;
428 | KW_WHEN PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock
429 { $$ = block_end($remember, newWHENOP($mexpr, op_scope($mblock))); }
431 { $$ = newWHENOP(0, op_scope($block)); }
432 | KW_WHILE PERLY_PAREN_OPEN remember texpr PERLY_PAREN_CLOSE mintro mblock cont
434 $$ = block_end($remember,
435 newWHILEOP(0, 1, NULL,
436 $texpr, $mblock, $cont, $mintro));
437 parser->copline = (line_t)$KW_WHILE;
439 | KW_UNTIL PERLY_PAREN_OPEN remember iexpr PERLY_PAREN_CLOSE mintro mblock cont
441 $$ = block_end($remember,
442 newWHILEOP(0, 1, NULL,
443 $iexpr, $mblock, $cont, $mintro));
444 parser->copline = (line_t)$KW_UNTIL;
446 | KW_FOR PERLY_PAREN_OPEN remember mnexpr[init_mnexpr] PERLY_SEMICOLON
447 { parser->expect = XTERM; }
448 texpr PERLY_SEMICOLON
449 { parser->expect = XTERM; }
450 mintro mnexpr[iterate_mnexpr] PERLY_PAREN_CLOSE
453 OP *initop = $init_mnexpr;
454 OP *forop = newWHILEOP(0, 1, NULL,
455 scalar($texpr), $mblock, $iterate_mnexpr, $mintro);
457 forop = op_prepend_elem(OP_LINESEQ, initop,
458 op_append_elem(OP_LINESEQ,
459 newOP(OP_UNSTACK, OPf_SPECIAL),
462 PL_hints |= HINT_BLOCK_SCOPE;
463 $$ = block_end($remember, forop);
464 parser->copline = (line_t)$KW_FOR;
466 | KW_FOR KW_MY remember my_scalar PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont
468 $$ = block_end($remember, newFOROP(0, $my_scalar, $mexpr, $mblock, $cont));
469 parser->copline = (line_t)$KW_FOR;
471 | KW_FOR KW_MY remember PERLY_PAREN_OPEN my_list_of_scalars PERLY_PAREN_CLOSE PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont
473 if ($my_list_of_scalars->op_type == OP_PADSV)
474 /* degenerate case of 1 var: for my ($x) ....
475 Flag it so it can be special-cased in newFOROP */
476 $my_list_of_scalars->op_flags |= OPf_PARENS;
477 $$ = block_end($remember, newFOROP(0, $my_list_of_scalars, $mexpr, $mblock, $cont));
478 parser->copline = (line_t)$KW_FOR;
480 | KW_FOR scalar PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
482 $$ = block_end($remember, newFOROP(0,
483 op_lvalue($scalar, OP_ENTERLOOP), $mexpr, $mblock, $cont));
484 parser->copline = (line_t)$KW_FOR;
486 | KW_FOR my_refgen remember my_var
487 { parser->in_my = 0; $<opval>$ = my($my_var); }[variable]
488 PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont
494 newUNOP(OP_REFGEN, 0,
497 $mexpr, $mblock, $cont)
499 parser->copline = (line_t)$KW_FOR;
501 | KW_FOR REFGEN refgen_topic PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
503 $$ = block_end($remember, newFOROP(
504 0, op_lvalue(newUNOP(OP_REFGEN, 0,
506 OP_ENTERLOOP), $mexpr, $mblock, $cont));
507 parser->copline = (line_t)$KW_FOR;
509 | KW_FOR PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
511 $$ = block_end($remember,
512 newFOROP(0, NULL, $mexpr, $mblock, $cont));
513 parser->copline = (line_t)$KW_FOR;
515 | KW_TRY mblock[try] KW_CATCH remember catch_paren[scalar]
518 yyerror("catch block requires a (VAR)");
522 mblock[catch] finally
524 $$ = newTRYCATCHOP(0,
525 $try, $scalar, block_end($remember, op_scope($catch)));
527 $$ = op_wrap_finally($$, $finally);
528 parser->copline = (line_t)$KW_TRY;
532 /* a block is a loop that happens once */
533 $$ = newWHILEOP(0, 1, NULL,
534 NULL, $block, $cont, 0);
536 | KW_PACKAGE BAREWORD[version] BAREWORD[package] PERLY_BRACE_OPEN remember
540 package_version($version);
543 stmtseq PERLY_BRACE_CLOSE
545 /* a block is a loop that happens once */
546 $$ = newWHILEOP(0, 1, NULL,
547 NULL, block_end($remember, $stmtseq), NULL, 0);
548 if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
549 parser->copline = (line_t)$PERLY_BRACE_OPEN;
551 | sideff PERLY_SEMICOLON
557 $$ = newDEFEROP(0, op_scope($2));
559 | YADAYADA PERLY_SEMICOLON
561 /* diag_listed_as: Unimplemented */
562 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
563 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
568 parser->copline = NOLINE;
573 formline: THING formarg
577 list = op_append_elem(OP_LIST, $THING, term);
582 if (parser->copline == NOLINE)
583 parser->copline = CopLINE(PL_curcop)-1;
584 else parser->copline--;
585 $$ = newSTATEOP(0, NULL,
586 op_convert_list(OP_FORMLINE, 0, list));
592 | FORMLBRACK stmtseq FORMRBRACK
593 { $$ = op_unscope($stmtseq); }
599 /* An expression which may have a side-effect */
604 | expr[body] KW_IF condition
605 { $$ = newLOGOP(OP_AND, 0, $condition, $body); }
606 | expr[body] KW_UNLESS condition
607 { $$ = newLOGOP(OP_OR, 0, $condition, $body); }
608 | expr[body] KW_WHILE condition
609 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($condition), $body); }
610 | expr[body] KW_UNTIL iexpr
611 { $$ = newLOOPOP(OPf_PARENS, 1, $iexpr, $body); }
612 | expr[body] KW_FOR condition
613 { $$ = newFOROP(0, NULL, $condition, $body, NULL);
614 parser->copline = (line_t)$KW_FOR; }
615 | expr[body] KW_WHEN condition
616 { $$ = newWHENOP($condition, op_scope($body)); }
619 /* else and elsif blocks */
624 ($mblock)->op_flags |= OPf_PARENS;
625 $$ = op_scope($mblock);
627 | KW_ELSIF PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock else[else.recurse]
628 { parser->copline = (line_t)$KW_ELSIF;
630 newSTATEOP(OPf_SPECIAL,NULL,$mexpr),
631 op_scope($mblock), $[else.recurse]);
632 PL_hints |= HINT_BLOCK_SCOPE;
636 /* Continue blocks */
640 { $$ = op_scope($block); }
647 { $$ = op_scope($block); }
650 /* determine whether there are any new my declarations */
652 { $$ = (PL_min_intro_pending &&
653 PL_max_intro_pending >= PL_min_intro_pending);
656 /* Normal expression */
662 /* Boolean expression */
663 texpr : %empty /* NULL means true */
665 (void)scan_num("1", &tmplval);
666 $$ = tmplval.opval; }
670 /* Inverted boolean expression */
672 { $$ = invert(scalar($expr)); }
675 /* Expression with its own lexical scope */
677 { $$ = $expr; intro_my(); }
681 { $$ = $nexpr; intro_my(); }
684 formname: BAREWORD { $$ = $BAREWORD; }
688 startsub: %empty /* start a regular subroutine scope */
689 { $$ = start_subparse(FALSE, 0);
690 SAVEFREESV(PL_compcv); }
694 startanonsub: %empty /* start an anonymous subroutine scope */
695 { $$ = start_subparse(FALSE, CVf_ANON);
696 SAVEFREESV(PL_compcv); }
699 startformsub: %empty /* start a format subroutine scope */
700 { $$ = start_subparse(TRUE, 0);
701 SAVEFREESV(PL_compcv); }
704 /* Name of a subroutine - must be a bareword, could be special */
709 /* Subroutine prototype */
715 /* Optional list of subroutine attributes */
720 OP *attrlist = $THING;
721 if(attrlist && !PL_parser->sig_seen)
722 attrlist = apply_builtin_cv_attributes(PL_compcv, attrlist);
729 /* List of attributes for a "my" variable declaration */
730 myattrlist: COLONATTR THING
738 /* --------------------------------------
739 * subroutine signature parsing
742 /* the '' or 'foo' part of a '$' or '@foo' etc signature variable */
744 { parser->in_my = 0; $$ = NULL; }
746 { parser->in_my = 0; $$ = $PRIVATEREF; }
755 /* @, %, @foo, %foo */
756 sigslurpelem: sigslurpsigil sigvarname sigdefault/* def only to catch errors */
758 I32 sigil = $sigslurpsigil;
759 OP *var = $sigvarname;
760 OP *defop = $sigdefault;
762 if (parser->sig_slurpy)
763 yyerror("Multiple slurpy parameters not allowed");
764 parser->sig_slurpy = (char)sigil;
767 yyerror("A slurpy parameter may not have "
770 $$ = var ? newSTATEOP(0, NULL, var) : NULL;
774 /* default part of sub signature scalar element: i.e. '= default_expr' */
778 { $$ = newARGDEFELEMOP(0, newOP(OP_NULL, 0), parser->sig_elems); }
782 if ($ASSIGNOP == OP_DORASSIGN)
783 flags |= OPpARG_IF_UNDEF << 8;
784 if ($ASSIGNOP == OP_ORASSIGN)
785 flags |= OPpARG_IF_FALSE << 8;
786 $$ = newARGDEFELEMOP(flags, $term, parser->sig_elems);
790 /* subroutine signature scalar element: e.g. '$x', '$=', '$x = $default' */
792 PERLY_DOLLAR sigvarname sigdefault
794 OP *var = $sigvarname;
795 OP *defop = $sigdefault;
797 if (parser->sig_slurpy)
798 yyerror("Slurpy parameter not last");
803 parser->sig_optelems++;
805 OP *defexpr = cLOGOPx(defop)->op_first;
807 if ( defexpr->op_type == OP_NULL
808 && !(defexpr->op_flags & OPf_KIDS))
810 /* handle '$=' special case */
812 yyerror("Optional parameter "
813 "lacks default expression");
817 /* a normal '=default' expression */
819 var->op_flags |= OPf_STACKED;
820 (void)op_sibling_splice(var,
825 var = newUNOP(OP_NULL, 0, defop);
828 /* NB: normally the first child of a
829 * logop is executed before the logop,
830 * and it pushes a boolean result
831 * ready for the logop. For ARGDEFELEM,
832 * the op itself does the boolean
833 * calculation, so set the first op to
836 var->op_next = defop;
837 defexpr->op_next = var;
841 if (parser->sig_optelems)
842 yyerror("Mandatory parameter "
843 "follows optional parameter");
846 $$ = var ? newSTATEOP(0, NULL, var) : NULL;
851 /* subroutine signature element: e.g. '$x = $default' or '%h' */
852 sigelem: sigscalarelem
853 { parser->in_my = KEY_sigvar; $$ = $sigscalarelem; }
855 { parser->in_my = KEY_sigvar; $$ = $sigslurpelem; }
858 /* list of subroutine signature elements */
860 siglist[list] PERLY_COMMA
862 | siglist[list] PERLY_COMMA sigelem[element]
864 $$ = op_append_list(OP_LINESEQ, $list, $element);
866 | sigelem[element] %prec PREC_LOW
876 /* optional subroutine signature */
882 /* Subroutine signature */
883 subsignature: PERLY_PAREN_OPEN subsigguts PERLY_PAREN_CLOSE
884 { $$ = $subsigguts; }
889 SAVEIV(parser->sig_elems);
890 SAVEIV(parser->sig_optelems);
891 SAVEI8(parser->sig_slurpy);
892 parser->sig_elems = 0;
893 parser->sig_optelems = 0;
894 parser->sig_slurpy = 0;
895 parser->in_my = KEY_sigvar;
899 OP *sigops = $optsiglist;
900 struct op_argcheck_aux *aux;
903 if (!FEATURE_SIGNATURES_IS_ENABLED)
904 Perl_croak(aTHX_ "Experimental "
905 "subroutine signatures not enabled");
907 /* We shouldn't get here otherwise */
908 aux = (struct op_argcheck_aux*)
909 PerlMemShared_malloc(
910 sizeof(struct op_argcheck_aux));
911 aux->params = parser->sig_elems;
912 aux->opt_params = parser->sig_optelems;
913 aux->slurpy = parser->sig_slurpy;
914 check = newUNOP_AUX(OP_ARGCHECK, 0, NULL,
915 (UNOP_AUX_item *)aux);
916 sigops = op_prepend_elem(OP_LINESEQ, check, sigops);
917 sigops = op_prepend_elem(OP_LINESEQ,
918 newSTATEOP(0, NULL, NULL),
920 /* a nextstate at the end handles context
921 * correctly for an empty sub body */
922 sigops = op_append_elem(OP_LINESEQ,
924 newSTATEOP(0, NULL, NULL));
925 /* wrap the list of arg ops in a NULL aux op.
926 This serves two purposes. First, it makes
927 the arg list a separate subtree from the
928 body of the sub, and secondly the null op
929 may in future be upgraded to an OP_SIGNATURE
930 when implemented. For now leave it as
932 $$ = newUNOP_AUX(OP_ARGCHECK, 0, sigops, NULL);
935 CvSIGNATURE_on(PL_compcv);
938 /* tell the toker that attrributes can follow
939 * this sig, but only so that the toker
940 * can skip through any (illegal) trailing
941 * attribute text then give a useful error
942 * message about "attributes before sig",
943 * rather than falling over ina mess at
944 * unrecognised syntax.
946 parser->expect = XATTRBLOCK;
947 parser->sig_seen = TRUE;
952 /* Optional subroutine body (for named subroutine declaration) */
955 | PERLY_SEMICOLON { $$ = NULL; }
959 /* Subroutine body (without signature) */
960 subbody: remember PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE
962 if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
963 parser->copline = (line_t)$PERLY_BRACE_OPEN;
964 $$ = block_end($remember, $stmtseq);
969 /* optional [ Subroutine body with optional signature ] (for named
970 * subroutine declaration) */
973 | PERLY_SEMICOLON { $$ = NULL; }
976 /* Subroutine body with optional signature */
977 sigsubbody: remember optsubsignature PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE
979 if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
980 parser->copline = (line_t)$PERLY_BRACE_OPEN;
981 $$ = block_end($remember,
982 op_append_list(OP_LINESEQ, $optsubsignature, $stmtseq));
987 /* Ordinary expressions; logical combinations */
988 expr : expr[lhs] ANDOP expr[rhs]
989 { $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); }
990 | expr[lhs] OROP[operator] expr[rhs]
991 { $$ = newLOGOP($operator, 0, $lhs, $rhs); }
992 | listexpr %prec PREC_LOW
995 /* Expressions are a list of terms joined by commas */
996 listexpr: listexpr[list] PERLY_COMMA
998 | listexpr[list] PERLY_COMMA term
1001 $$ = op_append_elem(OP_LIST, $list, term);
1003 | term %prec PREC_LOW
1006 /* List operators */
1007 listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
1008 { $$ = op_convert_list($LSTOP, OPf_STACKED,
1009 op_prepend_elem(OP_LIST, newGVREF($LSTOP,$indirob), $listexpr) );
1011 | FUNC PERLY_PAREN_OPEN indirob expr PERLY_PAREN_CLOSE /* print ($fh @args */
1012 { $$ = op_convert_list($FUNC, OPf_STACKED,
1013 op_prepend_elem(OP_LIST, newGVREF($FUNC,$indirob), $expr) );
1015 | term ARROW methodname PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* $foo->bar(list) */
1016 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
1017 op_append_elem(OP_LIST,
1018 op_prepend_elem(OP_LIST, scalar($term), $optexpr),
1019 newMETHOP(OP_METHOD, 0, $methodname)));
1021 | term ARROW methodname /* $foo->bar */
1022 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
1023 op_append_elem(OP_LIST, scalar($term),
1024 newMETHOP(OP_METHOD, 0, $methodname)));
1026 | METHCALL0 indirob optlistexpr /* new Class @args */
1027 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
1028 op_append_elem(OP_LIST,
1029 op_prepend_elem(OP_LIST, $indirob, $optlistexpr),
1030 newMETHOP(OP_METHOD, 0, $METHCALL0)));
1032 | METHCALL indirob PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* method $object (@args) */
1033 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
1034 op_append_elem(OP_LIST,
1035 op_prepend_elem(OP_LIST, $indirob, $optexpr),
1036 newMETHOP(OP_METHOD, 0, $METHCALL)));
1038 | LSTOP optlistexpr /* print @args */
1039 { $$ = op_convert_list($LSTOP, 0, $optlistexpr); }
1040 | FUNC PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* print (@args) */
1041 { $$ = op_convert_list($FUNC, 0, $optexpr); }
1042 | FUNC SUBLEXSTART optexpr SUBLEXEND /* uc($arg) from "\U..." */
1043 { $$ = op_convert_list($FUNC, 0, $optexpr); }
1044 | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */
1045 { SvREFCNT_inc_simple_void(PL_compcv);
1046 $<opval>$ = newANONATTRSUB($startanonsub, 0, NULL, $block); }[anonattrsub]
1047 optlistexpr %prec LSTOP /* ... @bar */
1048 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1049 op_append_elem(OP_LIST,
1050 op_prepend_elem(OP_LIST, $<opval>anonattrsub, $optlistexpr), $LSTOPSUB));
1054 /* Names of methods. May use $object->$methodname */
1055 methodname: METHCALL0
1059 /* Some kind of subscripted expression */
1060 subscripted: gelem PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* *main::{something} */
1061 /* In this and all the hash accessors, PERLY_SEMICOLON is
1062 * provided by the tokeniser */
1063 { $$ = newBINOP(OP_GELEM, 0, $gelem, scalar($expr)); }
1064 | scalar[array] PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* $array[$element] */
1065 { $$ = newBINOP(OP_AELEM, 0, oopsAV($array), scalar($expr));
1067 | term[array_reference] ARROW PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* somearef->[$element] */
1068 { $$ = newBINOP(OP_AELEM, 0,
1069 ref(newAVREF($array_reference),OP_RV2AV),
1072 | subscripted[array_reference] PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* $foo->[$bar]->[$baz] */
1073 { $$ = newBINOP(OP_AELEM, 0,
1074 ref(newAVREF($array_reference),OP_RV2AV),
1077 | scalar[hash] PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* $foo{bar();} */
1078 { $$ = newBINOP(OP_HELEM, 0, oopsHV($hash), jmaybe($expr));
1080 | term[hash_reference] ARROW PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* somehref->{bar();} */
1081 { $$ = newBINOP(OP_HELEM, 0,
1082 ref(newHVREF($hash_reference),OP_RV2HV),
1084 | subscripted[hash_reference] PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* $foo->[bar]->{baz;} */
1085 { $$ = newBINOP(OP_HELEM, 0,
1086 ref(newHVREF($hash_reference),OP_RV2HV),
1088 | term[code_reference] ARROW PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* $subref->() */
1089 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1090 newCVREF(0, scalar($code_reference)));
1091 if (parser->expect == XBLOCK)
1092 parser->expect = XOPERATOR;
1094 | term[code_reference] ARROW PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* $subref->(@args) */
1095 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1096 op_append_elem(OP_LIST, $expr,
1097 newCVREF(0, scalar($code_reference))));
1098 if (parser->expect == XBLOCK)
1099 parser->expect = XOPERATOR;
1102 | subscripted[code_reference] PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* $foo->{bar}->(@args) */
1103 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1104 op_append_elem(OP_LIST, $expr,
1105 newCVREF(0, scalar($code_reference))));
1106 if (parser->expect == XBLOCK)
1107 parser->expect = XOPERATOR;
1109 | subscripted[code_reference] PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* $foo->{bar}->() */
1110 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1111 newCVREF(0, scalar($code_reference)));
1112 if (parser->expect == XBLOCK)
1113 parser->expect = XOPERATOR;
1115 | PERLY_PAREN_OPEN expr[list] PERLY_PAREN_CLOSE PERLY_BRACKET_OPEN expr[slice] PERLY_BRACKET_CLOSE /* list slice */
1116 { $$ = newSLICEOP(0, $slice, $list); }
1117 | QWLIST PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* list literal slice */
1118 { $$ = newSLICEOP(0, $expr, $QWLIST); }
1119 | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* empty list slice! */
1120 { $$ = newSLICEOP(0, $expr, NULL); }
1123 /* Binary operators between terms */
1124 termbinop: term[lhs] PLUGHIGHOP[op] term[rhs]
1125 { $$ = build_infix_plugin($lhs, $rhs, $op); }
1126 | term[lhs] ASSIGNOP term[rhs] /* $x = $y, $x += $y */
1127 { $$ = newASSIGNOP(OPf_STACKED, $lhs, $ASSIGNOP, $rhs); }
1128 | term[lhs] POWOP term[rhs] /* $x ** $y */
1129 { $$ = newBINOP($POWOP, 0, scalar($lhs), scalar($rhs)); }
1130 | term[lhs] PLUGPOWOP[op] term[rhs]
1131 { $$ = build_infix_plugin($lhs, $rhs, $op); }
1132 | term[lhs] MULOP term[rhs] /* $x * $y, $x x $y */
1133 { if ($MULOP != OP_REPEAT)
1135 $$ = newBINOP($MULOP, 0, $lhs, scalar($rhs));
1137 | term[lhs] PLUGMULOP[op] term[rhs]
1138 { $$ = build_infix_plugin($lhs, $rhs, $op); }
1139 | term[lhs] ADDOP term[rhs] /* $x + $y */
1140 { $$ = newBINOP($ADDOP, 0, scalar($lhs), scalar($rhs)); }
1141 | term[lhs] PLUGADDOP[op] term[rhs]
1142 { $$ = build_infix_plugin($lhs, $rhs, $op); }
1143 | term[lhs] SHIFTOP term[rhs] /* $x >> $y, $x << $y */
1144 { $$ = newBINOP($SHIFTOP, 0, scalar($lhs), scalar($rhs)); }
1145 | termrelop %prec PREC_LOW /* $x > $y, etc. */
1146 { $$ = $termrelop; }
1147 | termeqop %prec PREC_LOW /* $x == $y, $x cmp $y */
1149 | term[lhs] BITANDOP term[rhs] /* $x & $y */
1150 { $$ = newBINOP($BITANDOP, 0, scalar($lhs), scalar($rhs)); }
1151 | term[lhs] BITOROP term[rhs] /* $x | $y */
1152 { $$ = newBINOP($BITOROP, 0, scalar($lhs), scalar($rhs)); }
1153 | term[lhs] DOTDOT term[rhs] /* $x..$y, $x...$y */
1154 { $$ = newRANGE($DOTDOT, scalar($lhs), scalar($rhs)); }
1155 | term[lhs] ANDAND term[rhs] /* $x && $y */
1156 { $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); }
1157 | term[lhs] OROR term[rhs] /* $x || $y */
1158 { $$ = newLOGOP(OP_OR, 0, $lhs, $rhs); }
1159 | term[lhs] DORDOR term[rhs] /* $x // $y */
1160 { $$ = newLOGOP(OP_DOR, 0, $lhs, $rhs); }
1161 | term[lhs] MATCHOP term[rhs] /* $x =~ /$y/ */
1162 { $$ = bind_match($MATCHOP, $lhs, $rhs); }
1163 | term[lhs] PLUGLOWOP[op] term[rhs]
1164 { $$ = build_infix_plugin($lhs, $rhs, $op); }
1167 termrelop: relopchain %prec PREC_LOW
1168 { $$ = cmpchain_finish($relopchain); }
1169 | term[lhs] NCRELOP term[rhs]
1170 { $$ = newBINOP($NCRELOP, 0, scalar($lhs), scalar($rhs)); }
1172 { yyerror("syntax error"); YYERROR; }
1174 { yyerror("syntax error"); YYERROR; }
1175 | term[lhs] PLUGRELOP[op] term[rhs]
1176 { $$ = build_infix_plugin($lhs, $rhs, $op); }
1179 relopchain: term[lhs] CHRELOP term[rhs]
1180 { $$ = cmpchain_start($CHRELOP, $lhs, $rhs); }
1181 | relopchain[lhs] CHRELOP term[rhs]
1182 { $$ = cmpchain_extend($CHRELOP, $lhs, $rhs); }
1185 termeqop: eqopchain %prec PREC_LOW
1186 { $$ = cmpchain_finish($eqopchain); }
1187 | term[lhs] NCEQOP term[rhs]
1188 { $$ = newBINOP($NCEQOP, 0, scalar($lhs), scalar($rhs)); }
1190 { yyerror("syntax error"); YYERROR; }
1192 { yyerror("syntax error"); YYERROR; }
1195 eqopchain: term[lhs] CHEQOP term[rhs]
1196 { $$ = cmpchain_start($CHEQOP, $lhs, $rhs); }
1197 | eqopchain[lhs] CHEQOP term[rhs]
1198 { $$ = cmpchain_extend($CHEQOP, $lhs, $rhs); }
1201 /* Unary operators and terms */
1202 termunop : PERLY_MINUS term %prec UMINUS /* -$x */
1203 { $$ = newUNOP(OP_NEGATE, 0, scalar($term)); }
1204 | PERLY_PLUS term %prec UMINUS /* +$x */
1207 | PERLY_EXCLAMATION_MARK term /* !$x */
1208 { $$ = newUNOP(OP_NOT, 0, scalar($term)); }
1209 | PERLY_TILDE term /* ~$x */
1210 { $$ = newUNOP($PERLY_TILDE, 0, scalar($term)); }
1211 | term POSTINC /* $x++ */
1212 { $$ = newUNOP(OP_POSTINC, 0,
1213 op_lvalue(scalar($term), OP_POSTINC)); }
1214 | term POSTDEC /* $x-- */
1215 { $$ = newUNOP(OP_POSTDEC, 0,
1216 op_lvalue(scalar($term), OP_POSTDEC));}
1217 | term POSTJOIN /* implicit join after interpolated ->@ */
1218 { $$ = op_convert_list(OP_JOIN, 0,
1228 | PREINC term /* ++$x */
1229 { $$ = newUNOP(OP_PREINC, 0,
1230 op_lvalue(scalar($term), OP_PREINC)); }
1231 | PREDEC term /* --$x */
1232 { $$ = newUNOP(OP_PREDEC, 0,
1233 op_lvalue(scalar($term), OP_PREDEC)); }
1237 /* Constructors for anonymous data */
1239 : PERLY_BRACKET_OPEN optexpr PERLY_BRACKET_CLOSE
1240 { $$ = newANONLIST($optexpr); }
1241 | HASHBRACK optexpr PERLY_SEMICOLON PERLY_BRACE_CLOSE %prec PERLY_PAREN_OPEN /* { foo => "Bar" } */
1242 { $$ = newANONHASH($optexpr); }
1243 | KW_SUB_anon startanonsub proto subattrlist subbody %prec PERLY_PAREN_OPEN
1244 { SvREFCNT_inc_simple_void(PL_compcv);
1245 $$ = newANONATTRSUB($startanonsub, $proto, $subattrlist, $subbody); }
1246 | KW_SUB_anon_sig startanonsub subattrlist sigsubbody %prec PERLY_PAREN_OPEN
1247 { SvREFCNT_inc_simple_void(PL_compcv);
1248 $$ = newANONATTRSUB($startanonsub, NULL, $subattrlist, $sigsubbody); }
1251 /* Things called with "do" */
1252 termdo : KW_DO term %prec UNIOP /* do $filename */
1253 { $$ = dofile($term, $KW_DO);}
1254 | KW_DO block %prec PERLY_PAREN_OPEN /* do { code */
1255 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($block));}
1258 term[product] : termbinop
1262 | term[condition] PERLY_QUESTION_MARK term[then] PERLY_COLON term[else]
1263 { $$ = newCONDOP(0, $condition, $then, $else); }
1264 | REFGEN term[operand] /* \$x, \@y, \%z */
1265 { $$ = newUNOP(OP_REFGEN, 0, $operand); }
1266 | myattrterm %prec UNIOP
1267 { $$ = $myattrterm; }
1268 | KW_LOCAL term[operand] %prec UNIOP
1269 { $$ = localize($operand,0); }
1270 | PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE
1271 { $$ = sawparens($expr); }
1274 | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1275 { $$ = sawparens(newNULLLIST()); }
1276 | scalar %prec PERLY_PAREN_OPEN
1278 | star %prec PERLY_PAREN_OPEN
1280 | hsh %prec PERLY_PAREN_OPEN
1282 | ary %prec PERLY_PAREN_OPEN
1284 | arylen %prec PERLY_PAREN_OPEN /* $#x, $#{ something } */
1285 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($arylen, OP_AV2ARYLEN));}
1287 { $$ = $subscripted; }
1288 | sliceme PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* array slice */
1289 { $$ = op_prepend_elem(OP_ASLICE,
1290 newOP(OP_PUSHMARK, 0),
1291 newLISTOP(OP_ASLICE, 0,
1293 ref($sliceme, OP_ASLICE)));
1296 $sliceme->op_private & OPpSLICEWARNING;
1298 | kvslice PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* array key/value slice */
1299 { $$ = op_prepend_elem(OP_KVASLICE,
1300 newOP(OP_PUSHMARK, 0),
1301 newLISTOP(OP_KVASLICE, 0,
1303 ref(oopsAV($kvslice), OP_KVASLICE)));
1306 $kvslice->op_private & OPpSLICEWARNING;
1308 | sliceme PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* @hash{@keys} */
1309 { $$ = op_prepend_elem(OP_HSLICE,
1310 newOP(OP_PUSHMARK, 0),
1311 newLISTOP(OP_HSLICE, 0,
1313 ref(oopsHV($sliceme), OP_HSLICE)));
1316 $sliceme->op_private & OPpSLICEWARNING;
1318 | kvslice PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* %hash{@keys} */
1319 { $$ = op_prepend_elem(OP_KVHSLICE,
1320 newOP(OP_PUSHMARK, 0),
1321 newLISTOP(OP_KVHSLICE, 0,
1323 ref($kvslice, OP_KVHSLICE)));
1326 $kvslice->op_private & OPpSLICEWARNING;
1328 | THING %prec PERLY_PAREN_OPEN
1331 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($amper)); }
1332 | amper PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* &foo() or foo() */
1333 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($amper));
1335 | amper PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* &foo(@args) or foo(@args) */
1337 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1338 op_append_elem(OP_LIST, $expr, scalar($amper)));
1340 | NOAMP subname optlistexpr /* foo @args (no parens) */
1341 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1342 op_append_elem(OP_LIST, $optlistexpr, scalar($subname)));
1344 | term[operand] ARROW PERLY_DOLLAR PERLY_STAR
1345 { $$ = newSVREF($operand); }
1346 | term[operand] ARROW PERLY_SNAIL PERLY_STAR
1347 { $$ = newAVREF($operand); }
1348 | term[operand] ARROW PERLY_PERCENT_SIGN PERLY_STAR
1349 { $$ = newHVREF($operand); }
1350 | term[operand] ARROW PERLY_AMPERSAND PERLY_STAR
1351 { $$ = newUNOP(OP_ENTERSUB, 0,
1352 scalar(newCVREF($PERLY_AMPERSAND,$operand))); }
1353 | term[operand] ARROW PERLY_STAR PERLY_STAR %prec PERLY_PAREN_OPEN
1354 { $$ = newGVREF(0,$operand); }
1355 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
1356 { $$ = newOP($LOOPEX, OPf_SPECIAL);
1357 PL_hints |= HINT_BLOCK_SCOPE; }
1358 | LOOPEX term[operand]
1359 { $$ = newLOOPEX($LOOPEX,$operand); }
1360 | NOTOP listexpr /* not $foo */
1361 { $$ = newUNOP(OP_NOT, 0, scalar($listexpr)); }
1362 | UNIOP /* Unary op, $_ implied */
1363 { $$ = newOP($UNIOP, 0); }
1364 | UNIOP block /* eval { foo }* */
1365 { $$ = newUNOP($UNIOP, 0, $block); }
1366 | UNIOP term[operand] /* Unary op */
1367 { $$ = newUNOP($UNIOP, 0, $operand); }
1368 | KW_REQUIRE /* require, $_ implied */
1369 { $$ = newOP(OP_REQUIRE, $KW_REQUIRE ? OPf_SPECIAL : 0); }
1370 | KW_REQUIRE term[operand] /* require Foo */
1371 { $$ = newUNOP(OP_REQUIRE, $KW_REQUIRE ? OPf_SPECIAL : 0, $operand); }
1373 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($UNIOPSUB)); }
1374 | UNIOPSUB term[operand] /* Sub treated as unop */
1375 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1376 op_append_elem(OP_LIST, $operand, scalar($UNIOPSUB))); }
1377 | FUNC0 /* Nullary operator */
1378 { $$ = newOP($FUNC0, 0); }
1379 | FUNC0 PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1380 { $$ = newOP($FUNC0, 0);}
1381 | FUNC0OP /* Same as above, but op created in toke.c */
1383 | FUNC0OP PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1385 | FUNC0SUB /* Sub treated as nullop */
1386 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($FUNC0SUB)); }
1387 | FUNC1 PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* not () */
1388 { $$ = ($FUNC1 == OP_NOT)
1389 ? newUNOP($FUNC1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
1390 : newOP($FUNC1, OPf_SPECIAL); }
1391 | FUNC1 PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* not($foo) */
1392 { $$ = newUNOP($FUNC1, 0, $expr); }
1393 | PMFUNC /* m//, s///, qr//, tr/// */
1395 if ( $PMFUNC->op_type != OP_TRANS
1396 && $PMFUNC->op_type != OP_TRANSR
1397 && (((PMOP*)$PMFUNC)->op_pmflags & PMf_HAS_CV))
1399 $<ival>$ = start_subparse(FALSE, CVf_ANON);
1400 SAVEFREESV(PL_compcv);
1404 SUBLEXSTART listexpr optrepl SUBLEXEND
1405 { $$ = pmruntime($PMFUNC, $listexpr, $optrepl, 1, $<ival>2); }
1411 /* "my" declarations, with optional attributes */
1413 : KW_MY myterm myattrlist
1414 { $$ = my_attrs($myterm,$myattrlist); }
1416 { $$ = localize($myterm,1); }
1417 | KW_MY REFGEN myterm myattrlist
1418 { $$ = newUNOP(OP_REFGEN, 0, my_attrs($myterm,$myattrlist)); }
1419 | KW_MY REFGEN term[operand]
1420 { $$ = newUNOP(OP_REFGEN, 0, localize($operand,1)); }
1423 /* Things that can be "my"'d */
1424 myterm : PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE
1425 { $$ = sawparens($expr); }
1426 | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1427 { $$ = sawparens(newNULLLIST()); }
1429 | scalar %prec PERLY_PAREN_OPEN
1431 | hsh %prec PERLY_PAREN_OPEN
1433 | ary %prec PERLY_PAREN_OPEN
1437 /* Basic list expressions */
1439 : empty %prec PREC_LOW
1440 | listexpr %prec PREC_LOW
1450 | PERLY_SLASH expr { $$ = $expr; }
1453 /* A little bit of trickery to make "for my $foo (@bar)" actually be
1456 { parser->in_my = 0; $$ = my($scalar); }
1459 /* A list of scalars for "for my ($foo, $bar) (@baz)" */
1460 list_of_scalars: list_of_scalars[list] PERLY_COMMA
1462 | list_of_scalars[list] PERLY_COMMA scalar
1464 $$ = op_append_elem(OP_LIST, $list, $scalar);
1466 | scalar %prec PREC_LOW
1469 my_list_of_scalars: list_of_scalars
1470 { parser->in_my = 0; $$ = $list_of_scalars; }
1478 refgen_topic: my_var
1482 my_refgen: KW_MY REFGEN
1486 amper : PERLY_AMPERSAND indirob
1487 { $$ = newCVREF($PERLY_AMPERSAND,$indirob); }
1490 scalar : PERLY_DOLLAR indirob
1491 { $$ = newSVREF($indirob); }
1494 ary : PERLY_SNAIL indirob
1495 { $$ = newAVREF($indirob);
1496 if ($$) $$->op_private |= $PERLY_SNAIL;
1500 hsh : PERLY_PERCENT_SIGN indirob
1501 { $$ = newHVREF($indirob);
1502 if ($$) $$->op_private |= $PERLY_PERCENT_SIGN;
1506 arylen : DOLSHARP indirob
1507 { $$ = newAVREF($indirob); }
1508 | term ARROW DOLSHARP PERLY_STAR
1509 { $$ = newAVREF($term); }
1512 star : PERLY_STAR indirob
1513 { $$ = newGVREF(0,$indirob); }
1517 | term ARROW PERLY_SNAIL
1518 { $$ = newAVREF($term); }
1522 | term ARROW PERLY_PERCENT_SIGN
1523 { $$ = newHVREF($term); }
1527 | term ARROW PERLY_STAR
1528 { $$ = newGVREF(0,$term); }
1531 /* Indirect objects */
1533 { $$ = scalar($BAREWORD); }
1534 | scalar %prec PREC_LOW
1535 { $$ = scalar($scalar); }
1537 { $$ = op_scope($block); }
1540 { $$ = $PRIVATEREF; }