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