Because I like pain. An update to README
[perl.git] / madly.y
1 /*    perly.y
2  *
3  *    Copyright (c) 1991-2002, 2003, 2004 Larry Wall
4  *
5  *    You may distribute under the terms of either the GNU General Public
6  *    License or the Artistic License, as specified in the README file.
7  *
8  */
9
10 /*
11  * 'I see,' laughed Strider.  'I look foul and feel fair.  Is that it?
12  * All that is gold does not glitter, not all those who wander are lost.'
13  */
14
15 /*  Make the parser re-entrant. */
16
17 /* FIXME for MAD - is the new mintro on while and until important?  */
18 %pure_parser
19
20 %start prog
21
22 %union {
23     I32 ival;
24     char *pval;
25     TOKEN* tkval;
26     OP *opval;
27     GV *gvval;
28 }
29
30 %token <tkval> '{' '}' '[' ']' '-' '+' '$' '@' '%' '*'
31
32 %token <opval> WORD METHOD FUNCMETH THING PMFUNC PRIVATEREF
33 %token <opval> FUNC0SUB UNIOPSUB LSTOPSUB
34 %token <tkval> LABEL
35 %token <tkval> FORMAT SUB ANONSUB PACKAGE USE
36 %token <tkval> WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE FOR
37 %token <tkval> GIVEN WHEN DEFAULT
38 %token <tkval> LOOPEX DOTDOT
39 %token <tkval> FUNC0 FUNC1 FUNC UNIOP LSTOP
40 %token <tkval> RELOP EQOP MULOP ADDOP
41 %token <tkval> DOLSHARP DO HASHBRACK NOAMP
42 %token <tkval> LOCAL MY MYSUB REQUIRE
43 %token <tkval> COLONATTR
44
45 %type <ival> prog progstart remember mremember savescope
46 %type <ival>  startsub startanonsub startformsub
47 /* FIXME for MAD - are these two ival? */
48 %type <ival> mydefsv mintro
49
50 %type <tkval> '&' ';'
51
52 %type <opval> decl format subrout mysubrout package use peg
53
54 %type <opval> block mblock lineseq line loop cond else
55 %type <opval> expr term subscripted scalar ary hsh arylen star amper sideff
56 %type <opval> argexpr nexpr texpr iexpr mexpr mnexpr miexpr
57 %type <opval> listexpr listexprcom indirob listop method
58 %type <opval> formname subname proto subbody cont my_scalar
59 %type <opval> subattrlist myattrlist myattrterm myterm
60 %type <opval> termbinop termunop anonymous termdo
61 %type <opval> switch case
62 %type <tkval> label
63
64 %nonassoc <tkval> PREC_LOW
65 %nonassoc LOOPEX
66
67 %left <tkval> OROP DOROP
68 %left <tkval> ANDOP
69 %right <tkval> NOTOP
70 %nonassoc LSTOP LSTOPSUB
71 %left <tkval> ','
72 %right <tkval> ASSIGNOP
73 %right <tkval> '?' ':'
74 %nonassoc DOTDOT
75 %left <tkval> OROR DORDOR
76 %left <tkval> ANDAND
77 %left <tkval> BITOROP
78 %left <tkval> BITANDOP
79 %nonassoc EQOP
80 %nonassoc RELOP
81 %nonassoc UNIOP UNIOPSUB
82 %nonassoc REQUIRE
83 %left <tkval> SHIFTOP
84 %left ADDOP
85 %left MULOP
86 %left <tkval> MATCHOP
87 %right <tkval> '!' '~' UMINUS REFGEN
88 %right <tkval> POWOP
89 %nonassoc <tkval> PREINC PREDEC POSTINC POSTDEC
90 %left <tkval> ARROW
91 %nonassoc <tkval> ')'
92 %left <tkval> '('
93 %left '[' '{'
94
95 %token <tkval> PEG
96
97 %% /* RULES */
98
99 /* The whole program */
100 prog    :       progstart
101         /*CONTINUED*/   lineseq
102                         { $$ = $1; newPROG(block_end($1,$2)); }
103         ;
104
105 /* An ordinary block */
106 block   :       '{' remember lineseq '}'
107                         { if (PL_copline > (line_t)($1)->tk_lval.ival)
108                               PL_copline = (line_t)($1)->tk_lval.ival;
109                           $$ = block_end($2, $3);
110                           token_getmad($1,$$,'{');
111                           token_getmad($4,$$,'}');
112                         }
113         ;
114
115 remember:       /* NULL */      /* start a full lexical scope */
116                         { $$ = block_start(TRUE); }
117         ;
118
119 mydefsv:        /* NULL */      /* lexicalize $_ */
120                         { $$ = (I32) allocmy("$_"); }
121         ;
122
123 progstart:
124                 {
125                     PL_expect = XSTATE; $$ = block_start(TRUE);
126                 }
127         ;
128
129
130 mblock  :       '{' mremember lineseq '}'
131                         { if (PL_copline > (line_t)($1)->tk_lval.ival)
132                               PL_copline = (line_t)($1)->tk_lval.ival;
133                           $$ = block_end($2, $3);
134                           token_getmad($1,$$,'{');
135                           token_getmad($4,$$,'}');
136                         }
137         ;
138
139 mremember:      /* NULL */      /* start a partial lexical scope */
140                         { $$ = block_start(FALSE); }
141         ;
142
143 savescope:      /* NULL */      /* remember stack pos in case of error */
144                 { $$ = PL_savestack_ix; }
145
146 /* A collection of "lines" in the program */
147 lineseq :       /* NULL */
148                         { $$ = Nullop; }
149         |       lineseq decl
150 /*                      { $$ = $1 } */
151                         { $$ = append_list(OP_LINESEQ,
152                                 (LISTOP*)$1, (LISTOP*)$2); }
153         |       lineseq savescope line
154                         {   LEAVE_SCOPE($2);
155                             $$ = append_list(OP_LINESEQ,
156                                 (LISTOP*)$1, (LISTOP*)$3);
157                             PL_pad_reset_pending = TRUE;
158                             if ($1 && $3) PL_hints |= HINT_BLOCK_SCOPE; }
159         ;
160
161 /* A "line" in the program */
162 line    :       label cond
163                         { $$ = newSTATEOP(0, ($1)->tk_lval.pval, $2);
164                           token_getmad($1,((LISTOP*)$$)->op_first,'L'); }
165         |       loop    /* loops add their own labels */
166         |       switch  /* ... and so do switches */
167                         { $$ = $1; }
168         |       label case
169                         { $$ = newSTATEOP(0, ($1)->tk_lval.pval, $2); }
170         |       label ';'
171                         {
172                           if (($1)->tk_lval.pval) {
173                               $$ = newSTATEOP(0, ($1)->tk_lval.pval, newOP(OP_NULL, 0));
174                               token_getmad($1,$$,'L');
175                               token_getmad($2,((LISTOP*)$$)->op_first,';');
176                           }
177                           else {
178                               $$ = newOP(OP_NULL, 0);
179                               PL_copline = NOLINE;
180                               token_free($1);
181                               token_getmad($2,$$,';');
182                           }
183                           PL_expect = XSTATE;
184                         }
185         |       label sideff ';'
186                         { OP* op;
187                           $$ = newSTATEOP(0, ($1)->tk_lval.pval, $2);
188                           PL_expect = XSTATE;
189                           /* sideff might already have a nexstate */
190                           op = ((LISTOP*)$$)->op_first;
191                           if (op) {
192                               while (op->op_sibling &&
193                                  op->op_sibling->op_type == OP_NEXTSTATE)
194                                     op = op->op_sibling;
195                               token_getmad($1,op,'L');
196                               token_getmad($3,op,';');
197                           }
198                         }
199         ;
200
201 /* An expression which may have a side-effect */
202 sideff  :       error
203                         { $$ = Nullop; }
204         |       expr
205                         { $$ = $1; }
206         |       expr IF expr
207                         { $$ = newLOGOP(OP_AND, 0, $3, $1);
208                           token_getmad($2,$$,'i');
209                         }
210         |       expr UNLESS expr
211                         { $$ = newLOGOP(OP_OR, 0, $3, $1);
212                           token_getmad($2,$$,'i');
213                         }
214         |       expr WHILE expr
215                         { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1);
216                           token_getmad($2,$$,'w');
217                         }
218         |       expr UNTIL iexpr
219                         { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1);
220                           token_getmad($2,$$,'w');
221                         }
222         |       expr FOR expr
223                         { $$ = newFOROP(0, Nullch, (line_t)($2)->tk_lval.ival,
224                                         Nullop, $3, $1, Nullop);
225                           token_getmad($2,((LISTOP*)$$)->op_first->op_sibling,'w');
226                         }
227         ;
228
229 /* else and elsif blocks */
230 else    :       /* NULL */
231                         { $$ = Nullop; }
232         |       ELSE mblock
233                         { ($2)->op_flags |= OPf_PARENS; $$ = scope($2);
234                           token_getmad($1,$$,'o');
235                         }
236         |       ELSIF '(' mexpr ')' mblock else
237                         { PL_copline = (line_t)($1)->tk_lval.ival;
238                             $$ = newCONDOP(0, $3, scope($5), $6);
239                             PL_hints |= HINT_BLOCK_SCOPE;
240                           token_getmad($1,$$,'I');
241                           token_getmad($2,$$,'(');
242                           token_getmad($4,$$,')');
243                         }
244         ;
245
246 /* Real conditional expressions */
247 cond    :       IF '(' remember mexpr ')' mblock else
248                         { PL_copline = (line_t)($1)->tk_lval.ival;
249                             $$ = block_end($3,
250                                    newCONDOP(0, $4, scope($6), $7));
251                           token_getmad($1,$$,'I');
252                           token_getmad($2,$$,'(');
253                           token_getmad($5,$$,')');
254                         }
255         |       UNLESS '(' remember miexpr ')' mblock else
256                         { PL_copline = (line_t)($1)->tk_lval.ival;
257                             $$ = block_end($3,
258                                    newCONDOP(0, $4, scope($6), $7));
259                           token_getmad($1,$$,'I');
260                           token_getmad($2,$$,'(');
261                           token_getmad($5,$$,')');
262                         }
263         ;
264
265 /* Cases for a switch statement */
266 case    :       WHEN '(' remember mexpr ')' mblock
267         { $$ = block_end($3,
268                 newWHENOP($4, scope($6))); }
269         |       DEFAULT block
270         { $$ = newWHENOP(0, scope($2)); }
271         ;
272
273 /* Continue blocks */
274 cont    :       /* NULL */
275                         { $$ = Nullop; }
276         |       CONTINUE block
277                         { $$ = scope($2);
278                           token_getmad($1,$$,'o');
279                         }
280         ;
281
282 /* Loops: while, until, for, and a bare block */
283 loop    :       label WHILE '(' remember texpr ')' mintro mblock cont
284                         { OP *innerop;
285                           PL_copline = (line_t)$2;
286                             $$ = block_end($4,
287                                    newSTATEOP(0, ($1)->tk_lval.pval,
288                                      innerop = newWHILEOP(0, 1, (LOOP*)Nullop,
289                                                 ($2)->tk_lval.ival, $5, $8, $9, $7)));
290                           token_getmad($1,innerop,'L');
291                           token_getmad($2,innerop,'W');
292                           token_getmad($3,innerop,'(');
293                           token_getmad($6,innerop,')');
294                         }
295
296         |       label UNTIL '(' remember iexpr ')' mintro mblock cont
297                         { OP *innerop;
298                           PL_copline = (line_t)$2;
299                             $$ = block_end($4,
300                                    newSTATEOP(0, ($1)->tk_lval.pval,
301                                      newWHILEOP(0, 1, (LOOP*)Nullop,
302                                                 ($2)->tk_lval.ival, $5, $8, $9, $7)));
303                           token_getmad($1,innerop,'L');
304                           token_getmad($2,innerop,'W');
305                           token_getmad($3,innerop,'(');
306                           token_getmad($6,innerop,')');
307                         }
308         |       label FOR MY remember my_scalar '(' mexpr ')' mblock cont
309                         { OP *innerop;
310                           $$ = block_end($4,
311                              innerop = newFOROP(0, ($1)->tk_lval.pval, (line_t)($2)->tk_lval.ival, $5, $7, $9, $10));
312                           token_getmad($1,((LISTOP*)innerop)->op_first,'L');
313                           token_getmad($2,((LISTOP*)innerop)->op_first->op_sibling,'W');
314                           token_getmad($3,((LISTOP*)innerop)->op_first->op_sibling,'d');
315                           token_getmad($6,((LISTOP*)innerop)->op_first->op_sibling,'(');
316                           token_getmad($8,((LISTOP*)innerop)->op_first->op_sibling,')');
317                         }
318         |       label FOR scalar '(' remember mexpr ')' mblock cont
319                         { OP *innerop;
320                           $$ = block_end($5,
321                              innerop = newFOROP(0, ($1)->tk_lval.pval, (line_t)($2)->tk_lval.ival, mod($3, OP_ENTERLOOP),
322                                           $6, $8, $9));
323                           token_getmad($1,((LISTOP*)innerop)->op_first,'L');
324                           token_getmad($2,((LISTOP*)innerop)->op_first->op_sibling,'W');
325                           token_getmad($4,((LISTOP*)innerop)->op_first->op_sibling,'(');
326                           token_getmad($7,((LISTOP*)innerop)->op_first->op_sibling,')');
327                         }
328         |       label FOR '(' remember mexpr ')' mblock cont
329                         { OP *innerop;
330                           $$ = block_end($4,
331                              innerop = newFOROP(0, ($1)->tk_lval.pval, (line_t)($2)->tk_lval.ival, Nullop, $5, $7, $8));
332                           token_getmad($1,((LISTOP*)innerop)->op_first,'L');
333                           token_getmad($2,((LISTOP*)innerop)->op_first->op_sibling,'W');
334                           token_getmad($3,((LISTOP*)innerop)->op_first->op_sibling,'(');
335                           token_getmad($6,((LISTOP*)innerop)->op_first->op_sibling,')');
336                         }
337         |       label FOR '(' remember mnexpr ';' texpr ';' mintro mnexpr ')'
338                     mblock
339                         /* basically fake up an initialize-while lineseq */
340                         { OP *forop;
341                           PL_copline = (line_t)($2)->tk_lval.ival;
342                           forop = newSTATEOP(0, ($1)->tk_lval.pval,
343                                             newWHILEOP(0, 1, (LOOP*)Nullop,
344                                                 ($2)->tk_lval.ival, scalar($7),
345                                                 $12, $10, $9));
346                           if (!$5)
347                                 $5 = newOP(OP_NULL, 0);
348                           forop = newUNOP(OP_NULL, 0, append_elem(OP_LINESEQ,
349                                 newSTATEOP(0,
350                                            (($1)->tk_lval.pval
351                                            ?savepv(($1)->tk_lval.pval):Nullch),
352                                            $5),
353                                 forop));
354
355                           token_getmad($2,forop,'3');
356                           token_getmad($3,forop,'(');
357                           token_getmad($6,forop,'1');
358                           token_getmad($8,forop,'2');
359                           token_getmad($11,forop,')');
360                           token_getmad($1,forop,'L');
361                           $$ = block_end($4, forop); }
362         |       label block cont  /* a block is a loop that happens once */
363                         { $$ = newSTATEOP(0, ($1)->tk_lval.pval,
364                                  newWHILEOP(0, 1, (LOOP*)Nullop,
365                                             NOLINE, Nullop, $2, $3, 0));
366                           token_getmad($1,((LISTOP*)$$)->op_first,'L'); }
367         ;
368
369 /* Switch blocks */
370 switch  :       label GIVEN '(' remember mydefsv mexpr ')' mblock
371                         { PL_copline = (line_t) $2;
372                             $$ = block_end($4,
373                                 newSTATEOP(0, ($1)->tk_lval.pval,
374                                     newGIVENOP($6, scope($8),
375                                         (PADOFFSET) $5) )); }
376         ;
377
378 /* determine whether there are any new my declarations */
379 mintro  :       /* NULL */
380                         { $$ = (PL_min_intro_pending &&
381                             PL_max_intro_pending >=  PL_min_intro_pending);
382                           intro_my(); }
383
384 /* Normal expression */
385 nexpr   :       /* NULL */
386                         { $$ = Nullop; }
387         |       sideff
388         ;
389
390 /* Boolean expression */
391 texpr   :       /* NULL means true */
392                         { YYSTYPE tmplval;
393                           (void)scan_num("1", &tmplval);
394                           $$ = tmplval.opval; }
395         |       expr
396         ;
397
398 /* Inverted boolean expression */
399 iexpr   :       expr
400                         { $$ = invert(scalar($1)); }
401         ;
402
403 /* Expression with its own lexical scope */
404 mexpr   :       expr
405                         { $$ = $1; intro_my(); }
406         ;
407
408 mnexpr  :       nexpr
409                         { $$ = $1; intro_my(); }
410         ;
411
412 miexpr  :       iexpr
413                         { $$ = $1; intro_my(); }
414         ;
415
416 /* Optional "MAIN:"-style loop labels */
417 label   :       /* empty */
418                         { YYSTYPE tmplval;
419                           tmplval.pval = Nullch;
420                           $$ = newTOKEN(OP_NULL, tmplval, 0); }
421         |       LABEL
422         ;
423
424 /* Some kind of declaration - just hang on peg in the parse tree */
425 decl    :       format
426                         { $$ = $1; }
427         |       subrout
428                         { $$ = $1; }
429         |       mysubrout
430                         { $$ = $1; }
431         |       package
432                         { $$ = $1; }
433         |       use
434                         { $$ = $1; }
435         |       peg
436                         { $$ = $1; }
437         ;
438
439 peg     :       PEG
440                         { $$ = newOP(OP_NULL,0);
441                           token_getmad($1,$$,'p');
442                         }
443         ;
444
445 format  :       FORMAT startformsub formname block
446                         { SvREFCNT_inc(PL_compcv);
447                           $$ = newFORM($2, $3, $4);
448                           prepend_madprops($1->tk_mad, $$, 'F');
449                           $1->tk_mad = 0;
450                           token_free($1);
451                         }
452         ;
453
454 formname:       WORD            { $$ = $1; }
455         |       /* NULL */      { $$ = Nullop; }
456         ;
457
458 /* Unimplemented "my sub foo { }" */
459 mysubrout:      MYSUB startsub subname proto subattrlist subbody
460                         { SvREFCNT_inc(PL_compcv);
461                           $$ = newMYSUB($2, $3, $4, $5, $6);
462                           token_getmad($1,$$,'d');
463                         }
464         ;
465
466 /* Subroutine definition */
467 subrout :       SUB startsub subname proto subattrlist subbody
468                         { SvREFCNT_inc(PL_compcv);
469                           OP* o = newSVOP(OP_ANONCODE, 0,
470                             (SV*)newATTRSUB($2, $3, $4, $5, $6));
471                           $$ = newOP(OP_NULL,0);
472                           op_getmad(o,$$,'&');
473                           op_getmad($3,$$,'n');
474                           op_getmad($4,$$,'s');
475                           op_getmad($5,$$,'a');
476                           token_getmad($1,$$,'d');
477                           append_madprops($6->op_madprop, $$, 0);
478                           $6->op_madprop = 0;
479                         }
480         ;
481
482 startsub:       /* NULL */      /* start a regular subroutine scope */
483                         { $$ = start_subparse(FALSE, 0);
484                             SAVEFREESV(PL_compcv); }
485
486         ;
487
488 startanonsub:   /* NULL */      /* start an anonymous subroutine scope */
489                         { $$ = start_subparse(FALSE, CVf_ANON);
490                             SAVEFREESV(PL_compcv); }
491         ;
492
493 startformsub:   /* NULL */      /* start a format subroutine scope */
494                         { $$ = start_subparse(TRUE, 0);
495                             SAVEFREESV(PL_compcv); }
496         ;
497
498 /* Name of a subroutine - must be a bareword, could be special */
499 subname :       WORD    { const char *const name = SvPV_nolen_const(((SVOP*)$1)->op_sv);
500                           if (strEQ(name, "BEGIN") || strEQ(name, "END")
501                               || strEQ(name, "INIT") || strEQ(name, "CHECK")
502                               || strEQ(name, "UNITCHECK"))
503                               CvSPECIAL_on(PL_compcv);
504                           $$ = $1; }
505         ;
506
507 /* Subroutine prototype */
508 proto   :       /* NULL */
509                         { $$ = Nullop; }
510         |       THING
511         ;
512
513 /* Optional list of subroutine attributes */
514 subattrlist:    /* NULL */
515                         { $$ = Nullop; }
516         |       COLONATTR THING
517                         { $$ = $2;
518                           token_getmad($1,$$,':');
519                         }
520         |       COLONATTR
521                         { $$ = newOP(OP_NULL, 0);
522                           token_getmad($1,$$,':');
523                         }
524         ;
525
526 /* List of attributes for a "my" variable declaration */
527 myattrlist:     COLONATTR THING
528                         { $$ = $2;
529                           token_getmad($1,$$,':');
530                         }
531         |       COLONATTR
532                         { $$ = newOP(OP_NULL, 0);
533                           token_getmad($1,$$,':');
534                         }
535         ;
536
537 /* Subroutine body - either null or a block */
538 subbody :       block   { $$ = $1; }
539         |       ';'     { $$ = newOP(OP_NULL,0); PL_expect = XSTATE;
540                           token_getmad($1,$$,';');
541                         }
542         ;
543
544 package :       PACKAGE WORD ';'
545                         { $$ = package($2);
546                           token_getmad($1,$$,'o');
547                           token_getmad($3,$$,';');
548                         }
549         ;
550
551 use     :       USE startsub
552                         { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
553                     WORD WORD listexpr ';'
554                         { SvREFCNT_inc(PL_compcv);
555                           $$ = utilize(($1)->tk_lval.ival, $2, $4, $5, $6);
556                           token_getmad($1,$$,'o');
557                           token_getmad($7,$$,';');
558                           if (PL_rsfp_filters && AvFILLp(PL_rsfp_filters) >= 0)
559                               append_madprops(newMADPROP('!', MAD_PV, "", 0), $$, 0);
560                         }
561         ;
562
563 /* Ordinary expressions; logical combinations */
564 expr    :       expr ANDOP expr
565                         { $$ = newLOGOP(OP_AND, 0, $1, $3);
566                           token_getmad($2,$$,'o');
567                         }
568         |       expr OROP expr
569                         { $$ = newLOGOP(($2)->tk_lval.ival, 0, $1, $3);
570                           token_getmad($2,$$,'o');
571                         }
572         |       expr DOROP expr
573                         { $$ = newLOGOP(OP_DOR, 0, $1, $3);
574                           token_getmad($2,$$,'o');
575                         }
576         |       argexpr %prec PREC_LOW
577         ;
578
579 /* Expressions are a list of terms joined by commas */
580 argexpr :       argexpr ','
581                         { OP* op = newNULLLIST();
582                           token_getmad($2,op,',');
583                           $$ = append_elem(OP_LIST, $1, op);
584                         }
585         |       argexpr ',' term
586                         { 
587                           $3 = newUNOP(OP_NULL, 0, $3);
588                           token_getmad($2,$3,',');
589                           $$ = append_elem(OP_LIST, $1, $3);
590                         }
591         |       term %prec PREC_LOW
592         ;
593
594 /* List operators */
595 listop  :       LSTOP indirob argexpr          /* print $fh @args */
596                         { $$ = convert(($1)->tk_lval.ival, OPf_STACKED,
597                                 prepend_elem(OP_LIST, newGVREF(($1)->tk_lval.ival,$2), $3) );
598                           token_getmad($1,$$,'o');
599                         }
600         |       FUNC '(' indirob expr ')'      /* print ($fh @args */
601                         { $$ = convert(($1)->tk_lval.ival, OPf_STACKED,
602                                 prepend_elem(OP_LIST, newGVREF(($1)->tk_lval.ival,$3), $4) );
603                           token_getmad($1,$$,'o');
604                           token_getmad($2,$$,'(');
605                           token_getmad($5,$$,')');
606                         }
607         |       term ARROW method '(' listexprcom ')' /* $foo->bar(list) */
608                         { $$ = convert(OP_ENTERSUB, OPf_STACKED,
609                                 append_elem(OP_LIST,
610                                     prepend_elem(OP_LIST, scalar($1), $5),
611                                     newUNOP(OP_METHOD, 0, $3)));
612                           token_getmad($2,$$,'A');
613                           token_getmad($4,$$,'(');
614                           token_getmad($6,$$,')');
615                         }
616         |       term ARROW method                     /* $foo->bar */
617                         { $$ = convert(OP_ENTERSUB, OPf_STACKED,
618                                 append_elem(OP_LIST, scalar($1),
619                                     newUNOP(OP_METHOD, 0, $3)));
620                           token_getmad($2,$$,'A');
621                         }
622         |       METHOD indirob listexpr              /* new Class @args */
623                         { $$ = convert(OP_ENTERSUB, OPf_STACKED,
624                                 append_elem(OP_LIST,
625                                     prepend_elem(OP_LIST, $2, $3),
626                                     newUNOP(OP_METHOD, 0, $1)));
627                         }
628         |       FUNCMETH indirob '(' listexprcom ')' /* method $object (@args) */
629                         { $$ = convert(OP_ENTERSUB, OPf_STACKED,
630                                 append_elem(OP_LIST,
631                                     prepend_elem(OP_LIST, $2, $4),
632                                     newUNOP(OP_METHOD, 0, $1)));
633                           token_getmad($3,$$,'(');
634                           token_getmad($5,$$,')');
635                         }
636         |       LSTOP listexpr                       /* print @args */
637                         { $$ = convert(($1)->tk_lval.ival, 0, $2);
638                           token_getmad($1,$$,'o');
639                         }
640         |       FUNC '(' listexprcom ')'             /* print (@args) */
641                         { $$ = convert(($1)->tk_lval.ival, 0, $3);
642                           token_getmad($1,$$,'o');
643                           token_getmad($2,$$,'(');
644                           token_getmad($4,$$,')');
645                         }
646         |       LSTOPSUB startanonsub block          /* map { foo } ... */
647                         { SvREFCNT_inc(PL_compcv);
648                           $3 = newANONATTRSUB($2, 0, Nullop, $3); }
649                     listexpr            %prec LSTOP  /* ... @bar */
650                         { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
651                                  append_elem(OP_LIST,
652                                    prepend_elem(OP_LIST, $3, $5), $1));
653                         }
654         ;
655
656 /* Names of methods. May use $object->$methodname */
657 method  :       METHOD
658         |       scalar
659         ;
660
661 /* Some kind of subscripted expression */
662 subscripted:    star '{' expr ';' '}'        /* *main::{something} */
663                         /* In this and all the hash accessors, ';' is
664                          * provided by the tokeniser */
665                         { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3));
666                             PL_expect = XOPERATOR;
667                           token_getmad($2,$$,'{');
668                           token_getmad($4,$$,';');
669                           token_getmad($5,$$,'}');
670                         }
671         |       scalar '[' expr ']'          /* $array[$element] */
672                         { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3));
673                           token_getmad($2,$$,'[');
674                           token_getmad($4,$$,']');
675                         }
676         |       term ARROW '[' expr ']'      /* somearef->[$element] */
677                         { $$ = newBINOP(OP_AELEM, 0,
678                                         ref(newAVREF($1),OP_RV2AV),
679                                         scalar($4));
680                           token_getmad($2,$$,'a');
681                           token_getmad($3,$$,'[');
682                           token_getmad($5,$$,']');
683                         }
684         |       subscripted '[' expr ']'    /* $foo->[$bar]->[$baz] */
685                         { $$ = newBINOP(OP_AELEM, 0,
686                                         ref(newAVREF($1),OP_RV2AV),
687                                         scalar($3));
688                           token_getmad($2,$$,'[');
689                           token_getmad($4,$$,']');
690                         }
691         |       scalar '{' expr ';' '}'    /* $foo->{bar();} */
692                         { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
693                             PL_expect = XOPERATOR;
694                           token_getmad($2,$$,'{');
695                           token_getmad($4,$$,';');
696                           token_getmad($5,$$,'}');
697                         }
698         |       term ARROW '{' expr ';' '}' /* somehref->{bar();} */
699                         { $$ = newBINOP(OP_HELEM, 0,
700                                         ref(newHVREF($1),OP_RV2HV),
701                                         jmaybe($4));
702                             PL_expect = XOPERATOR;
703                           token_getmad($2,$$,'a');
704                           token_getmad($3,$$,'{');
705                           token_getmad($5,$$,';');
706                           token_getmad($6,$$,'}');
707                         }
708         |       subscripted '{' expr ';' '}' /* $foo->[bar]->{baz;} */
709                         { $$ = newBINOP(OP_HELEM, 0,
710                                         ref(newHVREF($1),OP_RV2HV),
711                                         jmaybe($3));
712                             PL_expect = XOPERATOR;
713                           token_getmad($2,$$,'{');
714                           token_getmad($4,$$,';');
715                           token_getmad($5,$$,'}');
716                         }
717         |       term ARROW '(' ')'          /* $subref->() */
718                         { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
719                                    newCVREF(0, scalar($1)));
720                           token_getmad($2,$$,'a');
721                           token_getmad($3,$$,'(');
722                           token_getmad($4,$$,')');
723                         }
724         |       term ARROW '(' expr ')'     /* $subref->(@args) */
725                         { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
726                                    append_elem(OP_LIST, $4,
727                                        newCVREF(0, scalar($1))));
728                           token_getmad($2,$$,'a');
729                           token_getmad($3,$$,'(');
730                           token_getmad($5,$$,')');
731                         }
732
733         |       subscripted '(' expr ')'   /* $foo->{bar}->(@args) */
734                         { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
735                                    append_elem(OP_LIST, $3,
736                                                newCVREF(0, scalar($1))));
737                           token_getmad($2,$$,'(');
738                           token_getmad($4,$$,')');
739                         }
740         |       subscripted '(' ')'        /* $foo->{bar}->() */
741                         { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
742                                    newCVREF(0, scalar($1)));
743                           token_getmad($2,$$,'(');
744                           token_getmad($3,$$,')');
745                         }
746         |       '(' expr ')' '[' expr ']'            /* list slice */
747                         { $$ = newSLICEOP(0, $5, $2);
748                           token_getmad($1,$$,'(');
749                           token_getmad($3,$$,')');
750                           token_getmad($4,$$,'[');
751                           token_getmad($6,$$,']');
752                         }
753         |       '(' ')' '[' expr ']'                 /* empty list slice! */
754                         { $$ = newSLICEOP(0, $4, Nullop);
755                           token_getmad($1,$$,'(');
756                           token_getmad($2,$$,')');
757                           token_getmad($3,$$,'[');
758                           token_getmad($5,$$,']');
759                         }
760     ;
761
762 /* Binary operators between terms */
763 termbinop:      term ASSIGNOP term             /* $x = $y */
764                         { $$ = newASSIGNOP(OPf_STACKED, $1, ($2)->tk_lval.ival, $3);
765                           token_getmad($2,$$,'o');
766                         }
767         |       term POWOP term                        /* $x ** $y */
768                         { $$ = newBINOP(($2)->tk_lval.ival, 0, scalar($1), scalar($3));
769                           token_getmad($2,$$,'o');
770                         }
771         |       term MULOP term                        /* $x * $y, $x x $y */
772                         {   if (($2)->tk_lval.ival != OP_REPEAT)
773                                 scalar($1);
774                             $$ = newBINOP(($2)->tk_lval.ival, 0, $1, scalar($3));
775                           token_getmad($2,$$,'o');
776                         }
777         |       term ADDOP term                        /* $x + $y */
778                         { $$ = newBINOP(($2)->tk_lval.ival, 0, scalar($1), scalar($3));
779                           token_getmad($2,$$,'o');
780                         }
781         |       term SHIFTOP term                      /* $x >> $y, $x << $y */
782                         { $$ = newBINOP(($2)->tk_lval.ival, 0, scalar($1), scalar($3));
783                           token_getmad($2,$$,'o');
784                         }
785         |       term RELOP term                        /* $x > $y, etc. */
786                         { $$ = newBINOP(($2)->tk_lval.ival, 0, scalar($1), scalar($3));
787                           token_getmad($2,$$,'o');
788                         }
789         |       term EQOP term                         /* $x == $y, $x eq $y */
790                         { $$ = newBINOP(($2)->tk_lval.ival, 0, scalar($1), scalar($3));
791                           token_getmad($2,$$,'o');
792                         }
793         |       term BITANDOP term                     /* $x & $y */
794                         { $$ = newBINOP(($2)->tk_lval.ival, 0, scalar($1), scalar($3));
795                           token_getmad($2,$$,'o');
796                         }
797         |       term BITOROP term                      /* $x | $y */
798                         { $$ = newBINOP(($2)->tk_lval.ival, 0, scalar($1), scalar($3));
799                           token_getmad($2,$$,'o');
800                         }
801         |       term DOTDOT term                       /* $x..$y, $x...$y */
802                         { UNOP *op;
803                           $$ = newRANGE(($2)->tk_lval.ival, scalar($1), scalar($3));
804                           op = (UNOP*)$$;
805                           op = (UNOP*)op->op_first;     /* get to flop */
806                           op = (UNOP*)op->op_first;     /* get to flip */
807                           op = (UNOP*)op->op_first;     /* get to range */
808                           token_getmad($2,(OP*)op,'o');
809                         }
810         |       term ANDAND term                       /* $x && $y */
811                         { $$ = newLOGOP(OP_AND, 0, $1, $3);
812                           token_getmad($2,$$,'o');
813                         }
814         |       term OROR term                         /* $x || $y */
815                         { $$ = newLOGOP(OP_OR, 0, $1, $3);
816                           token_getmad($2,$$,'o');
817                         }
818         |       term DORDOR term                       /* $x // $y */
819                         { $$ = newLOGOP(OP_DOR, 0, $1, $3);
820                           token_getmad($2,$$,'o');
821                         }
822         |       term MATCHOP term                      /* $x =~ /$y/ */
823                         { $$ = bind_match(($2)->tk_lval.ival, $1, $3);
824                           if ($$->op_type == OP_NOT)
825                               token_getmad($2,((UNOP*)$$)->op_first,'~');
826                             else
827                               token_getmad($2,$$,'~');
828                         }
829     ;
830
831 /* Unary operators and terms */
832 termunop : '-' term %prec UMINUS                       /* -$x */
833                         { $$ = newUNOP(OP_NEGATE, 0, scalar($2));
834                           token_getmad($1,$$,'o');
835                         }
836         |       '+' term %prec UMINUS                  /* +$x */
837                         { $$ = newUNOP(OP_NULL, 0, $2);
838                           token_getmad($1,$$,'+');
839                         }
840         |       '!' term                               /* !$x */
841                         { $$ = newUNOP(OP_NOT, 0, scalar($2));
842                           token_getmad($1,$$,'o');
843                         }
844         |       '~' term                               /* ~$x */
845                         { $$ = newUNOP(OP_COMPLEMENT, 0, scalar($2));
846                           token_getmad($1,$$,'o');
847                         }
848         |       term POSTINC                           /* $x++ */
849                         { $$ = newUNOP(OP_POSTINC, 0,
850                                         mod(scalar($1), OP_POSTINC));
851                           token_getmad($2,$$,'o');
852                         }
853         |       term POSTDEC                           /* $x-- */
854                         { $$ = newUNOP(OP_POSTDEC, 0,
855                                         mod(scalar($1), OP_POSTDEC));
856                           token_getmad($2,$$,'o');
857                         }
858         |       PREINC term                            /* ++$x */
859                         { $$ = newUNOP(OP_PREINC, 0,
860                                         mod(scalar($2), OP_PREINC));
861                           token_getmad($1,$$,'o');
862                         }
863         |       PREDEC term                            /* --$x */
864                         { $$ = newUNOP(OP_PREDEC, 0,
865                                         mod(scalar($2), OP_PREDEC));
866                           token_getmad($1,$$,'o');
867                         }
868
869     ;
870
871 /* Constructors for anonymous data */
872 anonymous:      '[' expr ']'
873                         { $$ = newANONLIST($2);
874                           token_getmad($1,$$,'[');
875                           token_getmad($3,$$,']');
876                         }
877         |       '[' ']'
878                         { $$ = newANONLIST(Nullop);
879                           token_getmad($1,$$,'[');
880                           token_getmad($2,$$,']');
881                         }
882         |       HASHBRACK expr ';' '}'  %prec '(' /* { foo => "Bar" } */
883                         { $$ = newANONHASH($2);
884                           token_getmad($1,$$,'{');
885                           token_getmad($3,$$,';');
886                           token_getmad($4,$$,'}');
887                         }
888         |       HASHBRACK ';' '}'       %prec '(' /* { } (';' by tokener) */
889                         { $$ = newANONHASH(Nullop);
890                           token_getmad($1,$$,'{');
891                           token_getmad($2,$$,';');
892                           token_getmad($3,$$,'}');
893                         }
894         |       ANONSUB startanonsub proto subattrlist block    %prec '('
895                         { SvREFCNT_inc(PL_compcv);
896                           $$ = newANONATTRSUB($2, $3, $4, $5);
897                           token_getmad($1,$$,'o');
898                           op_getmad($3,$$,'s');
899                           op_getmad($4,$$,'a');
900                         }
901
902     ;
903
904 /* Things called with "do" */
905 termdo  :       DO term %prec UNIOP                     /* do $filename */
906                         { $$ = dofile($2, $1);
907                           token_getmad($1,$$,'o');
908                         }
909         |       DO block        %prec '('               /* do { code */
910                         { $$ = newUNOP(OP_NULL, OPf_SPECIAL, scope($2));
911                           token_getmad($1,$$,'D');
912                         }
913         |       DO WORD '(' ')'                         /* do somesub() */
914                         { $$ = newUNOP(OP_ENTERSUB,
915                             OPf_SPECIAL|OPf_STACKED,
916                             prepend_elem(OP_LIST,
917                                 scalar(newCVREF(
918                                     (OPpENTERSUB_AMPER<<8),
919                                     scalar($2)
920                                 )),Nullop)); dep();
921                           token_getmad($1,$$,'o');
922                           token_getmad($3,$$,'(');
923                           token_getmad($4,$$,')');
924                         }
925         |       DO WORD '(' expr ')'                    /* do somesub(@args) */
926                         { $$ = newUNOP(OP_ENTERSUB,
927                             OPf_SPECIAL|OPf_STACKED,
928                             append_elem(OP_LIST,
929                                 $4,
930                                 scalar(newCVREF(
931                                     (OPpENTERSUB_AMPER<<8),
932                                     scalar($2)
933                                 )))); dep();
934                           token_getmad($1,$$,'o');
935                           token_getmad($3,$$,'(');
936                           token_getmad($5,$$,')');
937                         }
938         |       DO scalar '(' ')'                      /* do $subref () */
939                         { $$ = newUNOP(OP_ENTERSUB, OPf_SPECIAL|OPf_STACKED,
940                             prepend_elem(OP_LIST,
941                                 scalar(newCVREF(0,scalar($2))), Nullop)); dep();
942                           token_getmad($1,$$,'o');
943                           token_getmad($3,$$,'(');
944                           token_getmad($4,$$,')');
945                         }
946         |       DO scalar '(' expr ')'                 /* do $subref (@args) */
947                         { $$ = newUNOP(OP_ENTERSUB, OPf_SPECIAL|OPf_STACKED,
948                             prepend_elem(OP_LIST,
949                                 $4,
950                                 scalar(newCVREF(0,scalar($2))))); dep();
951                           token_getmad($1,$$,'o');
952                           token_getmad($3,$$,'(');
953                           token_getmad($5,$$,')');
954                         }
955
956         ;
957
958 term    :       termbinop
959         |       termunop
960         |       anonymous
961         |       termdo
962         |       term '?' term ':' term
963                         { $$ = newCONDOP(0, $1, $3, $5);
964                           token_getmad($2,$$,'?');
965                           token_getmad($4,$$,':');
966                         }
967         |       REFGEN term                          /* \$x, \@y, \%z */
968                         { $$ = newUNOP(OP_REFGEN, 0, mod($2,OP_REFGEN));
969                           token_getmad($1,$$,'o');
970                         }
971         |       myattrterm      %prec UNIOP
972                         { $$ = $1; }
973         |       LOCAL term      %prec UNIOP
974                         { $$ = localize($2,($1)->tk_lval.ival);
975                           token_getmad($1,$$,'d');
976                         }
977         |       '(' expr ')'
978                         { $$ = sawparens(newUNOP(OP_NULL,0,$2));
979                           token_getmad($1,$$,'(');
980                           token_getmad($3,$$,')');
981                         }
982         |       '(' ')'
983                         { $$ = sawparens(newNULLLIST());
984                           token_getmad($1,$$,'(');
985                           token_getmad($2,$$,')');
986                         }
987         |       scalar  %prec '('
988                         { $$ = $1; }
989         |       star    %prec '('
990                         { $$ = $1; }
991         |       hsh     %prec '('
992                         { $$ = $1; }
993         |       ary     %prec '('
994                         { $$ = $1; }
995         |       arylen  %prec '('                    /* $#x, $#{ something } */
996                         { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
997         |       subscripted
998                         { $$ = $1; }
999         |       ary '[' expr ']'                     /* array slice */
1000                         { $$ = prepend_elem(OP_ASLICE,
1001                                 newOP(OP_PUSHMARK, 0),
1002                                     newLISTOP(OP_ASLICE, 0,
1003                                         list($3),
1004                                         ref($1, OP_ASLICE)));
1005                           token_getmad($2,$$,'[');
1006                           token_getmad($4,$$,']');
1007                         }
1008         |       ary '{' expr ';' '}'                 /* @hash{@keys} */
1009                         { $$ = prepend_elem(OP_HSLICE,
1010                                 newOP(OP_PUSHMARK, 0),
1011                                     newLISTOP(OP_HSLICE, 0,
1012                                         list($3),
1013                                         ref(oopsHV($1), OP_HSLICE)));
1014                             PL_expect = XOPERATOR;
1015                           token_getmad($2,$$,'{');
1016                           token_getmad($4,$$,';');
1017                           token_getmad($5,$$,'}');
1018                         }
1019         |       THING   %prec '('
1020                         { $$ = $1; }
1021         |       amper                                /* &foo; */
1022                         { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
1023         |       amper '(' ')'                        /* &foo() */
1024                         { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1));
1025                           token_getmad($2,$$,'(');
1026                           token_getmad($3,$$,')');
1027                         }
1028         |       amper '(' expr ')'                   /* &foo(@args) */
1029                         { OP* op;
1030                           $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1031                                 append_elem(OP_LIST, $3, scalar($1)));
1032                           op = $$;
1033                           if (op->op_type == OP_CONST) { /* defeat const fold */
1034                             op = (OP*)op->op_madprop->mad_val;
1035                           }
1036                           token_getmad($2,op,'(');
1037                           token_getmad($4,op,')');
1038                         }
1039         |       NOAMP WORD listexpr                  /* foo(@args) */
1040                         { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1041                             append_elem(OP_LIST, $3, scalar($2)));
1042                           token_getmad($1,$$,'o');
1043                         }
1044         |       LOOPEX  /* loop exiting command (goto, last, dump, etc) */
1045                         { $$ = newOP(($1)->tk_lval.ival, OPf_SPECIAL);
1046                             PL_hints |= HINT_BLOCK_SCOPE;
1047                           token_getmad($1,$$,'o');
1048                         }
1049         |       LOOPEX term
1050                         { $$ = newLOOPEX(($1)->tk_lval.ival,$2);
1051                           token_getmad($1,$$,'o');
1052                         }
1053         |       NOTOP argexpr                        /* not $foo */
1054                         { $$ = newUNOP(OP_NOT, 0, scalar($2));
1055                           token_getmad($1,$$,'o');
1056                         }
1057         |       UNIOP                                /* Unary op, $_ implied */
1058                         { $$ = newOP(($1)->tk_lval.ival, 0);
1059                           token_getmad($1,$$,'o');
1060                         }
1061         |       UNIOP block                          /* eval { foo }, I *think* */
1062                         { $$ = newUNOP(($1)->tk_lval.ival, 0, $2);
1063                           token_getmad($1,$$,'o');
1064                         }
1065         |       UNIOP term                           /* Unary op */
1066                         { $$ = newUNOP(($1)->tk_lval.ival, 0, $2);
1067                           token_getmad($1,$$,'o');
1068                         }
1069         |       REQUIRE                              /* require, $_ implied *//* FIMXE for MAD needed? */
1070                         { $$ = newOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0); }
1071         |       REQUIRE term                         /* require Foo *//* FIMXE for MAD needed? */
1072                         { $$ = newUNOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0, $2); }
1073         |       UNIOPSUB term                        /* Sub treated as unop */
1074                         { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1075                             append_elem(OP_LIST, $2, scalar($1))); }
1076         |       FUNC0                                /* Nullary operator */
1077                         { $$ = newOP(($1)->tk_lval.ival, 0);
1078                           token_getmad($1,$$,'o');
1079                         }
1080         |       FUNC0 '(' ')'
1081                         { $$ = newOP(($1)->tk_lval.ival, 0);
1082                           token_getmad($1,$$,'o');
1083                           token_getmad($2,$$,'(');
1084                           token_getmad($3,$$,')');
1085                         }
1086         |       FUNC0SUB                             /* Sub treated as nullop */
1087                         { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
1088                                 scalar($1)); }
1089         |       FUNC1 '(' ')'                        /* not () */
1090                         { $$ = newOP(($1)->tk_lval.ival, OPf_SPECIAL);
1091                           token_getmad($1,$$,'o');
1092                           token_getmad($2,$$,'(');
1093                           token_getmad($3,$$,')');
1094                         }
1095         |       FUNC1 '(' expr ')'                   /* not($foo) */
1096                         { $$ = newUNOP(($1)->tk_lval.ival, 0, $3);
1097                           token_getmad($1,$$,'o');
1098                           token_getmad($2,$$,'(');
1099                           token_getmad($4,$$,')');
1100                         }
1101         |       PMFUNC '(' argexpr ')'          /* m//, s///, tr/// */
1102                         { $$ = pmruntime($1, $3, 1);
1103                           token_getmad($2,$$,'(');
1104                           token_getmad($4,$$,')');
1105                         }
1106         |       WORD
1107         |       listop
1108         ;
1109
1110 /* "my" declarations, with optional attributes */
1111 myattrterm:     MY myterm myattrlist
1112                         { $$ = my_attrs($2,$3);
1113                           token_getmad($1,$$,'d');
1114                           append_madprops($3->op_madprop, $$, 'a');
1115                           $3->op_madprop = 0;
1116                         }
1117         |       MY myterm
1118                         { $$ = localize($2,($1)->tk_lval.ival);
1119                           token_getmad($1,$$,'d');
1120                         }
1121         ;
1122
1123 /* Things that can be "my"'d */
1124 myterm  :       '(' expr ')'
1125                         { $$ = sawparens($2);
1126                           token_getmad($1,$$,'(');
1127                           token_getmad($3,$$,')');
1128                         }
1129         |       '(' ')'
1130                         { $$ = sawparens(newNULLLIST());
1131                           token_getmad($1,$$,'(');
1132                           token_getmad($2,$$,')');
1133                         }
1134         |       scalar  %prec '('
1135                         { $$ = $1; }
1136         |       hsh     %prec '('
1137                         { $$ = $1; }
1138         |       ary     %prec '('
1139                         { $$ = $1; }
1140         ;
1141
1142 /* Basic list expressions */
1143 listexpr:       /* NULL */ %prec PREC_LOW
1144                         { $$ = Nullop; }
1145         |       argexpr    %prec PREC_LOW
1146                         { $$ = $1; }
1147         ;
1148
1149 listexprcom:    /* NULL */
1150                         { $$ = Nullop; }
1151         |       expr
1152                         { $$ = $1; }
1153         |       expr ','
1154                         { OP* op = newNULLLIST();
1155                           token_getmad($2,op,',');
1156                           $$ = append_elem(OP_LIST, $1, op);
1157                         }
1158         ;
1159
1160 /* A little bit of trickery to make "for my $foo (@bar)" actually be
1161    lexical */
1162 my_scalar:      scalar
1163                         { PL_in_my = 0; $$ = my($1); }
1164         ;
1165
1166 amper   :       '&' indirob
1167                         { $$ = newCVREF(($1)->tk_lval.ival,$2);
1168                           token_getmad($1,$$,'&');
1169                         }
1170         ;
1171
1172 scalar  :       '$' indirob
1173                         { $$ = newSVREF($2);
1174                           token_getmad($1,$$,'$');
1175                         }
1176         ;
1177
1178 ary     :       '@' indirob
1179                         { $$ = newAVREF($2);
1180                           token_getmad($1,$$,'@');
1181                         }
1182         ;
1183
1184 hsh     :       '%' indirob
1185                         { $$ = newHVREF($2);
1186                           token_getmad($1,$$,'%');
1187                         }
1188         ;
1189
1190 arylen  :       DOLSHARP indirob
1191                         { $$ = newAVREF($2);
1192                           token_getmad($1,$$,'l');
1193                         }
1194         ;
1195
1196 star    :       '*' indirob
1197                         { $$ = newGVREF(0,$2);
1198                           token_getmad($1,$$,'*');
1199                         }
1200         ;
1201
1202 /* Indirect objects */
1203 indirob :       WORD
1204                         { $$ = scalar($1); }
1205         |       scalar %prec PREC_LOW
1206                         { $$ = scalar($1); }
1207         |       block
1208                         { $$ = scope($1); }
1209
1210         |       PRIVATEREF
1211                         { $$ = $1; }
1212         ;