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