This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make op_free() non-recursive
[perl5.git] / perly.y
1 /*    perly.y
2  *
3  *    Copyright (c) 1991-2002, 2003, 2004, 2005, 2006 Larry Wall
4  *    Copyright (c) 2007, 2008, 2009, 2010, 2011 by Larry Wall and others
5  *
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.
8  *
9  */
10
11 /*
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.'
14  *
15  *     [p.171 of _The Lord of the Rings_, I/x: "Strider"]
16  */
17
18 /*
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.
22  *
23  * The main job of 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.
26  *
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
29  * an action.
30  */
31
32 /*  Make the parser re-entrant. */
33
34 %pure-parser
35
36 %start grammar
37
38 %union {
39     I32 ival; /* __DEFAULT__ (marker for regen_perly.pl;
40                                 must always be 1st union member) */
41     char *pval;
42     OP *opval;
43     GV *gvval;
44 }
45
46 %token <ival> GRAMPROG GRAMEXPR GRAMBLOCK GRAMBARESTMT GRAMFULLSTMT GRAMSTMTSEQ
47
48 %token <ival> '{' '}' '[' ']' '-' '+' '@' '%' '&' '=' '.'
49
50 %token <opval> BAREWORD METHOD FUNCMETH THING PMFUNC PRIVATEREF QWLIST
51 %token <opval> FUNC0OP FUNC0SUB UNIOPSUB LSTOPSUB
52 %token <opval> PLUGEXPR PLUGSTMT
53 %token <opval> LABEL
54 %token <ival> FORMAT SUB SIGSUB ANONSUB ANON_SIGSUB PACKAGE USE
55 %token <ival> WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE FOR
56 %token <ival> GIVEN WHEN DEFAULT
57 %token <ival> LOOPEX DOTDOT YADAYADA
58 %token <ival> FUNC0 FUNC1 FUNC UNIOP LSTOP
59 %token <ival> RELOP EQOP MULOP ADDOP
60 %token <ival> DOLSHARP DO HASHBRACK NOAMP
61 %token <ival> LOCAL MY REQUIRE
62 %token <ival> COLONATTR FORMLBRACK FORMRBRACK
63 %token <ival> SUBLEXSTART SUBLEXEND
64
65 %type <ival> grammar remember mremember
66 %type <ival>  startsub startanonsub startformsub
67
68 %type <ival> mintro
69
70 %type <opval> stmtseq fullstmt labfullstmt barestmt block mblock else
71 %type <opval> expr term subscripted scalar ary hsh arylen star amper sideff
72 %type <opval> sliceme kvslice gelem
73 %type <opval> listexpr nexpr texpr iexpr mexpr mnexpr
74 %type <opval> optlistexpr optexpr optrepl indirob listop method
75 %type <opval> formname subname proto cont my_scalar my_var
76 %type <opval> refgen_topic formblock
77 %type <opval> subattrlist myattrlist myattrterm myterm
78 %type <opval> termbinop termunop anonymous termdo
79 %type <ival>  sigslurpsigil
80 %type <opval> sigvarname sigdefault sigscalarelem sigslurpelem
81 %type <opval> sigelem siglist siglistornull subsignature optsubsignature
82 %type <opval> subbody optsubbody sigsubbody optsigsubbody
83 %type <opval> formstmtseq formline formarg
84
85 %nonassoc <ival> PREC_LOW
86 %nonassoc LOOPEX
87
88 %left <ival> OROP DOROP
89 %left <ival> ANDOP
90 %right <ival> NOTOP
91 %nonassoc LSTOP LSTOPSUB
92 %left <ival> ','
93 %right <ival> ASSIGNOP
94 %right <ival> '?' ':'
95 %nonassoc DOTDOT
96 %left <ival> OROR DORDOR
97 %left <ival> ANDAND
98 %left <ival> BITOROP
99 %left <ival> BITANDOP
100 %nonassoc EQOP
101 %nonassoc RELOP
102 %nonassoc UNIOP UNIOPSUB
103 %nonassoc REQUIRE
104 %left <ival> SHIFTOP
105 %left ADDOP
106 %left MULOP
107 %left <ival> MATCHOP
108 %right <ival> '!' '~' UMINUS REFGEN
109 %right <ival> POWOP
110 %nonassoc <ival> PREINC PREDEC POSTINC POSTDEC POSTJOIN
111 %left <ival> ARROW
112 %nonassoc <ival> ')'
113 %left <ival> '('
114 %left '[' '{'
115
116 %% /* RULES */
117
118 /* Top-level choice of what kind of thing yyparse was called to parse */
119 grammar :       GRAMPROG
120                         {
121                           parser->expect = XSTATE;
122                           $<ival>$ = 0;
123                         }
124                 remember stmtseq
125                         {
126                           newPROG(block_end($3,$4));
127                           PL_compiling.cop_seq = 0;
128                           $$ = 0;
129                         }
130         |       GRAMEXPR
131                         {
132                           parser->expect = XTERM;
133                           $<ival>$ = 0;
134                         }
135                 optexpr
136                         {
137                           PL_eval_root = $3;
138                           $$ = 0;
139                         }
140         |       GRAMBLOCK
141                         {
142                           parser->expect = XBLOCK;
143                           $<ival>$ = 0;
144                         }
145                 block
146                         {
147                           PL_pad_reset_pending = TRUE;
148                           PL_eval_root = $3;
149                           $$ = 0;
150                           yyunlex();
151                           parser->yychar = yytoken = YYEOF;
152                         }
153         |       GRAMBARESTMT
154                         {
155                           parser->expect = XSTATE;
156                           $<ival>$ = 0;
157                         }
158                 barestmt
159                         {
160                           PL_pad_reset_pending = TRUE;
161                           PL_eval_root = $3;
162                           $$ = 0;
163                           yyunlex();
164                           parser->yychar = yytoken = YYEOF;
165                         }
166         |       GRAMFULLSTMT
167                         {
168                           parser->expect = XSTATE;
169                           $<ival>$ = 0;
170                         }
171                 fullstmt
172                         {
173                           PL_pad_reset_pending = TRUE;
174                           PL_eval_root = $3;
175                           $$ = 0;
176                           yyunlex();
177                           parser->yychar = yytoken = YYEOF;
178                         }
179         |       GRAMSTMTSEQ
180                         {
181                           parser->expect = XSTATE;
182                           $<ival>$ = 0;
183                         }
184                 stmtseq
185                         {
186                           PL_eval_root = $3;
187                           $$ = 0;
188                         }
189         ;
190
191 /* An ordinary block */
192 block   :       '{' remember stmtseq '}'
193                         { if (parser->copline > (line_t)$1)
194                               parser->copline = (line_t)$1;
195                           $$ = block_end($2, $3);
196                         }
197         ;
198
199 /* format body */
200 formblock:      '=' remember ';' FORMRBRACK formstmtseq ';' '.'
201                         { if (parser->copline > (line_t)$1)
202                               parser->copline = (line_t)$1;
203                           $$ = block_end($2, $5);
204                         }
205         ;
206
207 remember:       /* NULL */      /* start a full lexical scope */
208                         { $$ = block_start(TRUE);
209                           parser->parsed_sub = 0; }
210         ;
211
212 mblock  :       '{' mremember stmtseq '}'
213                         { if (parser->copline > (line_t)$1)
214                               parser->copline = (line_t)$1;
215                           $$ = block_end($2, $3);
216                         }
217         ;
218
219 mremember:      /* NULL */      /* start a partial lexical scope */
220                         { $$ = block_start(FALSE);
221                           parser->parsed_sub = 0; }
222         ;
223
224 /* A sequence of statements in the program */
225 stmtseq :       /* NULL */
226                         { $$ = NULL; }
227         |       stmtseq fullstmt
228                         {   $$ = op_append_list(OP_LINESEQ, $1, $2);
229                             PL_pad_reset_pending = TRUE;
230                             if ($1 && $2)
231                                 PL_hints |= HINT_BLOCK_SCOPE;
232                         }
233         ;
234
235 /* A sequence of format lines */
236 formstmtseq:    /* NULL */
237                         { $$ = NULL; }
238         |       formstmtseq formline
239                         {   $$ = op_append_list(OP_LINESEQ, $1, $2);
240                             PL_pad_reset_pending = TRUE;
241                             if ($1 && $2)
242                                 PL_hints |= HINT_BLOCK_SCOPE;
243                         }
244         ;
245
246 /* A statement in the program, including optional labels */
247 fullstmt:       barestmt
248                         {
249                           $$ = $1 ? newSTATEOP(0, NULL, $1) : NULL;
250                         }
251         |       labfullstmt
252                         { $$ = $1; }
253         ;
254
255 labfullstmt:    LABEL barestmt
256                         {
257                           SV *label = cSVOPx_sv($1);
258                           $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8,
259                                             savepv(SvPVX_const(label)), $2);
260                           op_free($1);
261                         }
262         |       LABEL labfullstmt
263                         {
264                           SV *label = cSVOPx_sv($1);
265                           $$ = newSTATEOP(SvFLAGS(label) & SVf_UTF8,
266                                             savepv(SvPVX_const(label)), $2);
267                           op_free($1);
268                         }
269         ;
270
271 /* A bare statement, lacking label and other aspects of state op */
272 barestmt:       PLUGSTMT
273                         { $$ = $1; }
274         |       FORMAT startformsub formname formblock
275                         {
276                           CV *fmtcv = PL_compcv;
277                           newFORM($2, $3, $4);
278                           $$ = NULL;
279                           if (CvOUTSIDE(fmtcv) && !CvEVAL(CvOUTSIDE(fmtcv))) {
280                               pad_add_weakref(fmtcv);
281                           }
282                           parser->parsed_sub = 1;
283                         }
284         |       SUB subname startsub
285                     /* sub declaration or definition not within scope
286                        of 'use feature "signatures"'*/
287                         {
288                           init_named_cv(PL_compcv, $2);
289                           parser->in_my = 0;
290                           parser->in_my_stash = NULL;
291                         }
292                     proto subattrlist optsubbody
293                         {
294                           SvREFCNT_inc_simple_void(PL_compcv);
295                           $2->op_type == OP_CONST
296                               ? newATTRSUB($3, $2, $5, $6, $7)
297                               : newMYSUB($3, $2, $5, $6, $7)
298                           ;
299                           $$ = NULL;
300                           intro_my();
301                           parser->parsed_sub = 1;
302                         }
303         |       SIGSUB subname startsub
304                     /* sub declaration or definition under 'use feature
305                      * "signatures"'. (Note that a signature isn't
306                      * allowed in a declaration)
307                      */
308                         {
309                           init_named_cv(PL_compcv, $2);
310                           parser->in_my = 0;
311                           parser->in_my_stash = NULL;
312                         }
313                     subattrlist optsigsubbody
314                         {
315                           SvREFCNT_inc_simple_void(PL_compcv);
316                           $2->op_type == OP_CONST
317                               ? newATTRSUB($3, $2, NULL, $5, $6)
318                               : newMYSUB(  $3, $2, NULL, $5, $6)
319                           ;
320                           $$ = NULL;
321                           intro_my();
322                           parser->parsed_sub = 1;
323                         }
324         |       PACKAGE BAREWORD BAREWORD ';'
325                         {
326                           package($3);
327                           if ($2)
328                               package_version($2);
329                           $$ = NULL;
330                         }
331         |       USE startsub
332                         { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
333                 BAREWORD BAREWORD optlistexpr ';'
334                         {
335                           SvREFCNT_inc_simple_void(PL_compcv);
336                           utilize($1, $2, $4, $5, $6);
337                           parser->parsed_sub = 1;
338                           $$ = NULL;
339                         }
340         |       IF '(' remember mexpr ')' mblock else
341                         {
342                           $$ = block_end($3,
343                               newCONDOP(0, $4, op_scope($6), $7));
344                           parser->copline = (line_t)$1;
345                         }
346         |       UNLESS '(' remember mexpr ')' mblock else
347                         {
348                           $$ = block_end($3,
349                               newCONDOP(0, $4, $7, op_scope($6)));
350                           parser->copline = (line_t)$1;
351                         }
352         |       GIVEN '(' remember mexpr ')' mblock
353                         {
354                           $$ = block_end($3, newGIVENOP($4, op_scope($6), 0));
355                           parser->copline = (line_t)$1;
356                         }
357         |       WHEN '(' remember mexpr ')' mblock
358                         { $$ = block_end($3, newWHENOP($4, op_scope($6))); }
359         |       DEFAULT block
360                         { $$ = newWHENOP(0, op_scope($2)); }
361         |       WHILE '(' remember texpr ')' mintro mblock cont
362                         {
363                           $$ = block_end($3,
364                                   newWHILEOP(0, 1, NULL,
365                                       $4, $7, $8, $6));
366                           parser->copline = (line_t)$1;
367                         }
368         |       UNTIL '(' remember iexpr ')' mintro mblock cont
369                         {
370                           $$ = block_end($3,
371                                   newWHILEOP(0, 1, NULL,
372                                       $4, $7, $8, $6));
373                           parser->copline = (line_t)$1;
374                         }
375         |       FOR '(' remember mnexpr ';'
376                         { parser->expect = XTERM; }
377                 texpr ';'
378                         { parser->expect = XTERM; }
379                 mintro mnexpr ')'
380                 mblock
381                         {
382                           OP *initop = $4;
383                           OP *forop = newWHILEOP(0, 1, NULL,
384                                       scalar($7), $13, $11, $10);
385                           if (initop) {
386                               forop = op_prepend_elem(OP_LINESEQ, initop,
387                                   op_append_elem(OP_LINESEQ,
388                                       newOP(OP_UNSTACK, OPf_SPECIAL),
389                                       forop));
390                           }
391                           PL_hints |= HINT_BLOCK_SCOPE;
392                           $$ = block_end($3, forop);
393                           parser->copline = (line_t)$1;
394                         }
395         |       FOR MY remember my_scalar '(' mexpr ')' mblock cont
396                         {
397                           $$ = block_end($3, newFOROP(0, $4, $6, $8, $9));
398                           parser->copline = (line_t)$1;
399                         }
400         |       FOR scalar '(' remember mexpr ')' mblock cont
401                         {
402                           $$ = block_end($4, newFOROP(0,
403                                       op_lvalue($2, OP_ENTERLOOP), $5, $7, $8));
404                           parser->copline = (line_t)$1;
405                         }
406         |       FOR my_refgen remember my_var
407                         { parser->in_my = 0; $<opval>$ = my($4); }
408                 '(' mexpr ')' mblock cont
409                         {
410                           $$ = block_end(
411                                 $3,
412                                 newFOROP(0,
413                                          op_lvalue(
414                                             newUNOP(OP_REFGEN, 0,
415                                                     $<opval>5),
416                                             OP_ENTERLOOP),
417                                          $7, $9, $10)
418                           );
419                           parser->copline = (line_t)$1;
420                         }
421         |       FOR REFGEN refgen_topic '(' remember mexpr ')' mblock cont
422                         {
423                           $$ = block_end($5, newFOROP(
424                                 0, op_lvalue(newUNOP(OP_REFGEN, 0,
425                                                      $3),
426                                              OP_ENTERLOOP), $6, $8, $9));
427                           parser->copline = (line_t)$1;
428                         }
429         |       FOR '(' remember mexpr ')' mblock cont
430                         {
431                           $$ = block_end($3,
432                                   newFOROP(0, NULL, $4, $6, $7));
433                           parser->copline = (line_t)$1;
434                         }
435         |       block cont
436                         {
437                           /* a block is a loop that happens once */
438                           $$ = newWHILEOP(0, 1, NULL,
439                                   NULL, $1, $2, 0);
440                         }
441         |       PACKAGE BAREWORD BAREWORD '{' remember
442                         {
443                           package($3);
444                           if ($2) {
445                               package_version($2);
446                           }
447                         }
448                 stmtseq '}'
449                         {
450                           /* a block is a loop that happens once */
451                           $$ = newWHILEOP(0, 1, NULL,
452                                   NULL, block_end($5, $7), NULL, 0);
453                           if (parser->copline > (line_t)$4)
454                               parser->copline = (line_t)$4;
455                         }
456         |       sideff ';'
457                         {
458                           $$ = $1;
459                         }
460         |       YADAYADA ';'
461                         {
462                           $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
463                                 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
464                         }
465         |       ';'
466                         {
467                           $$ = NULL;
468                           parser->copline = NOLINE;
469                         }
470         ;
471
472 /* Format line */
473 formline:       THING formarg
474                         { OP *list;
475                           if ($2) {
476                               OP *term = $2;
477                               list = op_append_elem(OP_LIST, $1, term);
478                           }
479                           else {
480                               list = $1;
481                           }
482                           if (parser->copline == NOLINE)
483                                parser->copline = CopLINE(PL_curcop)-1;
484                           else parser->copline--;
485                           $$ = newSTATEOP(0, NULL,
486                                           op_convert_list(OP_FORMLINE, 0, list));
487                         }
488         ;
489
490 formarg :       /* NULL */
491                         { $$ = NULL; }
492         |       FORMLBRACK stmtseq FORMRBRACK
493                         { $$ = op_unscope($2); }
494         ;
495
496 /* An expression which may have a side-effect */
497 sideff  :       error
498                         { $$ = NULL; }
499         |       expr
500                         { $$ = $1; }
501         |       expr IF expr
502                         { $$ = newLOGOP(OP_AND, 0, $3, $1); }
503         |       expr UNLESS expr
504                         { $$ = newLOGOP(OP_OR, 0, $3, $1); }
505         |       expr WHILE expr
506                         { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); }
507         |       expr UNTIL iexpr
508                         { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1); }
509         |       expr FOR expr
510                         { $$ = newFOROP(0, NULL, $3, $1, NULL);
511                           parser->copline = (line_t)$2; }
512         |       expr WHEN expr
513                         { $$ = newWHENOP($3, op_scope($1)); }
514         ;
515
516 /* else and elsif blocks */
517 else    :       /* NULL */
518                         { $$ = NULL; }
519         |       ELSE mblock
520                         {
521                           ($2)->op_flags |= OPf_PARENS;
522                           $$ = op_scope($2);
523                         }
524         |       ELSIF '(' mexpr ')' mblock else
525                         { parser->copline = (line_t)$1;
526                             $$ = newCONDOP(0,
527                                 newSTATEOP(OPf_SPECIAL,NULL,$3),
528                                 op_scope($5), $6);
529                           PL_hints |= HINT_BLOCK_SCOPE;
530                         }
531         ;
532
533 /* Continue blocks */
534 cont    :       /* NULL */
535                         { $$ = NULL; }
536         |       CONTINUE block
537                         { $$ = op_scope($2); }
538         ;
539
540 /* determine whether there are any new my declarations */
541 mintro  :       /* NULL */
542                         { $$ = (PL_min_intro_pending &&
543                             PL_max_intro_pending >=  PL_min_intro_pending);
544                           intro_my(); }
545
546 /* Normal expression */
547 nexpr   :       /* NULL */
548                         { $$ = NULL; }
549         |       sideff
550         ;
551
552 /* Boolean expression */
553 texpr   :       /* NULL means true */
554                         { YYSTYPE tmplval;
555                           (void)scan_num("1", &tmplval);
556                           $$ = tmplval.opval; }
557         |       expr
558         ;
559
560 /* Inverted boolean expression */
561 iexpr   :       expr
562                         { $$ = invert(scalar($1)); }
563         ;
564
565 /* Expression with its own lexical scope */
566 mexpr   :       expr
567                         { $$ = $1; intro_my(); }
568         ;
569
570 mnexpr  :       nexpr
571                         { $$ = $1; intro_my(); }
572         ;
573
574 formname:       BAREWORD        { $$ = $1; }
575         |       /* NULL */      { $$ = NULL; }
576         ;
577
578 startsub:       /* NULL */      /* start a regular subroutine scope */
579                         { $$ = start_subparse(FALSE, 0);
580                             SAVEFREESV(PL_compcv); }
581
582         ;
583
584 startanonsub:   /* NULL */      /* start an anonymous subroutine scope */
585                         { $$ = start_subparse(FALSE, CVf_ANON);
586                             SAVEFREESV(PL_compcv); }
587         ;
588
589 startformsub:   /* NULL */      /* start a format subroutine scope */
590                         { $$ = start_subparse(TRUE, 0);
591                             SAVEFREESV(PL_compcv); }
592         ;
593
594 /* Name of a subroutine - must be a bareword, could be special */
595 subname :       BAREWORD
596         |       PRIVATEREF
597         ;
598
599 /* Subroutine prototype */
600 proto   :       /* NULL */
601                         { $$ = NULL; }
602         |       THING
603         ;
604
605 /* Optional list of subroutine attributes */
606 subattrlist:    /* NULL */
607                         { $$ = NULL; }
608         |       COLONATTR THING
609                         { $$ = $2; }
610         |       COLONATTR
611                         { $$ = NULL; }
612         ;
613
614 /* List of attributes for a "my" variable declaration */
615 myattrlist:     COLONATTR THING
616                         { $$ = $2; }
617         |       COLONATTR
618                         { $$ = NULL; }
619         ;
620
621
622
623 /* --------------------------------------
624  * subroutine signature parsing
625  */
626
627 /* the '' or 'foo' part of a '$' or '@foo' etc signature variable  */
628 sigvarname:     /* NULL */
629                         { parser->in_my = 0; $$ = NULL; }
630         |       PRIVATEREF
631                         { parser->in_my = 0; $$ = $1; }
632         ;
633
634 sigslurpsigil:
635                 '@'
636                         { $$ = '@'; }
637         |       '%'
638                         { $$ = '%'; }
639
640 /* @, %, @foo, %foo */
641 sigslurpelem: sigslurpsigil sigvarname sigdefault/* def only to catch errors */ 
642                         {
643                             I32 sigil   = $1;
644                             OP *var     = $2;
645                             OP *defexpr = $3;
646
647                             if (parser->sig_slurpy)
648                                 yyerror("Multiple slurpy parameters not allowed");
649                             parser->sig_slurpy = (char)sigil;
650
651                             if (defexpr)
652                                 yyerror("A slurpy parameter may not have "
653                                         "a default value");
654
655                             $$ = var ? newSTATEOP(0, NULL, var) : NULL;
656                         }
657         ;
658
659 /* default part of sub signature scalar element: i.e. '= default_expr' */
660 sigdefault:     /* NULL */
661                         { $$ = NULL; }
662         |       ASSIGNOP
663                         { $$ = newOP(OP_NULL, 0); }
664         |       ASSIGNOP term
665                         { $$ = $2; }
666
667
668 /* subroutine signature scalar element: e.g. '$x', '$=', '$x = $default' */
669 sigscalarelem:
670                 '$' sigvarname sigdefault
671                         {
672                             OP *var     = $2;
673                             OP *defexpr = $3;
674
675                             if (parser->sig_slurpy)
676                                 yyerror("Slurpy parameter not last");
677
678                             parser->sig_elems++;
679
680                             if (defexpr) {
681                                 parser->sig_optelems++;
682
683                                 if (   defexpr->op_type == OP_NULL
684                                     && !(defexpr->op_flags & OPf_KIDS))
685                                 {
686                                     /* handle '$=' special case */
687                                     if (var)
688                                         yyerror("Optional parameter "
689                                                     "lacks default expression");
690                                     op_free(defexpr);
691                                 }
692                                 else { 
693                                     /* a normal '=default' expression */ 
694                                     OP *defop = (OP*)alloc_LOGOP(OP_ARGDEFELEM,
695                                                         defexpr,
696                                                         LINKLIST(defexpr));
697                                     /* re-purpose op_targ to hold @_ index */
698                                     defop->op_targ =
699                                         (PADOFFSET)(parser->sig_elems - 1);
700
701                                     if (var) {
702                                         var->op_flags |= OPf_STACKED;
703                                         (void)op_sibling_splice(var,
704                                                         NULL, 0, defop);
705                                         scalar(defop);
706                                     }
707                                     else
708                                         var = newUNOP(OP_NULL, 0, defop);
709
710                                     LINKLIST(var);
711                                     /* NB: normally the first child of a
712                                      * logop is executed before the logop,
713                                      * and it pushes a boolean result
714                                      * ready for the logop. For ARGDEFELEM,
715                                      * the op itself does the boolean
716                                      * calculation, so set the first op to
717                                      * it instead.
718                                      */
719                                     var->op_next = defop;
720                                     defexpr->op_next = var;
721                                 }
722                             }
723                             else {
724                                 if (parser->sig_optelems)
725                                     yyerror("Mandatory parameter "
726                                             "follows optional parameter");
727                             }
728
729                             $$ = var ? newSTATEOP(0, NULL, var) : NULL;
730                         }
731         ;
732
733
734 /* subroutine signature element: e.g. '$x = $default' or '%h' */
735 sigelem:        sigscalarelem
736                         { parser->in_my = KEY_sigvar; $$ = $1; }
737         |       sigslurpelem
738                         { parser->in_my = KEY_sigvar; $$ = $1; }
739         ;
740
741 /* list of subroutine signature elements */
742 siglist:
743                 siglist ','
744                         { $$ = $1; }
745         |       siglist ',' sigelem
746                         {
747                           $$ = op_append_list(OP_LINESEQ, $1, $3);
748                         }
749         |       sigelem  %prec PREC_LOW
750                         { $$ = $1; }
751         ;
752
753 /* () or (....) */
754 siglistornull:          /* NULL */
755                         { $$ = NULL; }
756         |       siglist
757                         { $$ = $1; }
758
759 /* optional subroutine signature */
760 optsubsignature:        /* NULL */
761                         { $$ = NULL; }
762         |       subsignature
763                         { $$ = $1; }
764
765 /* Subroutine signature */
766 subsignature:   '('
767                         {
768                             ENTER;
769                             SAVEIV(parser->sig_elems);
770                             SAVEIV(parser->sig_optelems);
771                             SAVEI8(parser->sig_slurpy);
772                             parser->sig_elems    = 0;
773                             parser->sig_optelems = 0;
774                             parser->sig_slurpy   = 0;
775                             parser->in_my        = KEY_sigvar;
776                         }
777                 siglistornull
778                 ')'
779                         {
780                             OP            *sigops = $3;
781                             UNOP_AUX_item *aux;
782                             OP            *check;
783
784                             if (!FEATURE_SIGNATURES_IS_ENABLED)
785                                 Perl_croak(aTHX_ "Experimental "
786                                     "subroutine signatures not enabled");
787
788                             /* We shouldn't get here otherwise */
789                             Perl_ck_warner_d(aTHX_
790                                 packWARN(WARN_EXPERIMENTAL__SIGNATURES),
791                                 "The signatures feature is experimental");
792
793                             aux = (UNOP_AUX_item*)PerlMemShared_malloc(
794                                 sizeof(UNOP_AUX_item) * 3);
795                             aux[0].iv = parser->sig_elems;
796                             aux[1].iv = parser->sig_optelems;
797                             aux[2].iv = parser->sig_slurpy;
798                             check = newUNOP_AUX(OP_ARGCHECK, 0, NULL, aux);
799                             sigops = op_prepend_elem(OP_LINESEQ, check, sigops);
800                             sigops = op_prepend_elem(OP_LINESEQ,
801                                                 newSTATEOP(0, NULL, NULL),
802                                                 sigops);
803                             /* a nextstate at the end handles context
804                              * correctly for an empty sub body */
805                             $$ = op_append_elem(OP_LINESEQ,
806                                                 sigops,
807                                                 newSTATEOP(0, NULL, NULL));
808
809                             parser->in_my = 0;
810                             /* tell the toker that attrributes can follow
811                              * this sig, but only so that the toker
812                              * can skip through any (illegal) trailing
813                              * attribute text then give a useful error
814                              * message about "attributes before sig",
815                              * rather than falling over ina mess at
816                              * unrecognised syntax.
817                              */
818                             parser->expect = XATTRBLOCK;
819                             parser->sig_seen = TRUE;
820                             LEAVE;
821                         }
822         ;
823
824 /* Optional subroutine body (for named subroutine declaration) */
825 optsubbody:     subbody { $$ = $1; }
826         |       ';'     { $$ = NULL; }
827         ;
828
829
830 /* Subroutine body (without signature) */
831 subbody:        remember  '{' stmtseq '}'
832                         {
833                           if (parser->copline > (line_t)$2)
834                               parser->copline = (line_t)$2;
835                           $$ = block_end($1, $3);
836                         }
837         ;
838
839
840 /* optional [ Subroutine body with optional signature ] (for named
841  * subroutine declaration) */
842 optsigsubbody:  sigsubbody { $$ = $1; }
843         |       ';'        { $$ = NULL; }
844
845 /* Subroutine body with optional signature */
846 sigsubbody:     remember optsubsignature '{' stmtseq '}'
847                         {
848                           if (parser->copline > (line_t)$3)
849                               parser->copline = (line_t)$3;
850                           $$ = block_end($1,
851                                 op_append_list(OP_LINESEQ, $2, $4));
852                         }
853         ;
854
855
856 /* Ordinary expressions; logical combinations */
857 expr    :       expr ANDOP expr
858                         { $$ = newLOGOP(OP_AND, 0, $1, $3); }
859         |       expr OROP expr
860                         { $$ = newLOGOP($2, 0, $1, $3); }
861         |       expr DOROP expr
862                         { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
863         |       listexpr %prec PREC_LOW
864         ;
865
866 /* Expressions are a list of terms joined by commas */
867 listexpr:       listexpr ','
868                         { $$ = $1; }
869         |       listexpr ',' term
870                         {
871                           OP* term = $3;
872                           $$ = op_append_elem(OP_LIST, $1, term);
873                         }
874         |       term %prec PREC_LOW
875         ;
876
877 /* List operators */
878 listop  :       LSTOP indirob listexpr /* map {...} @args or print $fh @args */
879                         { $$ = op_convert_list($1, OPf_STACKED,
880                                 op_prepend_elem(OP_LIST, newGVREF($1,$2), $3) );
881                         }
882         |       FUNC '(' indirob expr ')'      /* print ($fh @args */
883                         { $$ = op_convert_list($1, OPf_STACKED,
884                                 op_prepend_elem(OP_LIST, newGVREF($1,$3), $4) );
885                         }
886         |       term ARROW method '(' optexpr ')' /* $foo->bar(list) */
887                         { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
888                                 op_append_elem(OP_LIST,
889                                     op_prepend_elem(OP_LIST, scalar($1), $5),
890                                     newMETHOP(OP_METHOD, 0, $3)));
891                         }
892         |       term ARROW method                     /* $foo->bar */
893                         { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
894                                 op_append_elem(OP_LIST, scalar($1),
895                                     newMETHOP(OP_METHOD, 0, $3)));
896                         }
897         |       METHOD indirob optlistexpr           /* new Class @args */
898                         { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
899                                 op_append_elem(OP_LIST,
900                                     op_prepend_elem(OP_LIST, $2, $3),
901                                     newMETHOP(OP_METHOD, 0, $1)));
902                         }
903         |       FUNCMETH indirob '(' optexpr ')'    /* method $object (@args) */
904                         { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
905                                 op_append_elem(OP_LIST,
906                                     op_prepend_elem(OP_LIST, $2, $4),
907                                     newMETHOP(OP_METHOD, 0, $1)));
908                         }
909         |       LSTOP optlistexpr                    /* print @args */
910                         { $$ = op_convert_list($1, 0, $2); }
911         |       FUNC '(' optexpr ')'                 /* print (@args) */
912                         { $$ = op_convert_list($1, 0, $3); }
913         |       FUNC SUBLEXSTART optexpr SUBLEXEND          /* uc($arg) from "\U..." */
914                         { $$ = op_convert_list($1, 0, $3); }
915         |       LSTOPSUB startanonsub block /* sub f(&@);   f { foo } ... */
916                         { SvREFCNT_inc_simple_void(PL_compcv);
917                           $<opval>$ = newANONATTRSUB($2, 0, NULL, $3); }
918                     optlistexpr         %prec LSTOP  /* ... @bar */
919                         { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
920                                  op_append_elem(OP_LIST,
921                                    op_prepend_elem(OP_LIST, $<opval>4, $5), $1));
922                         }
923         ;
924
925 /* Names of methods. May use $object->$methodname */
926 method  :       METHOD
927         |       scalar
928         ;
929
930 /* Some kind of subscripted expression */
931 subscripted:    gelem '{' expr ';' '}'        /* *main::{something} */
932                         /* In this and all the hash accessors, ';' is
933                          * provided by the tokeniser */
934                         { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); }
935         |       scalar '[' expr ']'          /* $array[$element] */
936                         { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3));
937                         }
938         |       term ARROW '[' expr ']'      /* somearef->[$element] */
939                         { $$ = newBINOP(OP_AELEM, 0,
940                                         ref(newAVREF($1),OP_RV2AV),
941                                         scalar($4));
942                         }
943         |       subscripted '[' expr ']'    /* $foo->[$bar]->[$baz] */
944                         { $$ = newBINOP(OP_AELEM, 0,
945                                         ref(newAVREF($1),OP_RV2AV),
946                                         scalar($3));
947                         }
948         |       scalar '{' expr ';' '}'    /* $foo{bar();} */
949                         { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
950                         }
951         |       term ARROW '{' expr ';' '}' /* somehref->{bar();} */
952                         { $$ = newBINOP(OP_HELEM, 0,
953                                         ref(newHVREF($1),OP_RV2HV),
954                                         jmaybe($4)); }
955         |       subscripted '{' expr ';' '}' /* $foo->[bar]->{baz;} */
956                         { $$ = newBINOP(OP_HELEM, 0,
957                                         ref(newHVREF($1),OP_RV2HV),
958                                         jmaybe($3)); }
959         |       term ARROW '(' ')'          /* $subref->() */
960                         { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
961                                    newCVREF(0, scalar($1)));
962                           if (parser->expect == XBLOCK)
963                               parser->expect = XOPERATOR;
964                         }
965         |       term ARROW '(' expr ')'     /* $subref->(@args) */
966                         { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
967                                    op_append_elem(OP_LIST, $4,
968                                        newCVREF(0, scalar($1))));
969                           if (parser->expect == XBLOCK)
970                               parser->expect = XOPERATOR;
971                         }
972
973         |       subscripted '(' expr ')'   /* $foo->{bar}->(@args) */
974                         { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
975                                    op_append_elem(OP_LIST, $3,
976                                                newCVREF(0, scalar($1))));
977                           if (parser->expect == XBLOCK)
978                               parser->expect = XOPERATOR;
979                         }
980         |       subscripted '(' ')'        /* $foo->{bar}->() */
981                         { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
982                                    newCVREF(0, scalar($1)));
983                           if (parser->expect == XBLOCK)
984                               parser->expect = XOPERATOR;
985                         }
986         |       '(' expr ')' '[' expr ']'            /* list slice */
987                         { $$ = newSLICEOP(0, $5, $2); }
988         |       QWLIST '[' expr ']'            /* list literal slice */
989                         { $$ = newSLICEOP(0, $3, $1); }
990         |       '(' ')' '[' expr ']'                 /* empty list slice! */
991                         { $$ = newSLICEOP(0, $4, NULL); }
992     ;
993
994 /* Binary operators between terms */
995 termbinop:      term ASSIGNOP term                     /* $x = $y, $x += $y */
996                         { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); }
997         |       term POWOP term                        /* $x ** $y */
998                         { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
999         |       term MULOP term                        /* $x * $y, $x x $y */
1000                         {   if ($2 != OP_REPEAT)
1001                                 scalar($1);
1002                             $$ = newBINOP($2, 0, $1, scalar($3));
1003                         }
1004         |       term ADDOP term                        /* $x + $y */
1005                         { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
1006         |       term SHIFTOP term                      /* $x >> $y, $x << $y */
1007                         { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
1008         |       term RELOP term                        /* $x > $y, etc. */
1009                         { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
1010         |       term EQOP term                         /* $x == $y, $x eq $y */
1011                         { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
1012         |       term BITANDOP term                     /* $x & $y */
1013                         { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
1014         |       term BITOROP term                      /* $x | $y */
1015                         { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
1016         |       term DOTDOT term                       /* $x..$y, $x...$y */
1017                         { $$ = newRANGE($2, scalar($1), scalar($3)); }
1018         |       term ANDAND term                       /* $x && $y */
1019                         { $$ = newLOGOP(OP_AND, 0, $1, $3); }
1020         |       term OROR term                         /* $x || $y */
1021                         { $$ = newLOGOP(OP_OR, 0, $1, $3); }
1022         |       term DORDOR term                       /* $x // $y */
1023                         { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
1024         |       term MATCHOP term                      /* $x =~ /$y/ */
1025                         { $$ = bind_match($2, $1, $3); }
1026     ;
1027
1028 /* Unary operators and terms */
1029 termunop : '-' term %prec UMINUS                       /* -$x */
1030                         { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); }
1031         |       '+' term %prec UMINUS                  /* +$x */
1032                         { $$ = $2; }
1033
1034         |       '!' term                               /* !$x */
1035                         { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
1036         |       '~' term                               /* ~$x */
1037                         { $$ = newUNOP($1, 0, scalar($2)); }
1038         |       term POSTINC                           /* $x++ */
1039                         { $$ = newUNOP(OP_POSTINC, 0,
1040                                         op_lvalue(scalar($1), OP_POSTINC)); }
1041         |       term POSTDEC                           /* $x-- */
1042                         { $$ = newUNOP(OP_POSTDEC, 0,
1043                                         op_lvalue(scalar($1), OP_POSTDEC));}
1044         |       term POSTJOIN    /* implicit join after interpolated ->@ */
1045                         { $$ = op_convert_list(OP_JOIN, 0,
1046                                        op_append_elem(
1047                                         OP_LIST,
1048                                         newSVREF(scalar(
1049                                             newSVOP(OP_CONST,0,
1050                                                     newSVpvs("\""))
1051                                         )),
1052                                         $1
1053                                        ));
1054                         }
1055         |       PREINC term                            /* ++$x */
1056                         { $$ = newUNOP(OP_PREINC, 0,
1057                                         op_lvalue(scalar($2), OP_PREINC)); }
1058         |       PREDEC term                            /* --$x */
1059                         { $$ = newUNOP(OP_PREDEC, 0,
1060                                         op_lvalue(scalar($2), OP_PREDEC)); }
1061
1062     ;
1063
1064 /* Constructors for anonymous data */
1065 anonymous:      '[' expr ']'
1066                         { $$ = newANONLIST($2); }
1067         |       '[' ']'
1068                         { $$ = newANONLIST(NULL);}
1069         |       HASHBRACK expr ';' '}'  %prec '(' /* { foo => "Bar" } */
1070                         { $$ = newANONHASH($2); }
1071         |       HASHBRACK ';' '}'       %prec '(' /* { } (';' by tokener) */
1072                         { $$ = newANONHASH(NULL); }
1073         |       ANONSUB     startanonsub proto subattrlist subbody    %prec '('
1074                         { SvREFCNT_inc_simple_void(PL_compcv);
1075                           $$ = newANONATTRSUB($2, $3, $4, $5); }
1076         |       ANON_SIGSUB startanonsub subattrlist sigsubbody %prec '('
1077                         { SvREFCNT_inc_simple_void(PL_compcv);
1078                           $$ = newANONATTRSUB($2, NULL, $3, $4); }
1079     ;
1080
1081 /* Things called with "do" */
1082 termdo  :       DO term %prec UNIOP                     /* do $filename */
1083                         { $$ = dofile($2, $1);}
1084         |       DO block        %prec '('               /* do { code */
1085                         { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($2));}
1086         ;
1087
1088 term    :       termbinop
1089         |       termunop
1090         |       anonymous
1091         |       termdo
1092         |       term '?' term ':' term
1093                         { $$ = newCONDOP(0, $1, $3, $5); }
1094         |       REFGEN term                          /* \$x, \@y, \%z */
1095                         { $$ = newUNOP(OP_REFGEN, 0, $2); }
1096         |       MY REFGEN term
1097                         { $$ = newUNOP(OP_REFGEN, 0, localize($3,1)); }
1098         |       myattrterm      %prec UNIOP
1099                         { $$ = $1; }
1100         |       LOCAL term      %prec UNIOP
1101                         { $$ = localize($2,0); }
1102         |       '(' expr ')'
1103                         { $$ = sawparens($2); }
1104         |       QWLIST
1105                         { $$ = $1; }
1106         |       '(' ')'
1107                         { $$ = sawparens(newNULLLIST()); }
1108         |       scalar  %prec '('
1109                         { $$ = $1; }
1110         |       star    %prec '('
1111                         { $$ = $1; }
1112         |       hsh     %prec '('
1113                         { $$ = $1; }
1114         |       ary     %prec '('
1115                         { $$ = $1; }
1116         |       arylen  %prec '('                    /* $#x, $#{ something } */
1117                         { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
1118         |       subscripted
1119                         { $$ = $1; }
1120         |       sliceme '[' expr ']'                     /* array slice */
1121                         { $$ = op_prepend_elem(OP_ASLICE,
1122                                 newOP(OP_PUSHMARK, 0),
1123                                     newLISTOP(OP_ASLICE, 0,
1124                                         list($3),
1125                                         ref($1, OP_ASLICE)));
1126                           if ($$ && $1)
1127                               $$->op_private |=
1128                                   $1->op_private & OPpSLICEWARNING;
1129                         }
1130         |       kvslice '[' expr ']'                 /* array key/value slice */
1131                         { $$ = op_prepend_elem(OP_KVASLICE,
1132                                 newOP(OP_PUSHMARK, 0),
1133                                     newLISTOP(OP_KVASLICE, 0,
1134                                         list($3),
1135                                         ref(oopsAV($1), OP_KVASLICE)));
1136                           if ($$ && $1)
1137                               $$->op_private |=
1138                                   $1->op_private & OPpSLICEWARNING;
1139                         }
1140         |       sliceme '{' expr ';' '}'                 /* @hash{@keys} */
1141                         { $$ = op_prepend_elem(OP_HSLICE,
1142                                 newOP(OP_PUSHMARK, 0),
1143                                     newLISTOP(OP_HSLICE, 0,
1144                                         list($3),
1145                                         ref(oopsHV($1), OP_HSLICE)));
1146                           if ($$ && $1)
1147                               $$->op_private |=
1148                                   $1->op_private & OPpSLICEWARNING;
1149                         }
1150         |       kvslice '{' expr ';' '}'                 /* %hash{@keys} */
1151                         { $$ = op_prepend_elem(OP_KVHSLICE,
1152                                 newOP(OP_PUSHMARK, 0),
1153                                     newLISTOP(OP_KVHSLICE, 0,
1154                                         list($3),
1155                                         ref($1, OP_KVHSLICE)));
1156                           if ($$ && $1)
1157                               $$->op_private |=
1158                                   $1->op_private & OPpSLICEWARNING;
1159                         }
1160         |       THING   %prec '('
1161                         { $$ = $1; }
1162         |       amper                                /* &foo; */
1163                         { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
1164         |       amper '(' ')'                 /* &foo() or foo() */
1165                         { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1));
1166                         }
1167         |       amper '(' expr ')'          /* &foo(@args) or foo(@args) */
1168                         {
1169                           $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1170                                 op_append_elem(OP_LIST, $3, scalar($1)));
1171                         }
1172         |       NOAMP subname optlistexpr       /* foo @args (no parens) */
1173                         { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1174                             op_append_elem(OP_LIST, $3, scalar($2)));
1175                         }
1176         |       term ARROW '$' '*'
1177                         { $$ = newSVREF($1); }
1178         |       term ARROW '@' '*'
1179                         { $$ = newAVREF($1); }
1180         |       term ARROW '%' '*'
1181                         { $$ = newHVREF($1); }
1182         |       term ARROW '&' '*'
1183                         { $$ = newUNOP(OP_ENTERSUB, 0,
1184                                        scalar(newCVREF($3,$1))); }
1185         |       term ARROW '*' '*'      %prec '('
1186                         { $$ = newGVREF(0,$1); }
1187         |       LOOPEX  /* loop exiting command (goto, last, dump, etc) */
1188                         { $$ = newOP($1, OPf_SPECIAL);
1189                             PL_hints |= HINT_BLOCK_SCOPE; }
1190         |       LOOPEX term
1191                         { $$ = newLOOPEX($1,$2); }
1192         |       NOTOP listexpr                       /* not $foo */
1193                         { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
1194         |       UNIOP                                /* Unary op, $_ implied */
1195                         { $$ = newOP($1, 0); }
1196         |       UNIOP block                          /* eval { foo }* */
1197                         { $$ = newUNOP($1, 0, $2); }
1198         |       UNIOP term                           /* Unary op */
1199                         { $$ = newUNOP($1, 0, $2); }
1200         |       REQUIRE                              /* require, $_ implied */
1201                         { $$ = newOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0); }
1202         |       REQUIRE term                         /* require Foo */
1203                         { $$ = newUNOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0, $2); }
1204         |       UNIOPSUB
1205                         { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
1206         |       UNIOPSUB term                        /* Sub treated as unop */
1207                         { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1208                             op_append_elem(OP_LIST, $2, scalar($1))); }
1209         |       FUNC0                                /* Nullary operator */
1210                         { $$ = newOP($1, 0); }
1211         |       FUNC0 '(' ')'
1212                         { $$ = newOP($1, 0);}
1213         |       FUNC0OP       /* Same as above, but op created in toke.c */
1214                         { $$ = $1; }
1215         |       FUNC0OP '(' ')'
1216                         { $$ = $1; }
1217         |       FUNC0SUB                             /* Sub treated as nullop */
1218                         { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
1219         |       FUNC1 '(' ')'                        /* not () */
1220                         { $$ = ($1 == OP_NOT)
1221                           ? newUNOP($1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
1222                           : newOP($1, OPf_SPECIAL); }
1223         |       FUNC1 '(' expr ')'                   /* not($foo) */
1224                         { $$ = newUNOP($1, 0, $3); }
1225         |       PMFUNC /* m//, s///, qr//, tr/// */
1226                         {
1227                             if (   $1->op_type != OP_TRANS
1228                                 && $1->op_type != OP_TRANSR
1229                                 && (((PMOP*)$1)->op_pmflags & PMf_HAS_CV))
1230                             {
1231                                 $<ival>$ = start_subparse(FALSE, CVf_ANON);
1232                                 SAVEFREESV(PL_compcv);
1233                             } else
1234                                 $<ival>$ = 0;
1235                         }
1236                     SUBLEXSTART listexpr optrepl SUBLEXEND
1237                         { $$ = pmruntime($1, $4, $5, 1, $<ival>2); }
1238         |       BAREWORD
1239         |       listop
1240         |       PLUGEXPR
1241         ;
1242
1243 /* "my" declarations, with optional attributes */
1244 myattrterm:     MY myterm myattrlist
1245                         { $$ = my_attrs($2,$3); }
1246         |       MY myterm
1247                         { $$ = localize($2,1); }
1248         |       MY REFGEN myterm myattrlist
1249                         { $$ = newUNOP(OP_REFGEN, 0, my_attrs($3,$4)); }
1250         ;
1251
1252 /* Things that can be "my"'d */
1253 myterm  :       '(' expr ')'
1254                         { $$ = sawparens($2); }
1255         |       '(' ')'
1256                         { $$ = sawparens(newNULLLIST()); }
1257
1258         |       scalar  %prec '('
1259                         { $$ = $1; }
1260         |       hsh     %prec '('
1261                         { $$ = $1; }
1262         |       ary     %prec '('
1263                         { $$ = $1; }
1264         ;
1265
1266 /* Basic list expressions */
1267 optlistexpr:    /* NULL */ %prec PREC_LOW
1268                         { $$ = NULL; }
1269         |       listexpr    %prec PREC_LOW
1270                         { $$ = $1; }
1271         ;
1272
1273 optexpr:        /* NULL */
1274                         { $$ = NULL; }
1275         |       expr
1276                         { $$ = $1; }
1277         ;
1278
1279 optrepl:        /* NULL */
1280                         { $$ = NULL; }
1281         |       '/' expr
1282                         { $$ = $2; }
1283         ;
1284
1285 /* A little bit of trickery to make "for my $foo (@bar)" actually be
1286    lexical */
1287 my_scalar:      scalar
1288                         { parser->in_my = 0; $$ = my($1); }
1289         ;
1290
1291 my_var  :       scalar
1292         |       ary
1293         |       hsh
1294         ;
1295
1296 refgen_topic:   my_var
1297         |       amper
1298         ;
1299
1300 my_refgen:      MY REFGEN
1301         |       REFGEN MY
1302         ;
1303
1304 amper   :       '&' indirob
1305                         { $$ = newCVREF($1,$2); }
1306         ;
1307
1308 scalar  :       '$' indirob
1309                         { $$ = newSVREF($2); }
1310         ;
1311
1312 ary     :       '@' indirob
1313                         { $$ = newAVREF($2);
1314                           if ($$) $$->op_private |= $1;
1315                         }
1316         ;
1317
1318 hsh     :       '%' indirob
1319                         { $$ = newHVREF($2);
1320                           if ($$) $$->op_private |= $1;
1321                         }
1322         ;
1323
1324 arylen  :       DOLSHARP indirob
1325                         { $$ = newAVREF($2); }
1326         |       term ARROW DOLSHARP '*'
1327                         { $$ = newAVREF($1); }
1328         ;
1329
1330 star    :       '*' indirob
1331                         { $$ = newGVREF(0,$2); }
1332         ;
1333
1334 sliceme :       ary
1335         |       term ARROW '@'
1336                         { $$ = newAVREF($1); }
1337         ;
1338
1339 kvslice :       hsh
1340         |       term ARROW '%'
1341                         { $$ = newHVREF($1); }
1342         ;
1343
1344 gelem   :       star
1345         |       term ARROW '*'
1346                         { $$ = newGVREF(0,$1); }
1347         ;
1348
1349 /* Indirect objects */
1350 indirob :       BAREWORD
1351                         { $$ = scalar($1); }
1352         |       scalar %prec PREC_LOW
1353                         { $$ = scalar($1); }
1354         |       block
1355                         { $$ = op_scope($1); }
1356
1357         |       PRIVATEREF
1358                         { $$ = $1; }
1359         ;