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