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