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