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 FINALLY
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 finally
88 %type <opval> expr term subscripted scalar ary hsh arylen star amper sideff
89 %type <opval> condition
91 %type <opval> sliceme kvslice gelem
92 %type <opval> listexpr nexpr texpr iexpr mexpr mnexpr
93 %type <opval> optlistexpr optexpr optrepl indirob listop method
94 %type <opval> formname subname proto cont my_scalar my_var
95 %type <opval> list_of_scalars my_list_of_scalars refgen_topic formblock
96 %type <opval> subattrlist myattrlist myattrterm myterm
97 %type <opval> termbinop termunop anonymous termdo
98 %type <opval> termrelop relopchain termeqop eqopchain
99 %type <ival> sigslurpsigil
100 %type <opval> sigvarname sigdefault sigscalarelem sigslurpelem
101 %type <opval> sigelem siglist optsiglist subsigguts subsignature optsubsignature
102 %type <opval> subbody optsubbody sigsubbody optsigsubbody
103 %type <opval> formstmtseq formline formarg
105 %nonassoc <ival> PREC_LOW
111 %nonassoc LSTOP LSTOPSUB
113 %right <ival> ASSIGNOP
114 %right <ival> PERLY_QUESTION_MARK PERLY_COLON
116 %left <ival> OROR DORDOR
119 %left <ival> BITANDOP
120 %left <ival> CHEQOP NCEQOP
121 %left <ival> CHRELOP NCRELOP
122 %nonassoc UNIOP UNIOPSUB
128 %right <ival> PERLY_EXCLAMATION_MARK PERLY_TILDE UMINUS REFGEN
130 %nonassoc <ival> PREINC PREDEC POSTINC POSTDEC POSTJOIN
132 %nonassoc <ival> PERLY_PAREN_CLOSE
133 %left <ival> PERLY_PAREN_OPEN
134 %left PERLY_BRACKET_OPEN PERLY_BRACE_OPEN
138 /* Top-level choice of what kind of thing yyparse was called to parse */
141 parser->expect = XSTATE;
146 newPROG(block_end($remember,$stmtseq));
147 PL_compiling.cop_seq = 0;
152 parser->expect = XTERM;
157 PL_eval_root = $optexpr;
162 parser->expect = XBLOCK;
167 PL_pad_reset_pending = TRUE;
168 PL_eval_root = $block;
171 parser->yychar = yytoken = YYEOF;
175 parser->expect = XSTATE;
180 PL_pad_reset_pending = TRUE;
181 PL_eval_root = $barestmt;
184 parser->yychar = yytoken = YYEOF;
188 parser->expect = XSTATE;
193 PL_pad_reset_pending = TRUE;
194 PL_eval_root = $fullstmt;
197 parser->yychar = yytoken = YYEOF;
201 parser->expect = XSTATE;
206 PL_eval_root = $stmtseq;
211 parser->expect = XSTATE;
216 PL_eval_root = $subsigguts;
221 /* An ordinary block */
222 block : PERLY_BRACE_OPEN remember stmtseq PERLY_BRACE_CLOSE
223 { if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
224 parser->copline = (line_t)$PERLY_BRACE_OPEN;
225 $$ = block_end($remember, $stmtseq);
230 : %empty { $$ = NULL; }
234 formblock: PERLY_EQUAL_SIGN remember PERLY_SEMICOLON FORMRBRACK formstmtseq PERLY_SEMICOLON PERLY_DOT
235 { if (parser->copline > (line_t)$PERLY_EQUAL_SIGN)
236 parser->copline = (line_t)$PERLY_EQUAL_SIGN;
237 $$ = block_end($remember, $formstmtseq);
241 remember: %empty /* start a full lexical scope */
242 { $$ = block_start(TRUE);
243 parser->parsed_sub = 0; }
246 mblock : PERLY_BRACE_OPEN mremember stmtseq PERLY_BRACE_CLOSE
247 { if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
248 parser->copline = (line_t)$PERLY_BRACE_OPEN;
249 $$ = block_end($mremember, $stmtseq);
253 mremember: %empty /* start a partial lexical scope */
254 { $$ = block_start(FALSE);
255 parser->parsed_sub = 0; }
258 /* A sequence of statements in the program */
261 | stmtseq[list] fullstmt
262 { $$ = op_append_list(OP_LINESEQ, $list, $fullstmt);
263 PL_pad_reset_pending = TRUE;
264 if ($list && $fullstmt)
265 PL_hints |= HINT_BLOCK_SCOPE;
269 /* A sequence of format lines */
272 | formstmtseq[list] formline
273 { $$ = op_append_list(OP_LINESEQ, $list, $formline);
274 PL_pad_reset_pending = TRUE;
275 if ($list && $formline)
276 PL_hints |= HINT_BLOCK_SCOPE;
280 /* A statement in the program, including optional labels */
283 $$ = $barestmt ? newSTATEOP(0, NULL, $barestmt) : NULL;
286 { $$ = $labfullstmt; }
289 labfullstmt: LABEL barestmt
291 SV *label = cSVOPx_sv($LABEL);
292 $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8,
293 savepv(SvPVX_const(label)), $barestmt);
296 | LABEL labfullstmt[list]
298 SV *label = cSVOPx_sv($LABEL);
299 $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8,
300 savepv(SvPVX_const(label)), $list);
305 /* A bare statement, lacking label and other aspects of state op */
308 | FORMAT startformsub formname formblock
310 CV *fmtcv = PL_compcv;
311 newFORM($startformsub, $formname, $formblock);
313 if (CvOUTSIDE(fmtcv) && !CvEVAL(CvOUTSIDE(fmtcv))) {
314 pad_add_weakref(fmtcv);
316 parser->parsed_sub = 1;
318 | SUB subname startsub
319 /* sub declaration or definition not within scope
320 of 'use feature "signatures"'*/
322 init_named_cv(PL_compcv, $subname);
324 parser->in_my_stash = NULL;
326 proto subattrlist optsubbody
328 SvREFCNT_inc_simple_void(PL_compcv);
329 $subname->op_type == OP_CONST
330 ? newATTRSUB($startsub, $subname, $proto, $subattrlist, $optsubbody)
331 : newMYSUB($startsub, $subname, $proto, $subattrlist, $optsubbody)
335 parser->parsed_sub = 1;
337 | SIGSUB subname startsub
338 /* sub declaration or definition under 'use feature
339 * "signatures"'. (Note that a signature isn't
340 * allowed in a declaration)
343 init_named_cv(PL_compcv, $subname);
345 parser->in_my_stash = NULL;
347 subattrlist optsigsubbody
349 SvREFCNT_inc_simple_void(PL_compcv);
350 $subname->op_type == OP_CONST
351 ? newATTRSUB($startsub, $subname, NULL, $subattrlist, $optsigsubbody)
352 : newMYSUB( $startsub, $subname, NULL, $subattrlist, $optsigsubbody)
356 parser->parsed_sub = 1;
358 | PACKAGE BAREWORD[version] BAREWORD[package] PERLY_SEMICOLON
362 package_version($version);
366 { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
367 BAREWORD[version] BAREWORD[module] optlistexpr PERLY_SEMICOLON
369 SvREFCNT_inc_simple_void(PL_compcv);
370 utilize($USE, $startsub, $version, $module, $optlistexpr);
371 parser->parsed_sub = 1;
374 | IF PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock else
376 $$ = block_end($remember,
377 newCONDOP(0, $mexpr, op_scope($mblock), $else));
378 parser->copline = (line_t)$IF;
380 | UNLESS PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock else
382 $$ = block_end($remember,
383 newCONDOP(0, $mexpr, $else, op_scope($mblock)));
384 parser->copline = (line_t)$UNLESS;
386 | GIVEN PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock
388 $$ = block_end($remember, newGIVENOP($mexpr, op_scope($mblock), 0));
389 parser->copline = (line_t)$GIVEN;
391 | WHEN PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock
392 { $$ = block_end($remember, newWHENOP($mexpr, op_scope($mblock))); }
394 { $$ = newWHENOP(0, op_scope($block)); }
395 | WHILE PERLY_PAREN_OPEN remember texpr PERLY_PAREN_CLOSE mintro mblock cont
397 $$ = block_end($remember,
398 newWHILEOP(0, 1, NULL,
399 $texpr, $mblock, $cont, $mintro));
400 parser->copline = (line_t)$WHILE;
402 | UNTIL PERLY_PAREN_OPEN remember iexpr PERLY_PAREN_CLOSE mintro mblock cont
404 $$ = block_end($remember,
405 newWHILEOP(0, 1, NULL,
406 $iexpr, $mblock, $cont, $mintro));
407 parser->copline = (line_t)$UNTIL;
409 | FOR PERLY_PAREN_OPEN remember mnexpr[init_mnexpr] PERLY_SEMICOLON
410 { parser->expect = XTERM; }
411 texpr PERLY_SEMICOLON
412 { parser->expect = XTERM; }
413 mintro mnexpr[iterate_mnexpr] PERLY_PAREN_CLOSE
416 OP *initop = $init_mnexpr;
417 OP *forop = newWHILEOP(0, 1, NULL,
418 scalar($texpr), $mblock, $iterate_mnexpr, $mintro);
420 forop = op_prepend_elem(OP_LINESEQ, initop,
421 op_append_elem(OP_LINESEQ,
422 newOP(OP_UNSTACK, OPf_SPECIAL),
425 PL_hints |= HINT_BLOCK_SCOPE;
426 $$ = block_end($remember, forop);
427 parser->copline = (line_t)$FOR;
429 | FOR MY remember my_scalar PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont
431 $$ = block_end($remember, newFOROP(0, $my_scalar, $mexpr, $mblock, $cont));
432 parser->copline = (line_t)$FOR;
434 | FOR MY remember PERLY_PAREN_OPEN my_list_of_scalars PERLY_PAREN_CLOSE PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont
436 if ($my_list_of_scalars->op_type == OP_PADSV)
437 /* degenerate case of 1 var: for my ($x) ....
438 Flag it so it can be special-cased in newFOROP */
439 $my_list_of_scalars->op_flags |= OPf_PARENS;
440 $$ = block_end($remember, newFOROP(0, $my_list_of_scalars, $mexpr, $mblock, $cont));
441 parser->copline = (line_t)$FOR;
443 | FOR scalar PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
445 $$ = block_end($remember, newFOROP(0,
446 op_lvalue($scalar, OP_ENTERLOOP), $mexpr, $mblock, $cont));
447 parser->copline = (line_t)$FOR;
449 | FOR my_refgen remember my_var
450 { parser->in_my = 0; $<opval>$ = my($my_var); }[variable]
451 PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock cont
457 newUNOP(OP_REFGEN, 0,
460 $mexpr, $mblock, $cont)
462 parser->copline = (line_t)$FOR;
464 | FOR REFGEN refgen_topic PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
466 $$ = block_end($remember, newFOROP(
467 0, op_lvalue(newUNOP(OP_REFGEN, 0,
469 OP_ENTERLOOP), $mexpr, $mblock, $cont));
470 parser->copline = (line_t)$FOR;
472 | FOR PERLY_PAREN_OPEN remember mexpr PERLY_PAREN_CLOSE mblock cont
474 $$ = block_end($remember,
475 newFOROP(0, NULL, $mexpr, $mblock, $cont));
476 parser->copline = (line_t)$FOR;
478 | TRY mblock[try] CATCH PERLY_PAREN_OPEN
479 { parser->in_my = 1; }
481 { parser->in_my = 0; intro_my(); }
482 PERLY_PAREN_CLOSE mblock[catch] finally
484 $$ = newTRYCATCHOP(0,
485 $try, $scalar, block_end($remember, op_scope($catch)));
487 $$ = op_wrap_finally($$, $finally);
488 parser->copline = (line_t)$TRY;
492 /* a block is a loop that happens once */
493 $$ = newWHILEOP(0, 1, NULL,
494 NULL, $block, $cont, 0);
496 | PACKAGE BAREWORD[version] BAREWORD[package] PERLY_BRACE_OPEN remember
500 package_version($version);
503 stmtseq PERLY_BRACE_CLOSE
505 /* a block is a loop that happens once */
506 $$ = newWHILEOP(0, 1, NULL,
507 NULL, block_end($remember, $stmtseq), NULL, 0);
508 if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
509 parser->copline = (line_t)$PERLY_BRACE_OPEN;
511 | sideff PERLY_SEMICOLON
517 $$ = newDEFEROP(0, op_scope($2));
519 | YADAYADA PERLY_SEMICOLON
521 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
522 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
527 parser->copline = NOLINE;
532 formline: THING formarg
536 list = op_append_elem(OP_LIST, $THING, term);
541 if (parser->copline == NOLINE)
542 parser->copline = CopLINE(PL_curcop)-1;
543 else parser->copline--;
544 $$ = newSTATEOP(0, NULL,
545 op_convert_list(OP_FORMLINE, 0, list));
551 | FORMLBRACK stmtseq FORMRBRACK
552 { $$ = op_unscope($stmtseq); }
558 /* An expression which may have a side-effect */
563 | expr[body] IF condition
564 { $$ = newLOGOP(OP_AND, 0, $condition, $body); }
565 | expr[body] UNLESS condition
566 { $$ = newLOGOP(OP_OR, 0, $condition, $body); }
567 | expr[body] WHILE condition
568 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($condition), $body); }
569 | expr[body] UNTIL iexpr
570 { $$ = newLOOPOP(OPf_PARENS, 1, $iexpr, $body); }
571 | expr[body] FOR condition
572 { $$ = newFOROP(0, NULL, $condition, $body, NULL);
573 parser->copline = (line_t)$FOR; }
574 | expr[body] WHEN condition
575 { $$ = newWHENOP($condition, op_scope($body)); }
578 /* else and elsif blocks */
583 ($mblock)->op_flags |= OPf_PARENS;
584 $$ = op_scope($mblock);
586 | ELSIF PERLY_PAREN_OPEN mexpr PERLY_PAREN_CLOSE mblock else[else.recurse]
587 { parser->copline = (line_t)$ELSIF;
589 newSTATEOP(OPf_SPECIAL,NULL,$mexpr),
590 op_scope($mblock), $[else.recurse]);
591 PL_hints |= HINT_BLOCK_SCOPE;
595 /* Continue blocks */
599 { $$ = op_scope($block); }
606 { $$ = op_scope($block); }
609 /* determine whether there are any new my declarations */
611 { $$ = (PL_min_intro_pending &&
612 PL_max_intro_pending >= PL_min_intro_pending);
615 /* Normal expression */
621 /* Boolean expression */
622 texpr : %empty /* NULL means true */
624 (void)scan_num("1", &tmplval);
625 $$ = tmplval.opval; }
629 /* Inverted boolean expression */
631 { $$ = invert(scalar($expr)); }
634 /* Expression with its own lexical scope */
636 { $$ = $expr; intro_my(); }
640 { $$ = $nexpr; intro_my(); }
643 formname: BAREWORD { $$ = $BAREWORD; }
647 startsub: %empty /* start a regular subroutine scope */
648 { $$ = start_subparse(FALSE, 0);
649 SAVEFREESV(PL_compcv); }
653 startanonsub: %empty /* start an anonymous subroutine scope */
654 { $$ = start_subparse(FALSE, CVf_ANON);
655 SAVEFREESV(PL_compcv); }
658 startformsub: %empty /* start a format subroutine scope */
659 { $$ = start_subparse(TRUE, 0);
660 SAVEFREESV(PL_compcv); }
663 /* Name of a subroutine - must be a bareword, could be special */
668 /* Subroutine prototype */
674 /* Optional list of subroutine attributes */
683 /* List of attributes for a "my" variable declaration */
684 myattrlist: COLONATTR THING
692 /* --------------------------------------
693 * subroutine signature parsing
696 /* the '' or 'foo' part of a '$' or '@foo' etc signature variable */
698 { parser->in_my = 0; $$ = NULL; }
700 { parser->in_my = 0; $$ = $PRIVATEREF; }
709 /* @, %, @foo, %foo */
710 sigslurpelem: sigslurpsigil sigvarname sigdefault/* def only to catch errors */
712 I32 sigil = $sigslurpsigil;
713 OP *var = $sigvarname;
714 OP *defexpr = $sigdefault;
716 if (parser->sig_slurpy)
717 yyerror("Multiple slurpy parameters not allowed");
718 parser->sig_slurpy = (char)sigil;
721 yyerror("A slurpy parameter may not have "
724 $$ = var ? newSTATEOP(0, NULL, var) : NULL;
728 /* default part of sub signature scalar element: i.e. '= default_expr' */
732 { $$ = newOP(OP_NULL, 0); }
737 /* subroutine signature scalar element: e.g. '$x', '$=', '$x = $default' */
739 PERLY_DOLLAR sigvarname sigdefault
741 OP *var = $sigvarname;
742 OP *defexpr = $sigdefault;
744 if (parser->sig_slurpy)
745 yyerror("Slurpy parameter not last");
750 parser->sig_optelems++;
752 if ( defexpr->op_type == OP_NULL
753 && !(defexpr->op_flags & OPf_KIDS))
755 /* handle '$=' special case */
757 yyerror("Optional parameter "
758 "lacks default expression");
762 /* a normal '=default' expression */
763 OP *defop = (OP*)alloc_LOGOP(OP_ARGDEFELEM,
766 /* re-purpose op_targ to hold @_ index */
768 (PADOFFSET)(parser->sig_elems - 1);
771 var->op_flags |= OPf_STACKED;
772 (void)op_sibling_splice(var,
777 var = newUNOP(OP_NULL, 0, defop);
780 /* NB: normally the first child of a
781 * logop is executed before the logop,
782 * and it pushes a boolean result
783 * ready for the logop. For ARGDEFELEM,
784 * the op itself does the boolean
785 * calculation, so set the first op to
788 var->op_next = defop;
789 defexpr->op_next = var;
793 if (parser->sig_optelems)
794 yyerror("Mandatory parameter "
795 "follows optional parameter");
798 $$ = var ? newSTATEOP(0, NULL, var) : NULL;
803 /* subroutine signature element: e.g. '$x = $default' or '%h' */
804 sigelem: sigscalarelem
805 { parser->in_my = KEY_sigvar; $$ = $sigscalarelem; }
807 { parser->in_my = KEY_sigvar; $$ = $sigslurpelem; }
810 /* list of subroutine signature elements */
812 siglist[list] PERLY_COMMA
814 | siglist[list] PERLY_COMMA sigelem[element]
816 $$ = op_append_list(OP_LINESEQ, $list, $element);
818 | sigelem[element] %prec PREC_LOW
828 /* optional subroutine signature */
834 /* Subroutine signature */
835 subsignature: PERLY_PAREN_OPEN subsigguts PERLY_PAREN_CLOSE
836 { $$ = $subsigguts; }
841 SAVEIV(parser->sig_elems);
842 SAVEIV(parser->sig_optelems);
843 SAVEI8(parser->sig_slurpy);
844 parser->sig_elems = 0;
845 parser->sig_optelems = 0;
846 parser->sig_slurpy = 0;
847 parser->in_my = KEY_sigvar;
851 OP *sigops = $optsiglist;
852 struct op_argcheck_aux *aux;
855 if (!FEATURE_SIGNATURES_IS_ENABLED)
856 Perl_croak(aTHX_ "Experimental "
857 "subroutine signatures not enabled");
859 /* We shouldn't get here otherwise */
860 aux = (struct op_argcheck_aux*)
861 PerlMemShared_malloc(
862 sizeof(struct op_argcheck_aux));
863 aux->params = parser->sig_elems;
864 aux->opt_params = parser->sig_optelems;
865 aux->slurpy = parser->sig_slurpy;
866 check = newUNOP_AUX(OP_ARGCHECK, 0, NULL,
867 (UNOP_AUX_item *)aux);
868 sigops = op_prepend_elem(OP_LINESEQ, check, sigops);
869 sigops = op_prepend_elem(OP_LINESEQ,
870 newSTATEOP(0, NULL, NULL),
872 /* a nextstate at the end handles context
873 * correctly for an empty sub body */
874 sigops = op_append_elem(OP_LINESEQ,
876 newSTATEOP(0, NULL, NULL));
877 /* wrap the list of arg ops in a NULL aux op.
878 This serves two purposes. First, it makes
879 the arg list a separate subtree from the
880 body of the sub, and secondly the null op
881 may in future be upgraded to an OP_SIGNATURE
882 when implemented. For now leave it as
884 $$ = newUNOP_AUX(OP_ARGCHECK, 0, sigops, NULL);
887 CvSIGNATURE_on(PL_compcv);
890 /* tell the toker that attrributes can follow
891 * this sig, but only so that the toker
892 * can skip through any (illegal) trailing
893 * attribute text then give a useful error
894 * message about "attributes before sig",
895 * rather than falling over ina mess at
896 * unrecognised syntax.
898 parser->expect = XATTRBLOCK;
899 parser->sig_seen = TRUE;
904 /* Optional subroutine body (for named subroutine declaration) */
907 | PERLY_SEMICOLON { $$ = NULL; }
911 /* Subroutine body (without signature) */
912 subbody: remember PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE
914 if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
915 parser->copline = (line_t)$PERLY_BRACE_OPEN;
916 $$ = block_end($remember, $stmtseq);
921 /* optional [ Subroutine body with optional signature ] (for named
922 * subroutine declaration) */
925 | PERLY_SEMICOLON { $$ = NULL; }
928 /* Subroutine body with optional signature */
929 sigsubbody: remember optsubsignature PERLY_BRACE_OPEN stmtseq PERLY_BRACE_CLOSE
931 if (parser->copline > (line_t)$PERLY_BRACE_OPEN)
932 parser->copline = (line_t)$PERLY_BRACE_OPEN;
933 $$ = block_end($remember,
934 op_append_list(OP_LINESEQ, $optsubsignature, $stmtseq));
939 /* Ordinary expressions; logical combinations */
940 expr : expr[lhs] ANDOP expr[rhs]
941 { $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); }
942 | expr[lhs] OROP[operator] expr[rhs]
943 { $$ = newLOGOP($operator, 0, $lhs, $rhs); }
944 | listexpr %prec PREC_LOW
947 /* Expressions are a list of terms joined by commas */
948 listexpr: listexpr[list] PERLY_COMMA
950 | listexpr[list] PERLY_COMMA term
953 $$ = op_append_elem(OP_LIST, $list, term);
955 | term %prec PREC_LOW
959 listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
960 { $$ = op_convert_list($LSTOP, OPf_STACKED,
961 op_prepend_elem(OP_LIST, newGVREF($LSTOP,$indirob), $listexpr) );
963 | FUNC PERLY_PAREN_OPEN indirob expr PERLY_PAREN_CLOSE /* print ($fh @args */
964 { $$ = op_convert_list($FUNC, OPf_STACKED,
965 op_prepend_elem(OP_LIST, newGVREF($FUNC,$indirob), $expr) );
967 | term ARROW method PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* $foo->bar(list) */
968 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
969 op_append_elem(OP_LIST,
970 op_prepend_elem(OP_LIST, scalar($term), $optexpr),
971 newMETHOP(OP_METHOD, 0, $method)));
973 | term ARROW method /* $foo->bar */
974 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
975 op_append_elem(OP_LIST, scalar($term),
976 newMETHOP(OP_METHOD, 0, $method)));
978 | METHOD indirob optlistexpr /* new Class @args */
979 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
980 op_append_elem(OP_LIST,
981 op_prepend_elem(OP_LIST, $indirob, $optlistexpr),
982 newMETHOP(OP_METHOD, 0, $METHOD)));
984 | FUNCMETH indirob PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* method $object (@args) */
985 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
986 op_append_elem(OP_LIST,
987 op_prepend_elem(OP_LIST, $indirob, $optexpr),
988 newMETHOP(OP_METHOD, 0, $FUNCMETH)));
990 | LSTOP optlistexpr /* print @args */
991 { $$ = op_convert_list($LSTOP, 0, $optlistexpr); }
992 | FUNC PERLY_PAREN_OPEN optexpr PERLY_PAREN_CLOSE /* print (@args) */
993 { $$ = op_convert_list($FUNC, 0, $optexpr); }
994 | FUNC SUBLEXSTART optexpr SUBLEXEND /* uc($arg) from "\U..." */
995 { $$ = op_convert_list($FUNC, 0, $optexpr); }
996 | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */
997 { SvREFCNT_inc_simple_void(PL_compcv);
998 $<opval>$ = newANONATTRSUB($startanonsub, 0, NULL, $block); }[anonattrsub]
999 optlistexpr %prec LSTOP /* ... @bar */
1000 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1001 op_append_elem(OP_LIST,
1002 op_prepend_elem(OP_LIST, $<opval>anonattrsub, $optlistexpr), $LSTOPSUB));
1006 /* Names of methods. May use $object->$methodname */
1011 /* Some kind of subscripted expression */
1012 subscripted: gelem PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* *main::{something} */
1013 /* In this and all the hash accessors, PERLY_SEMICOLON is
1014 * provided by the tokeniser */
1015 { $$ = newBINOP(OP_GELEM, 0, $gelem, scalar($expr)); }
1016 | scalar[array] PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* $array[$element] */
1017 { $$ = newBINOP(OP_AELEM, 0, oopsAV($array), scalar($expr));
1019 | term[array_reference] ARROW PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* somearef->[$element] */
1020 { $$ = newBINOP(OP_AELEM, 0,
1021 ref(newAVREF($array_reference),OP_RV2AV),
1024 | subscripted[array_reference] PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* $foo->[$bar]->[$baz] */
1025 { $$ = newBINOP(OP_AELEM, 0,
1026 ref(newAVREF($array_reference),OP_RV2AV),
1029 | scalar[hash] PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* $foo{bar();} */
1030 { $$ = newBINOP(OP_HELEM, 0, oopsHV($hash), jmaybe($expr));
1032 | term[hash_reference] ARROW PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* somehref->{bar();} */
1033 { $$ = newBINOP(OP_HELEM, 0,
1034 ref(newHVREF($hash_reference),OP_RV2HV),
1036 | subscripted[hash_reference] PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* $foo->[bar]->{baz;} */
1037 { $$ = newBINOP(OP_HELEM, 0,
1038 ref(newHVREF($hash_reference),OP_RV2HV),
1040 | term[code_reference] ARROW PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* $subref->() */
1041 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1042 newCVREF(0, scalar($code_reference)));
1043 if (parser->expect == XBLOCK)
1044 parser->expect = XOPERATOR;
1046 | term[code_reference] ARROW PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* $subref->(@args) */
1047 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1048 op_append_elem(OP_LIST, $expr,
1049 newCVREF(0, scalar($code_reference))));
1050 if (parser->expect == XBLOCK)
1051 parser->expect = XOPERATOR;
1054 | subscripted[code_reference] PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* $foo->{bar}->(@args) */
1055 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1056 op_append_elem(OP_LIST, $expr,
1057 newCVREF(0, scalar($code_reference))));
1058 if (parser->expect == XBLOCK)
1059 parser->expect = XOPERATOR;
1061 | subscripted[code_reference] PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* $foo->{bar}->() */
1062 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1063 newCVREF(0, scalar($code_reference)));
1064 if (parser->expect == XBLOCK)
1065 parser->expect = XOPERATOR;
1067 | PERLY_PAREN_OPEN expr[list] PERLY_PAREN_CLOSE PERLY_BRACKET_OPEN expr[slice] PERLY_BRACKET_CLOSE /* list slice */
1068 { $$ = newSLICEOP(0, $slice, $list); }
1069 | QWLIST PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* list literal slice */
1070 { $$ = newSLICEOP(0, $expr, $QWLIST); }
1071 | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* empty list slice! */
1072 { $$ = newSLICEOP(0, $expr, NULL); }
1075 /* Binary operators between terms */
1076 termbinop: term[lhs] ASSIGNOP term[rhs] /* $x = $y, $x += $y */
1077 { $$ = newASSIGNOP(OPf_STACKED, $lhs, $ASSIGNOP, $rhs); }
1078 | term[lhs] POWOP term[rhs] /* $x ** $y */
1079 { $$ = newBINOP($POWOP, 0, scalar($lhs), scalar($rhs)); }
1080 | term[lhs] MULOP term[rhs] /* $x * $y, $x x $y */
1081 { if ($MULOP != OP_REPEAT)
1083 $$ = newBINOP($MULOP, 0, $lhs, scalar($rhs));
1085 | term[lhs] ADDOP term[rhs] /* $x + $y */
1086 { $$ = newBINOP($ADDOP, 0, scalar($lhs), scalar($rhs)); }
1087 | term[lhs] SHIFTOP term[rhs] /* $x >> $y, $x << $y */
1088 { $$ = newBINOP($SHIFTOP, 0, scalar($lhs), scalar($rhs)); }
1089 | termrelop %prec PREC_LOW /* $x > $y, etc. */
1090 { $$ = $termrelop; }
1091 | termeqop %prec PREC_LOW /* $x == $y, $x cmp $y */
1093 | term[lhs] BITANDOP term[rhs] /* $x & $y */
1094 { $$ = newBINOP($BITANDOP, 0, scalar($lhs), scalar($rhs)); }
1095 | term[lhs] BITOROP term[rhs] /* $x | $y */
1096 { $$ = newBINOP($BITOROP, 0, scalar($lhs), scalar($rhs)); }
1097 | term[lhs] DOTDOT term[rhs] /* $x..$y, $x...$y */
1098 { $$ = newRANGE($DOTDOT, scalar($lhs), scalar($rhs)); }
1099 | term[lhs] ANDAND term[rhs] /* $x && $y */
1100 { $$ = newLOGOP(OP_AND, 0, $lhs, $rhs); }
1101 | term[lhs] OROR term[rhs] /* $x || $y */
1102 { $$ = newLOGOP(OP_OR, 0, $lhs, $rhs); }
1103 | term[lhs] DORDOR term[rhs] /* $x // $y */
1104 { $$ = newLOGOP(OP_DOR, 0, $lhs, $rhs); }
1105 | term[lhs] MATCHOP term[rhs] /* $x =~ /$y/ */
1106 { $$ = bind_match($MATCHOP, $lhs, $rhs); }
1109 termrelop: relopchain %prec PREC_LOW
1110 { $$ = cmpchain_finish($relopchain); }
1111 | term[lhs] NCRELOP term[rhs]
1112 { $$ = newBINOP($NCRELOP, 0, scalar($lhs), scalar($rhs)); }
1114 { yyerror("syntax error"); YYERROR; }
1116 { yyerror("syntax error"); YYERROR; }
1119 relopchain: term[lhs] CHRELOP term[rhs]
1120 { $$ = cmpchain_start($CHRELOP, $lhs, $rhs); }
1121 | relopchain[lhs] CHRELOP term[rhs]
1122 { $$ = cmpchain_extend($CHRELOP, $lhs, $rhs); }
1125 termeqop: eqopchain %prec PREC_LOW
1126 { $$ = cmpchain_finish($eqopchain); }
1127 | term[lhs] NCEQOP term[rhs]
1128 { $$ = newBINOP($NCEQOP, 0, scalar($lhs), scalar($rhs)); }
1130 { yyerror("syntax error"); YYERROR; }
1132 { yyerror("syntax error"); YYERROR; }
1135 eqopchain: term[lhs] CHEQOP term[rhs]
1136 { $$ = cmpchain_start($CHEQOP, $lhs, $rhs); }
1137 | eqopchain[lhs] CHEQOP term[rhs]
1138 { $$ = cmpchain_extend($CHEQOP, $lhs, $rhs); }
1141 /* Unary operators and terms */
1142 termunop : PERLY_MINUS term %prec UMINUS /* -$x */
1143 { $$ = newUNOP(OP_NEGATE, 0, scalar($term)); }
1144 | PERLY_PLUS term %prec UMINUS /* +$x */
1147 | PERLY_EXCLAMATION_MARK term /* !$x */
1148 { $$ = newUNOP(OP_NOT, 0, scalar($term)); }
1149 | PERLY_TILDE term /* ~$x */
1150 { $$ = newUNOP($PERLY_TILDE, 0, scalar($term)); }
1151 | term POSTINC /* $x++ */
1152 { $$ = newUNOP(OP_POSTINC, 0,
1153 op_lvalue(scalar($term), OP_POSTINC)); }
1154 | term POSTDEC /* $x-- */
1155 { $$ = newUNOP(OP_POSTDEC, 0,
1156 op_lvalue(scalar($term), OP_POSTDEC));}
1157 | term POSTJOIN /* implicit join after interpolated ->@ */
1158 { $$ = op_convert_list(OP_JOIN, 0,
1168 | PREINC term /* ++$x */
1169 { $$ = newUNOP(OP_PREINC, 0,
1170 op_lvalue(scalar($term), OP_PREINC)); }
1171 | PREDEC term /* --$x */
1172 { $$ = newUNOP(OP_PREDEC, 0,
1173 op_lvalue(scalar($term), OP_PREDEC)); }
1177 /* Constructors for anonymous data */
1179 : PERLY_BRACKET_OPEN optexpr PERLY_BRACKET_CLOSE
1180 { $$ = newANONLIST($optexpr); }
1181 | HASHBRACK optexpr PERLY_SEMICOLON PERLY_BRACE_CLOSE %prec PERLY_PAREN_OPEN /* { foo => "Bar" } */
1182 { $$ = newANONHASH($optexpr); }
1183 | ANONSUB startanonsub proto subattrlist subbody %prec PERLY_PAREN_OPEN
1184 { SvREFCNT_inc_simple_void(PL_compcv);
1185 $$ = newANONATTRSUB($startanonsub, $proto, $subattrlist, $subbody); }
1186 | ANON_SIGSUB startanonsub subattrlist sigsubbody %prec PERLY_PAREN_OPEN
1187 { SvREFCNT_inc_simple_void(PL_compcv);
1188 $$ = newANONATTRSUB($startanonsub, NULL, $subattrlist, $sigsubbody); }
1191 /* Things called with "do" */
1192 termdo : DO term %prec UNIOP /* do $filename */
1193 { $$ = dofile($term, $DO);}
1194 | DO block %prec PERLY_PAREN_OPEN /* do { code */
1195 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($block));}
1198 term[product] : termbinop
1202 | term[condition] PERLY_QUESTION_MARK term[then] PERLY_COLON term[else]
1203 { $$ = newCONDOP(0, $condition, $then, $else); }
1204 | REFGEN term[operand] /* \$x, \@y, \%z */
1205 { $$ = newUNOP(OP_REFGEN, 0, $operand); }
1206 | myattrterm %prec UNIOP
1207 { $$ = $myattrterm; }
1208 | LOCAL term[operand] %prec UNIOP
1209 { $$ = localize($operand,0); }
1210 | PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE
1211 { $$ = sawparens($expr); }
1214 | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1215 { $$ = sawparens(newNULLLIST()); }
1216 | scalar %prec PERLY_PAREN_OPEN
1218 | star %prec PERLY_PAREN_OPEN
1220 | hsh %prec PERLY_PAREN_OPEN
1222 | ary %prec PERLY_PAREN_OPEN
1224 | arylen %prec PERLY_PAREN_OPEN /* $#x, $#{ something } */
1225 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($arylen, OP_AV2ARYLEN));}
1227 { $$ = $subscripted; }
1228 | sliceme PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* array slice */
1229 { $$ = op_prepend_elem(OP_ASLICE,
1230 newOP(OP_PUSHMARK, 0),
1231 newLISTOP(OP_ASLICE, 0,
1233 ref($sliceme, OP_ASLICE)));
1236 $sliceme->op_private & OPpSLICEWARNING;
1238 | kvslice PERLY_BRACKET_OPEN expr PERLY_BRACKET_CLOSE /* array key/value slice */
1239 { $$ = op_prepend_elem(OP_KVASLICE,
1240 newOP(OP_PUSHMARK, 0),
1241 newLISTOP(OP_KVASLICE, 0,
1243 ref(oopsAV($kvslice), OP_KVASLICE)));
1246 $kvslice->op_private & OPpSLICEWARNING;
1248 | sliceme PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* @hash{@keys} */
1249 { $$ = op_prepend_elem(OP_HSLICE,
1250 newOP(OP_PUSHMARK, 0),
1251 newLISTOP(OP_HSLICE, 0,
1253 ref(oopsHV($sliceme), OP_HSLICE)));
1256 $sliceme->op_private & OPpSLICEWARNING;
1258 | kvslice PERLY_BRACE_OPEN expr PERLY_SEMICOLON PERLY_BRACE_CLOSE /* %hash{@keys} */
1259 { $$ = op_prepend_elem(OP_KVHSLICE,
1260 newOP(OP_PUSHMARK, 0),
1261 newLISTOP(OP_KVHSLICE, 0,
1263 ref($kvslice, OP_KVHSLICE)));
1266 $kvslice->op_private & OPpSLICEWARNING;
1268 | THING %prec PERLY_PAREN_OPEN
1271 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($amper)); }
1272 | amper PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* &foo() or foo() */
1273 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($amper));
1275 | amper PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* &foo(@args) or foo(@args) */
1277 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1278 op_append_elem(OP_LIST, $expr, scalar($amper)));
1280 | NOAMP subname optlistexpr /* foo @args (no parens) */
1281 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1282 op_append_elem(OP_LIST, $optlistexpr, scalar($subname)));
1284 | term[operand] ARROW PERLY_DOLLAR PERLY_STAR
1285 { $$ = newSVREF($operand); }
1286 | term[operand] ARROW PERLY_SNAIL PERLY_STAR
1287 { $$ = newAVREF($operand); }
1288 | term[operand] ARROW PERLY_PERCENT_SIGN PERLY_STAR
1289 { $$ = newHVREF($operand); }
1290 | term[operand] ARROW PERLY_AMPERSAND PERLY_STAR
1291 { $$ = newUNOP(OP_ENTERSUB, 0,
1292 scalar(newCVREF($PERLY_AMPERSAND,$operand))); }
1293 | term[operand] ARROW PERLY_STAR PERLY_STAR %prec PERLY_PAREN_OPEN
1294 { $$ = newGVREF(0,$operand); }
1295 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
1296 { $$ = newOP($LOOPEX, OPf_SPECIAL);
1297 PL_hints |= HINT_BLOCK_SCOPE; }
1298 | LOOPEX term[operand]
1299 { $$ = newLOOPEX($LOOPEX,$operand); }
1300 | NOTOP listexpr /* not $foo */
1301 { $$ = newUNOP(OP_NOT, 0, scalar($listexpr)); }
1302 | UNIOP /* Unary op, $_ implied */
1303 { $$ = newOP($UNIOP, 0); }
1304 | UNIOP block /* eval { foo }* */
1305 { $$ = newUNOP($UNIOP, 0, $block); }
1306 | UNIOP term[operand] /* Unary op */
1307 { $$ = newUNOP($UNIOP, 0, $operand); }
1308 | REQUIRE /* require, $_ implied */
1309 { $$ = newOP(OP_REQUIRE, $REQUIRE ? OPf_SPECIAL : 0); }
1310 | REQUIRE term[operand] /* require Foo */
1311 { $$ = newUNOP(OP_REQUIRE, $REQUIRE ? OPf_SPECIAL : 0, $operand); }
1313 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($UNIOPSUB)); }
1314 | UNIOPSUB term[operand] /* Sub treated as unop */
1315 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1316 op_append_elem(OP_LIST, $operand, scalar($UNIOPSUB))); }
1317 | FUNC0 /* Nullary operator */
1318 { $$ = newOP($FUNC0, 0); }
1319 | FUNC0 PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1320 { $$ = newOP($FUNC0, 0);}
1321 | FUNC0OP /* Same as above, but op created in toke.c */
1323 | FUNC0OP PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1325 | FUNC0SUB /* Sub treated as nullop */
1326 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($FUNC0SUB)); }
1327 | FUNC1 PERLY_PAREN_OPEN PERLY_PAREN_CLOSE /* not () */
1328 { $$ = ($FUNC1 == OP_NOT)
1329 ? newUNOP($FUNC1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
1330 : newOP($FUNC1, OPf_SPECIAL); }
1331 | FUNC1 PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE /* not($foo) */
1332 { $$ = newUNOP($FUNC1, 0, $expr); }
1333 | PMFUNC /* m//, s///, qr//, tr/// */
1335 if ( $PMFUNC->op_type != OP_TRANS
1336 && $PMFUNC->op_type != OP_TRANSR
1337 && (((PMOP*)$PMFUNC)->op_pmflags & PMf_HAS_CV))
1339 $<ival>$ = start_subparse(FALSE, CVf_ANON);
1340 SAVEFREESV(PL_compcv);
1344 SUBLEXSTART listexpr optrepl SUBLEXEND
1345 { $$ = pmruntime($PMFUNC, $listexpr, $optrepl, 1, $<ival>2); }
1351 /* "my" declarations, with optional attributes */
1353 : MY myterm myattrlist
1354 { $$ = my_attrs($myterm,$myattrlist); }
1356 { $$ = localize($myterm,1); }
1357 | MY REFGEN myterm myattrlist
1358 { $$ = newUNOP(OP_REFGEN, 0, my_attrs($myterm,$myattrlist)); }
1359 | MY REFGEN term[operand]
1360 { $$ = newUNOP(OP_REFGEN, 0, localize($operand,1)); }
1363 /* Things that can be "my"'d */
1364 myterm : PERLY_PAREN_OPEN expr PERLY_PAREN_CLOSE
1365 { $$ = sawparens($expr); }
1366 | PERLY_PAREN_OPEN PERLY_PAREN_CLOSE
1367 { $$ = sawparens(newNULLLIST()); }
1369 | scalar %prec PERLY_PAREN_OPEN
1371 | hsh %prec PERLY_PAREN_OPEN
1373 | ary %prec PERLY_PAREN_OPEN
1377 /* Basic list expressions */
1379 : empty %prec PREC_LOW
1380 | listexpr %prec PREC_LOW
1390 | PERLY_SLASH expr { $$ = $expr; }
1393 /* A little bit of trickery to make "for my $foo (@bar)" actually be
1396 { parser->in_my = 0; $$ = my($scalar); }
1399 /* A list of scalars for "for my ($foo, $bar) (@baz)" */
1400 list_of_scalars: list_of_scalars[list] PERLY_COMMA
1402 | list_of_scalars[list] PERLY_COMMA scalar
1404 $$ = op_append_elem(OP_LIST, $list, $scalar);
1406 | scalar %prec PREC_LOW
1409 my_list_of_scalars: list_of_scalars
1410 { parser->in_my = 0; $$ = $list_of_scalars; }
1418 refgen_topic: my_var
1422 my_refgen: MY REFGEN
1426 amper : PERLY_AMPERSAND indirob
1427 { $$ = newCVREF($PERLY_AMPERSAND,$indirob); }
1430 scalar : PERLY_DOLLAR indirob
1431 { $$ = newSVREF($indirob); }
1434 ary : PERLY_SNAIL indirob
1435 { $$ = newAVREF($indirob);
1436 if ($$) $$->op_private |= $PERLY_SNAIL;
1440 hsh : PERLY_PERCENT_SIGN indirob
1441 { $$ = newHVREF($indirob);
1442 if ($$) $$->op_private |= $PERLY_PERCENT_SIGN;
1446 arylen : DOLSHARP indirob
1447 { $$ = newAVREF($indirob); }
1448 | term ARROW DOLSHARP PERLY_STAR
1449 { $$ = newAVREF($term); }
1452 star : PERLY_STAR indirob
1453 { $$ = newGVREF(0,$indirob); }
1457 | term ARROW PERLY_SNAIL
1458 { $$ = newAVREF($term); }
1462 | term ARROW PERLY_PERCENT_SIGN
1463 { $$ = newHVREF($term); }
1467 | term ARROW PERLY_STAR
1468 { $$ = newGVREF(0,$term); }
1471 /* Indirect objects */
1473 { $$ = scalar($BAREWORD); }
1474 | scalar %prec PREC_LOW
1475 { $$ = scalar($scalar); }
1477 { $$ = op_scope($block); }
1480 { $$ = $PRIVATEREF; }