This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Correct OPf_SPECIAL/OP_UNSTACK comment
[perl5.git] / perly.y
CommitLineData
a0d0e21e 1/* perly.y
a687059c 2 *
f05e27e5 3 * Copyright (c) 1991-2002, 2003, 2004, 2005, 2006 Larry Wall
2eee27d7 4 * Copyright (c) 2007, 2008, 2009, 2010, 2011 by Larry Wall and others
a687059c 5 *
9ef589d8
LW
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.
8d063cd8 8 *
a0d0e21e
LW
9 */
10
11/*
12 * 'I see,' laughed Strider. 'I look foul and feel fair. Is that it?
4ac71550 13 * All that is gold does not glitter, not all those who wander are lost.'
f05e27e5 14 *
4ac71550
TC
15 * [p.171 of _The Lord of the Rings_, I/x: "Strider"]
16 */
17
18/*
f05e27e5 19 * This file holds the grammar for the Perl language. If edited, you need
166f8a29
DM
20 * to run regen_perly.pl, which re-creates the files perly.h, perly.tab
21 * and perly.act which are derived from this.
22 *
23 * The main job of of this grammar is to call the various newFOO()
24 * functions in op.c to build a syntax tree of OP structs.
61296642 25 * It relies on the lexer in toke.c to do the tokenizing.
29522234
DM
26 *
27 * Note: due to the way that the cleanup code works WRT to freeing ops on
28 * the parse stack, it is dangerous to assign to the $n variables within
29 * an action.
166f8a29
DM
30 */
31
0de566d7 32/* Make the parser re-entrant. */
8d063cd8 33
0de566d7 34%pure_parser
8d063cd8 35
28ac2b49 36%start grammar
9d116dd7 37
8d063cd8 38%union {
d5c6462e
DM
39 I32 ival; /* __DEFAULT__ (marker for regen_perly.pl;
40 must always be 1st union member) */
79072805
LW
41 char *pval;
42 OP *opval;
43 GV *gvval;
8d063cd8
LW
44}
45
78cdf107 46%token <ival> GRAMPROG GRAMEXPR GRAMBLOCK GRAMBARESTMT GRAMFULLSTMT GRAMSTMTSEQ
28ac2b49 47
b5bbe64a 48%token <ival> '{' '}' '[' ']' '-' '+' '$' '@' '%' '*' '&' ';' '=' '.'
f0fcb552 49
ea25a9b2 50%token <opval> WORD METHOD FUNCMETH THING PMFUNC PRIVATEREF QWLIST
7eb971ee 51%token <opval> FUNC0OP FUNC0SUB UNIOPSUB LSTOPSUB
88e1f1a2 52%token <opval> PLUGEXPR PLUGSTMT
b5bbe64a
JH
53%token <pval> LABEL
54%token <ival> FORMAT SUB ANONSUB PACKAGE USE
55%token <ival> WHILE UNTIL IF UNLESS ELSE ELSIF CONTINUE FOR
56%token <ival> GIVEN WHEN DEFAULT
57%token <ival> LOOPEX DOTDOT YADAYADA
58%token <ival> FUNC0 FUNC1 FUNC UNIOP LSTOP
59%token <ival> RELOP EQOP MULOP ADDOP
60%token <ival> DOLSHARP DO HASHBRACK NOAMP
61%token <ival> LOCAL MY REQUIRE
62%token <ival> COLONATTR FORMLBRACK FORMRBRACK
f05e27e5 63
727a8fe5 64%type <ival> grammar remember mremember
f05e27e5 65%type <ival> startsub startanonsub startformsub
b5bbe64a 66
b5a64814 67%type <ival> mintro
f05e27e5 68
8e720305 69%type <opval> stmtseq fullstmt labfullstmt barestmt block mblock else
fad39ff1 70%type <opval> expr term subscripted scalar ary hsh arylen star amper sideff
76eba8ab 71%type <opval> sliceme kvslice gelem
09b1cffe
Z
72%type <opval> listexpr nexpr texpr iexpr mexpr mnexpr miexpr
73%type <opval> optlistexpr optexpr indirob listop method
d39c26a6
FC
74%type <opval> formname subname proto optsubbody cont my_scalar my_var
75%type <opval> refgen_topic formblock
f05e27e5 76%type <opval> subattrlist myattrlist myattrterm myterm
30d9c59b 77%type <opval> realsubbody subsignature termbinop termunop anonymous termdo
705fe0e5 78%type <opval> formstmtseq formline formarg
79072805 79
b5bbe64a 80%nonassoc <ival> PREC_LOW
fad39ff1
SM
81%nonassoc LOOPEX
82
b5bbe64a
JH
83%left <ival> OROP DOROP
84%left <ival> ANDOP
85%right <ival> NOTOP
36477c24 86%nonassoc LSTOP LSTOPSUB
b5bbe64a
JH
87%left <ival> ','
88%right <ival> ASSIGNOP
89%right <ival> '?' ':'
be25f609 90%nonassoc DOTDOT YADAYADA
b5bbe64a
JH
91%left <ival> OROR DORDOR
92%left <ival> ANDAND
93%left <ival> BITOROP
94%left <ival> BITANDOP
a687059c
LW
95%nonassoc EQOP
96%nonassoc RELOP
36477c24 97%nonassoc UNIOP UNIOPSUB
20515881 98%nonassoc REQUIRE
b5bbe64a 99%left <ival> SHIFTOP
a687059c
LW
100%left ADDOP
101%left MULOP
b5bbe64a
JH
102%left <ival> MATCHOP
103%right <ival> '!' '~' UMINUS REFGEN
104%right <ival> POWOP
105%nonassoc <ival> PREINC PREDEC POSTINC POSTDEC POSTJOIN
106%left <ival> ARROW
107%nonassoc <ival> ')'
108%left <ival> '('
fad39ff1 109%left '[' '{'
8d063cd8
LW
110
111%% /* RULES */
112
28ac2b49 113/* Top-level choice of what kind of thing yyparse was called to parse */
727a8fe5
Z
114grammar : GRAMPROG
115 {
624fa8bd 116 parser->expect = XSTATE;
727a8fe5
Z
117 }
118 remember stmtseq
119 {
120 newPROG(block_end($3,$4));
8635e3c2 121 PL_compiling.cop_seq = 0;
727a8fe5
Z
122 $$ = 0;
123 }
78cdf107
Z
124 | GRAMEXPR
125 {
126 parser->expect = XTERM;
127 }
09b1cffe 128 optexpr
78cdf107
Z
129 {
130 PL_eval_root = $3;
131 $$ = 0;
132 }
e53d8f76
Z
133 | GRAMBLOCK
134 {
135 parser->expect = XBLOCK;
136 }
137 block
138 {
5f211341 139 PL_pad_reset_pending = TRUE;
8359b381
Z
140 PL_eval_root = $3;
141 $$ = 0;
142 yyunlex();
143 parser->yychar = YYEOF;
144 }
145 | GRAMBARESTMT
146 {
147 parser->expect = XSTATE;
148 }
149 barestmt
150 {
151 PL_pad_reset_pending = TRUE;
e53d8f76
Z
152 PL_eval_root = $3;
153 $$ = 0;
154 yyunlex();
155 parser->yychar = YYEOF;
156 }
9eb5c532 157 | GRAMFULLSTMT
28ac2b49 158 {
9eb5c532
Z
159 parser->expect = XSTATE;
160 }
161 fullstmt
162 {
5f211341 163 PL_pad_reset_pending = TRUE;
9eb5c532 164 PL_eval_root = $3;
28ac2b49
Z
165 $$ = 0;
166 yyunlex();
167 parser->yychar = YYEOF;
168 }
07ffcb73
Z
169 | GRAMSTMTSEQ
170 {
171 parser->expect = XSTATE;
172 }
5f211341 173 stmtseq
07ffcb73
Z
174 {
175 PL_eval_root = $3;
176 $$ = 0;
177 }
178 ;
179
891be019 180/* An ordinary block */
5f211341 181block : '{' remember stmtseq '}'
624fa8bd
FC
182 { if (parser->copline > (line_t)$1)
183 parser->copline = (line_t)$1;
f05e27e5 184 $$ = block_end($2, $3);
f05e27e5 185 }
a0d0e21e
LW
186 ;
187
7c70caa5 188/* format body */
705fe0e5 189formblock: '=' remember ';' FORMRBRACK formstmtseq ';' '.'
624fa8bd
FC
190 { if (parser->copline > (line_t)$1)
191 parser->copline = (line_t)$1;
705fe0e5 192 $$ = block_end($2, $5);
7c70caa5
FC
193 }
194 ;
195
55497cff 196remember: /* NULL */ /* start a full lexical scope */
34b54951
FC
197 { $$ = block_start(TRUE);
198 parser->parsed_sub = 0; }
55497cff
PP
199 ;
200
5f211341 201mblock : '{' mremember stmtseq '}'
624fa8bd
FC
202 { if (parser->copline > (line_t)$1)
203 parser->copline = (line_t)$1;
f05e27e5 204 $$ = block_end($2, $3);
f05e27e5 205 }
55497cff
PP
206 ;
207
208mremember: /* NULL */ /* start a partial lexical scope */
34b54951
FC
209 { $$ = block_start(FALSE);
210 parser->parsed_sub = 0; }
8d063cd8
LW
211 ;
212
eae48c89 213/* A sequence of statements in the program */
5f211341 214stmtseq : /* NULL */
bcabcc50 215 { $$ = (OP*)NULL; }
5f211341 216 | stmtseq fullstmt
2fcb4757 217 { $$ = op_append_list(OP_LINESEQ, $1, $2);
3280af22 218 PL_pad_reset_pending = TRUE;
503de470
DM
219 if ($1 && $2)
220 PL_hints |= HINT_BLOCK_SCOPE;
221 }
8d063cd8
LW
222 ;
223
705fe0e5
FC
224/* A sequence of format lines */
225formstmtseq: /* NULL */
226 { $$ = (OP*)NULL; }
227 | formstmtseq formline
228 { $$ = op_append_list(OP_LINESEQ, $1, $2);
229 PL_pad_reset_pending = TRUE;
230 if ($1 && $2)
231 PL_hints |= HINT_BLOCK_SCOPE;
232 }
233 ;
234
8e720305
Z
235/* A statement in the program, including optional labels */
236fullstmt: barestmt
eae48c89 237 {
b5bbe64a 238 $$ = $1 ? newSTATEOP(0, NULL, $1) : NULL;
eae48c89 239 }
8e720305
Z
240 | labfullstmt
241 { $$ = $1; }
242 ;
243
244labfullstmt: LABEL barestmt
245 {
b5bbe64a 246 $$ = newSTATEOP(SVf_UTF8 * $1[strlen($1)+1], $1, $2);
8e720305
Z
247 }
248 | LABEL labfullstmt
249 {
b5bbe64a 250 $$ = newSTATEOP(SVf_UTF8 * $1[strlen($1)+1], $1, $2);
8e720305 251 }
eae48c89
Z
252 ;
253
254/* A bare statement, lacking label and other aspects of state op */
255barestmt: PLUGSTMT
0d863452 256 { $$ = $1; }
7c70caa5 257 | FORMAT startformsub formname formblock
f05e27e5 258 {
eae48c89 259 CV *fmtcv = PL_compcv;
eae48c89
Z
260 newFORM($2, $3, $4);
261 $$ = (OP*)NULL;
4a273b91 262 if (CvOUTSIDE(fmtcv) && !CvEVAL(CvOUTSIDE(fmtcv))) {
eae48c89 263 SvREFCNT_inc_simple_void(fmtcv);
cc76b5cc 264 pad_add_anon(fmtcv, OP_NULL);
f05e27e5 265 }
eae48c89 266 }
50278755
FC
267 | SUB subname startsub
268 {
269 if ($2->op_type == OP_CONST) {
270 const char *const name =
271 SvPV_nolen_const(((SVOP*)$2)->op_sv);
272 if (strEQ(name, "BEGIN") || strEQ(name, "END")
764212cf
FC
273 || strEQ(name, "INIT") || strEQ(name, "CHECK")
274 || strEQ(name, "UNITCHECK"))
275 CvSPECIAL_on(PL_compcv);
50278755 276 }
e07561e6
FC
277 else
278 /* State subs inside anonymous subs need to be
279 clonable themselves. */
6d5c2147
FC
280 if (CvANON(CvOUTSIDE(PL_compcv))
281 || CvCLONE(CvOUTSIDE(PL_compcv))
282 || !PadnameIsSTATE(PadlistNAMESARRAY(CvPADLIST(
283 CvOUTSIDE(PL_compcv)
284 ))[$2->op_targ]))
e07561e6 285 CvCLONE_on(PL_compcv);
624fa8bd
FC
286 parser->in_my = 0;
287 parser->in_my_stash = NULL;
764212cf 288 }
30d9c59b 289 proto subattrlist optsubbody
eae48c89
Z
290 {
291 SvREFCNT_inc_simple_void(PL_compcv);
50278755
FC
292 $2->op_type == OP_CONST
293 ? newATTRSUB($3, $2, $5, $6, $7)
294 : newMYSUB($3, $2, $5, $6, $7)
50278755 295 ;
eae48c89 296 $$ = (OP*)NULL;
764212cf 297 intro_my();
34b54951 298 parser->parsed_sub = 1;
f05e27e5 299 }
eae48c89 300 | PACKAGE WORD WORD ';'
5f211341 301 {
eae48c89
Z
302 package($3);
303 if ($2)
304 package_version($2);
305 $$ = (OP*)NULL;
eae48c89
Z
306 }
307 | USE startsub
308 { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
09b1cffe 309 WORD WORD optlistexpr ';'
eae48c89
Z
310 {
311 SvREFCNT_inc_simple_void(PL_compcv);
b5bbe64a 312 utilize($1, $2, $4, $5, $6);
34b54951 313 parser->parsed_sub = 1;
eae48c89 314 $$ = (OP*)NULL;
eae48c89 315 }
417a992d 316 | IF '(' remember mexpr ')' mblock else
eae48c89 317 {
3ad73efd
Z
318 $$ = block_end($3,
319 newCONDOP(0, $4, op_scope($6), $7));
624fa8bd 320 parser->copline = (line_t)$1;
eae48c89 321 }
417a992d 322 | UNLESS '(' remember miexpr ')' mblock else
eae48c89 323 {
3ad73efd
Z
324 $$ = block_end($3,
325 newCONDOP(0, $4, op_scope($6), $7));
624fa8bd 326 parser->copline = (line_t)$1;
eae48c89 327 }
b5a64814 328 | GIVEN '(' remember mexpr ')' mblock
eae48c89 329 {
b5a64814 330 const PADOFFSET offset = pad_findmy_pvs("$_", 0);
eae48c89 331 $$ = block_end($3,
b5a64814
FC
332 newGIVENOP($4, op_scope($6),
333 offset == NOT_IN_PAD
334 || PAD_COMPNAME_FLAGS_isOUR(offset)
335 ? 0
336 : offset));
624fa8bd 337 parser->copline = (line_t)$1;
eae48c89 338 }
417a992d 339 | WHEN '(' remember mexpr ')' mblock
3ad73efd 340 { $$ = block_end($3, newWHENOP($4, op_scope($6))); }
eae48c89 341 | DEFAULT block
3ad73efd 342 { $$ = newWHENOP(0, op_scope($2)); }
417a992d 343 | WHILE '(' remember texpr ')' mintro mblock cont
eae48c89
Z
344 {
345 $$ = block_end($3,
346 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
94bf0465 347 $4, $7, $8, $6));
624fa8bd 348 parser->copline = (line_t)$1;
eae48c89 349 }
417a992d 350 | UNTIL '(' remember iexpr ')' mintro mblock cont
eae48c89
Z
351 {
352 $$ = block_end($3,
94bf0465
Z
353 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
354 $4, $7, $8, $6));
624fa8bd 355 parser->copline = (line_t)$1;
eae48c89 356 }
2d0e3c96
FC
357 | FOR '(' remember mnexpr ';'
358 { parser->expect = XTERM; }
359 texpr ';'
360 { parser->expect = XTERM; }
361 mintro mnexpr ')'
eae48c89
Z
362 mblock
363 {
b5bbe64a 364 OP *initop = $4;
eae48c89 365 OP *forop = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
2d0e3c96 366 scalar($7), $13, $11, $10);
eae48c89
Z
367 if (initop) {
368 forop = op_prepend_elem(OP_LINESEQ, initop,
369 op_append_elem(OP_LINESEQ,
370 newOP(OP_UNSTACK, OPf_SPECIAL),
371 forop));
5f211341 372 }
eae48c89 373 $$ = block_end($3, forop);
624fa8bd 374 parser->copline = (line_t)$1;
eae48c89 375 }
417a992d 376 | FOR MY remember my_scalar '(' mexpr ')' mblock cont
eae48c89 377 {
94bf0465 378 $$ = block_end($3, newFOROP(0, $4, $6, $8, $9));
624fa8bd 379 parser->copline = (line_t)$1;
eae48c89 380 }
417a992d 381 | FOR scalar '(' remember mexpr ')' mblock cont
eae48c89 382 {
94bf0465 383 $$ = block_end($4, newFOROP(0,
3ad73efd 384 op_lvalue($2, OP_ENTERLOOP), $5, $7, $8));
624fa8bd 385 parser->copline = (line_t)$1;
eae48c89 386 }
d39c26a6
FC
387 | FOR REFGEN MY remember my_var
388 { parser->in_my = 0; $<opval>$ = my($5); }
389 '(' mexpr ')' mblock cont
390 {
391 $$ = block_end(
392 $4,
393 newFOROP(0,
394 op_lvalue(
395 newUNOP(OP_REFGEN, 0,
96801525 396 $<opval>6),
d39c26a6
FC
397 OP_ENTERLOOP),
398 $8, $10, $11)
399 );
400 parser->copline = (line_t)$1;
401 }
402 | FOR REFGEN refgen_topic '(' remember mexpr ')' mblock cont
403 {
404 $$ = block_end($5, newFOROP(
405 0, op_lvalue(newUNOP(OP_REFGEN, 0,
96801525 406 $3),
d39c26a6
FC
407 OP_ENTERLOOP), $6, $8, $9));
408 parser->copline = (line_t)$1;
409 }
417a992d 410 | FOR '(' remember mexpr ')' mblock cont
eae48c89
Z
411 {
412 $$ = block_end($3,
94bf0465 413 newFOROP(0, (OP*)NULL, $4, $6, $7));
624fa8bd 414 parser->copline = (line_t)$1;
eae48c89
Z
415 }
416 | block cont
417 {
418 /* a block is a loop that happens once */
419 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
94bf0465 420 (OP*)NULL, $1, $2, 0);
eae48c89
Z
421 }
422 | PACKAGE WORD WORD '{' remember
423 {
eae48c89 424 package($3);
eae48c89 425 if ($2) {
eae48c89 426 package_version($2);
eae48c89
Z
427 }
428 }
429 stmtseq '}'
430 {
431 /* a block is a loop that happens once */
94bf0465 432 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
eae48c89 433 (OP*)NULL, block_end($5, $7), (OP*)NULL, 0);
624fa8bd
FC
434 if (parser->copline > (line_t)$4)
435 parser->copline = (line_t)$4;
eae48c89
Z
436 }
437 | sideff ';'
438 {
eae48c89 439 $$ = $1;
eae48c89
Z
440 }
441 | ';'
442 {
b5bbe64a 443 $$ = (OP*)NULL;
624fa8bd 444 parser->copline = NOLINE;
5f211341 445 }
8d063cd8
LW
446 ;
447
705fe0e5
FC
448/* Format line */
449formline: THING formarg
450 { OP *list;
451 if ($2) {
452 OP *term = $2;
705fe0e5
FC
453 list = op_append_elem(OP_LIST, $1, term);
454 }
455 else {
705fe0e5 456 list = $1;
705fe0e5 457 }
624fa8bd
FC
458 if (parser->copline == NOLINE)
459 parser->copline = CopLINE(PL_curcop)-1;
460 else parser->copline--;
705fe0e5 461 $$ = newSTATEOP(0, NULL,
03d05f6e 462 op_convert_list(OP_FORMLINE, 0, list));
705fe0e5
FC
463 }
464 ;
465
466formarg : /* NULL */
467 { $$ = NULL; }
468 | FORMLBRACK stmtseq FORMRBRACK
469 { $$ = op_unscope($2); }
470 ;
471
891be019 472/* An expression which may have a side-effect */
a687059c 473sideff : error
bcabcc50 474 { $$ = (OP*)NULL; }
a687059c 475 | expr
79072805 476 { $$ = $1; }
a687059c 477 | expr IF expr
b5bbe64a 478 { $$ = newLOGOP(OP_AND, 0, $3, $1); }
a687059c 479 | expr UNLESS expr
b5bbe64a 480 { $$ = newLOGOP(OP_OR, 0, $3, $1); }
a687059c 481 | expr WHILE expr
b5bbe64a 482 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); }
55497cff 483 | expr UNTIL iexpr
b5bbe64a 484 { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1); }
ecca16b0 485 | expr FOR expr
94bf0465 486 { $$ = newFOROP(0, (OP*)NULL, $3, $1, (OP*)NULL);
624fa8bd 487 parser->copline = (line_t)$2; }
f20dcd76 488 | expr WHEN expr
3ad73efd 489 { $$ = newWHENOP($3, op_scope($1)); }
79072805
LW
490 ;
491
891be019 492/* else and elsif blocks */
79072805 493else : /* NULL */
bcabcc50 494 { $$ = (OP*)NULL; }
55497cff 495 | ELSE mblock
3ad73efd
Z
496 {
497 ($2)->op_flags |= OPf_PARENS;
498 $$ = op_scope($2);
f05e27e5 499 }
417a992d 500 | ELSIF '(' mexpr ')' mblock else
624fa8bd 501 { parser->copline = (line_t)$1;
3ad73efd
Z
502 $$ = newCONDOP(0,
503 newSTATEOP(OPf_SPECIAL,NULL,$3),
504 op_scope($5), $6);
505 PL_hints |= HINT_BLOCK_SCOPE;
f05e27e5 506 }
79072805
LW
507 ;
508
891be019 509/* Continue blocks */
79072805 510cont : /* NULL */
bcabcc50 511 { $$ = (OP*)NULL; }
79072805 512 | CONTINUE block
b5bbe64a 513 { $$ = op_scope($2); }
79072805
LW
514 ;
515
a034e688
DM
516/* determine whether there are any new my declarations */
517mintro : /* NULL */
518 { $$ = (PL_min_intro_pending &&
519 PL_max_intro_pending >= PL_min_intro_pending);
520 intro_my(); }
521
891be019 522/* Normal expression */
8d063cd8 523nexpr : /* NULL */
bcabcc50 524 { $$ = (OP*)NULL; }
8d063cd8
LW
525 | sideff
526 ;
527
891be019 528/* Boolean expression */
8d063cd8 529texpr : /* NULL means true */
f05e27e5
DM
530 { YYSTYPE tmplval;
531 (void)scan_num("1", &tmplval);
532 $$ = tmplval.opval; }
8d063cd8
LW
533 | expr
534 ;
535
891be019 536/* Inverted boolean expression */
55497cff
PP
537iexpr : expr
538 { $$ = invert(scalar($1)); }
539 ;
540
891be019 541/* Expression with its own lexical scope */
55497cff 542mexpr : expr
bbce6d69
PP
543 { $$ = $1; intro_my(); }
544 ;
545
546mnexpr : nexpr
547 { $$ = $1; intro_my(); }
55497cff
PP
548 ;
549
55497cff 550miexpr : iexpr
bbce6d69 551 { $$ = $1; intro_my(); }
55497cff
PP
552 ;
553
44a8e56a 554formname: WORD { $$ = $1; }
bcabcc50 555 | /* NULL */ { $$ = (OP*)NULL; }
8d063cd8
LW
556 ;
557
fa83b5b6 558startsub: /* NULL */ /* start a regular subroutine scope */
a8ff2fa6
DM
559 { $$ = start_subparse(FALSE, 0);
560 SAVEFREESV(PL_compcv); }
f05e27e5 561
28757baa
PP
562 ;
563
564startanonsub: /* NULL */ /* start an anonymous subroutine scope */
a8ff2fa6
DM
565 { $$ = start_subparse(FALSE, CVf_ANON);
566 SAVEFREESV(PL_compcv); }
28757baa
PP
567 ;
568
44a8e56a 569startformsub: /* NULL */ /* start a format subroutine scope */
a8ff2fa6
DM
570 { $$ = start_subparse(TRUE, 0);
571 SAVEFREESV(PL_compcv); }
44a8e56a
PP
572 ;
573
891be019 574/* Name of a subroutine - must be a bareword, could be special */
50278755 575subname : WORD
4210d3f1 576 | PRIVATEREF
a0d0e21e
LW
577 ;
578
891be019 579/* Subroutine prototype */
4633a7c4 580proto : /* NULL */
bcabcc50 581 { $$ = (OP*)NULL; }
4633a7c4
LW
582 | THING
583 ;
28757baa 584
891be019 585/* Optional list of subroutine attributes */
09bef843 586subattrlist: /* NULL */
bcabcc50 587 { $$ = (OP*)NULL; }
09bef843 588 | COLONATTR THING
b5bbe64a 589 { $$ = $2; }
09bef843 590 | COLONATTR
b5bbe64a 591 { $$ = (OP*)NULL; }
09bef843
SB
592 ;
593
891be019 594/* List of attributes for a "my" variable declaration */
09bef843 595myattrlist: COLONATTR THING
b5bbe64a 596 { $$ = $2; }
09bef843 597 | COLONATTR
b5bbe64a 598 { $$ = (OP*)NULL; }
09bef843
SB
599 ;
600
30d9c59b
Z
601/* Optional subroutine signature */
602subsignature: /* NULL */ { $$ = (OP*)NULL; }
603 | '('
604 {
605 if (!FEATURE_SIGNATURES_IS_ENABLED)
606 Perl_croak(aTHX_ "Experimental "
607 "subroutine signatures not enabled");
608 Perl_ck_warner_d(aTHX_
609 packWARN(WARN_EXPERIMENTAL__SIGNATURES),
610 "The signatures feature is experimental");
611 $<opval>$ = parse_subsignature();
612 }
613 ')'
614 {
615 $$ = op_append_list(OP_LINESEQ, $<opval>2,
616 newSTATEOP(0, NULL, sawparens(newNULLLIST())));
624fa8bd 617 parser->expect = XBLOCK;
30d9c59b
Z
618 }
619 ;
620
621/* Subroutine body - block with optional signature */
622realsubbody: remember subsignature '{' stmtseq '}'
623 {
624fa8bd
FC
624 if (parser->copline > (line_t)$3)
625 parser->copline = (line_t)$3;
30d9c59b
Z
626 $$ = block_end($1,
627 op_append_list(OP_LINESEQ, $2, $4));
30d9c59b
Z
628 }
629 ;
630
631/* Optional subroutine body, for named subroutine declaration */
632optsubbody: realsubbody { $$ = $1; }
2d0e3c96 633 | ';' { $$ = (OP*)NULL; }
8d063cd8
LW
634 ;
635
891be019 636/* Ordinary expressions; logical combinations */
a0d0e21e 637expr : expr ANDOP expr
b5bbe64a 638 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
a0d0e21e 639 | expr OROP expr
b5bbe64a 640 { $$ = newLOGOP($2, 0, $1, $3); }
c963b151 641 | expr DOROP expr
b5bbe64a 642 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
09b1cffe 643 | listexpr %prec PREC_LOW
a0d0e21e
LW
644 ;
645
891be019 646/* Expressions are a list of terms joined by commas */
09b1cffe 647listexpr: listexpr ','
b5bbe64a 648 { $$ = $1; }
09b1cffe 649 | listexpr ',' term
f05e27e5 650 {
29522234 651 OP* term = $3;
2fcb4757 652 $$ = op_append_elem(OP_LIST, $1, term);
f05e27e5 653 }
fad39ff1 654 | term %prec PREC_LOW
8d063cd8
LW
655 ;
656
891be019 657/* List operators */
09b1cffe 658listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
03d05f6e 659 { $$ = op_convert_list($1, OPf_STACKED,
b5bbe64a 660 op_prepend_elem(OP_LIST, newGVREF($1,$2), $3) );
f05e27e5 661 }
891be019 662 | FUNC '(' indirob expr ')' /* print ($fh @args */
03d05f6e 663 { $$ = op_convert_list($1, OPf_STACKED,
b5bbe64a 664 op_prepend_elem(OP_LIST, newGVREF($1,$3), $4) );
f05e27e5 665 }
417a992d 666 | term ARROW method '(' optexpr ')' /* $foo->bar(list) */
03d05f6e 667 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757
Z
668 op_append_elem(OP_LIST,
669 op_prepend_elem(OP_LIST, scalar($1), $5),
b46e009d 670 newMETHOP(OP_METHOD, 0, $3)));
f05e27e5 671 }
891be019 672 | term ARROW method /* $foo->bar */
03d05f6e 673 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757 674 op_append_elem(OP_LIST, scalar($1),
b46e009d 675 newMETHOP(OP_METHOD, 0, $3)));
f05e27e5 676 }
09b1cffe 677 | METHOD indirob optlistexpr /* new Class @args */
03d05f6e 678 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757
Z
679 op_append_elem(OP_LIST,
680 op_prepend_elem(OP_LIST, $2, $3),
b46e009d 681 newMETHOP(OP_METHOD, 0, $1)));
f05e27e5 682 }
09b1cffe 683 | FUNCMETH indirob '(' optexpr ')' /* method $object (@args) */
03d05f6e 684 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757
Z
685 op_append_elem(OP_LIST,
686 op_prepend_elem(OP_LIST, $2, $4),
b46e009d 687 newMETHOP(OP_METHOD, 0, $1)));
f05e27e5 688 }
09b1cffe 689 | LSTOP optlistexpr /* print @args */
03d05f6e 690 { $$ = op_convert_list($1, 0, $2); }
09b1cffe 691 | FUNC '(' optexpr ')' /* print (@args) */
03d05f6e 692 { $$ = op_convert_list($1, 0, $3); }
718a7425 693 | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */
5a5094bd 694 { SvREFCNT_inc_simple_void(PL_compcv);
bcabcc50 695 $<opval>$ = newANONATTRSUB($2, 0, (OP*)NULL, $3); }
09b1cffe 696 optlistexpr %prec LSTOP /* ... @bar */
4633a7c4 697 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757
Z
698 op_append_elem(OP_LIST,
699 op_prepend_elem(OP_LIST, $<opval>4, $5), $1));
f05e27e5 700 }
a687059c
LW
701 ;
702
891be019 703/* Names of methods. May use $object->$methodname */
a0d0e21e
LW
704method : METHOD
705 | scalar
706 ;
707
891be019 708/* Some kind of subscripted expression */
89f35911 709subscripted: gelem '{' expr ';' '}' /* *main::{something} */
891be019
SC
710 /* In this and all the hash accessors, ';' is
711 * provided by the tokeniser */
5c86b6df 712 { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); }
891be019 713 | scalar '[' expr ']' /* $array[$element] */
f05e27e5 714 { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3));
f05e27e5 715 }
891be019 716 | term ARROW '[' expr ']' /* somearef->[$element] */
fad39ff1
SM
717 { $$ = newBINOP(OP_AELEM, 0,
718 ref(newAVREF($1),OP_RV2AV),
f05e27e5 719 scalar($4));
f05e27e5 720 }
891be019 721 | subscripted '[' expr ']' /* $foo->[$bar]->[$baz] */
fad39ff1
SM
722 { $$ = newBINOP(OP_AELEM, 0,
723 ref(newAVREF($1),OP_RV2AV),
f05e27e5 724 scalar($3));
f05e27e5 725 }
5a63ceef 726 | scalar '{' expr ';' '}' /* $foo{bar();} */
fad39ff1 727 { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
f05e27e5 728 }
891be019 729 | term ARROW '{' expr ';' '}' /* somehref->{bar();} */
fad39ff1
SM
730 { $$ = newBINOP(OP_HELEM, 0,
731 ref(newHVREF($1),OP_RV2HV),
5c86b6df 732 jmaybe($4)); }
891be019 733 | subscripted '{' expr ';' '}' /* $foo->[bar]->{baz;} */
fad39ff1
SM
734 { $$ = newBINOP(OP_HELEM, 0,
735 ref(newHVREF($1),OP_RV2HV),
5c86b6df 736 jmaybe($3)); }
891be019 737 | term ARROW '(' ')' /* $subref->() */
fad39ff1 738 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
b5bbe64a 739 newCVREF(0, scalar($1))); }
891be019 740 | term ARROW '(' expr ')' /* $subref->(@args) */
fad39ff1 741 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 742 op_append_elem(OP_LIST, $4,
b5bbe64a 743 newCVREF(0, scalar($1)))); }
fad39ff1 744
417a992d 745 | subscripted '(' expr ')' /* $foo->{bar}->(@args) */
fad39ff1 746 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 747 op_append_elem(OP_LIST, $3,
b5bbe64a 748 newCVREF(0, scalar($1)))); }
417a992d 749 | subscripted '(' ')' /* $foo->{bar}->() */
fad39ff1 750 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
b5bbe64a 751 newCVREF(0, scalar($1))); }
9a9798c2 752 | '(' expr ')' '[' expr ']' /* list slice */
b5bbe64a 753 { $$ = newSLICEOP(0, $5, $2); }
ea25a9b2 754 | QWLIST '[' expr ']' /* list literal slice */
b5bbe64a 755 { $$ = newSLICEOP(0, $3, $1); }
9a9798c2 756 | '(' ')' '[' expr ']' /* empty list slice! */
b5bbe64a 757 { $$ = newSLICEOP(0, $4, (OP*)NULL); }
891be019 758 ;
fad39ff1 759
891be019 760/* Binary operators between terms */
f05e27e5 761termbinop: term ASSIGNOP term /* $x = $y */
b5bbe64a 762 { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); }
891be019 763 | term POWOP term /* $x ** $y */
b5bbe64a 764 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 765 | term MULOP term /* $x * $y, $x x $y */
b5bbe64a 766 { if ($2 != OP_REPEAT)
79072805 767 scalar($1);
b5bbe64a 768 $$ = newBINOP($2, 0, $1, scalar($3));
f05e27e5 769 }
891be019 770 | term ADDOP term /* $x + $y */
b5bbe64a 771 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 772 | term SHIFTOP term /* $x >> $y, $x << $y */
b5bbe64a 773 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 774 | term RELOP term /* $x > $y, etc. */
b5bbe64a 775 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 776 | term EQOP term /* $x == $y, $x eq $y */
b5bbe64a 777 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 778 | term BITANDOP term /* $x & $y */
b5bbe64a 779 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 780 | term BITOROP term /* $x | $y */
b5bbe64a 781 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 782 | term DOTDOT term /* $x..$y, $x...$y */
b5bbe64a 783 { $$ = newRANGE($2, scalar($1), scalar($3)); }
891be019 784 | term ANDAND term /* $x && $y */
b5bbe64a 785 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
891be019 786 | term OROR term /* $x || $y */
b5bbe64a 787 { $$ = newLOGOP(OP_OR, 0, $1, $3); }
c963b151 788 | term DORDOR term /* $x // $y */
b5bbe64a 789 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
891be019 790 | term MATCHOP term /* $x =~ /$y/ */
b5bbe64a 791 { $$ = bind_match($2, $1, $3); }
891be019 792 ;
8d063cd8 793
891be019
SC
794/* Unary operators and terms */
795termunop : '-' term %prec UMINUS /* -$x */
b5bbe64a 796 { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); }
891be019 797 | '+' term %prec UMINUS /* +$x */
b5bbe64a
JH
798 { $$ = $2; }
799
891be019 800 | '!' term /* !$x */
b5bbe64a 801 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
891be019 802 | '~' term /* ~$x */
b5bbe64a 803 { $$ = newUNOP(OP_COMPLEMENT, 0, scalar($2)); }
891be019 804 | term POSTINC /* $x++ */
79072805 805 { $$ = newUNOP(OP_POSTINC, 0,
b5bbe64a 806 op_lvalue(scalar($1), OP_POSTINC)); }
891be019 807 | term POSTDEC /* $x-- */
79072805 808 { $$ = newUNOP(OP_POSTDEC, 0,
b5bbe64a 809 op_lvalue(scalar($1), OP_POSTDEC));}
cc624add 810 | term POSTJOIN /* implicit join after interpolated ->@ */
03d05f6e 811 { $$ = op_convert_list(OP_JOIN, 0,
cc624add
FC
812 op_append_elem(
813 OP_LIST,
814 newSVREF(scalar(
815 newSVOP(OP_CONST,0,
816 newSVpvs("\""))
817 )),
818 $1
819 ));
cc624add 820 }
891be019 821 | PREINC term /* ++$x */
79072805 822 { $$ = newUNOP(OP_PREINC, 0,
b5bbe64a 823 op_lvalue(scalar($2), OP_PREINC)); }
891be019 824 | PREDEC term /* --$x */
79072805 825 { $$ = newUNOP(OP_PREDEC, 0,
b5bbe64a 826 op_lvalue(scalar($2), OP_PREDEC)); }
891be019
SC
827
828 ;
829
830/* Constructors for anonymous data */
831anonymous: '[' expr ']'
b5bbe64a 832 { $$ = newANONLIST($2); }
891be019 833 | '[' ']'
b5bbe64a 834 { $$ = newANONLIST((OP*)NULL);}
891be019 835 | HASHBRACK expr ';' '}' %prec '(' /* { foo => "Bar" } */
b5bbe64a 836 { $$ = newANONHASH($2); }
891be019 837 | HASHBRACK ';' '}' %prec '(' /* { } (';' by tokener) */
b5bbe64a 838 { $$ = newANONHASH((OP*)NULL); }
30d9c59b 839 | ANONSUB startanonsub proto subattrlist realsubbody %prec '('
5a5094bd 840 { SvREFCNT_inc_simple_void(PL_compcv);
b5bbe64a 841 $$ = newANONATTRSUB($2, $3, $4, $5); }
891be019
SC
842
843 ;
844
845/* Things called with "do" */
846termdo : DO term %prec UNIOP /* do $filename */
b5bbe64a 847 { $$ = dofile($2, $1);}
891be019 848 | DO block %prec '(' /* do { code */
b5bbe64a 849 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($2));}
891be019
SC
850 ;
851
852term : termbinop
853 | termunop
854 | anonymous
855 | termdo
e9bdcc27 856 | term '?' term ':' term
b5bbe64a 857 { $$ = newCONDOP(0, $1, $3, $5); }
891be019 858 | REFGEN term /* \$x, \@y, \%z */
b5bbe64a 859 { $$ = newUNOP(OP_REFGEN, 0, op_lvalue($2,OP_REFGEN)); }
09bef843
SB
860 | myattrterm %prec UNIOP
861 { $$ = $1; }
862 | LOCAL term %prec UNIOP
b5bbe64a 863 { $$ = localize($2,$1); }
a0d0e21e 864 | '(' expr ')'
b5bbe64a 865 { $$ = sawparens($2); }
ea25a9b2 866 | QWLIST
b5bbe64a 867 { $$ = $1; }
8d063cd8 868 | '(' ')'
b5bbe64a 869 { $$ = sawparens(newNULLLIST()); }
79072805 870 | scalar %prec '('
8d063cd8 871 { $$ = $1; }
79072805 872 | star %prec '('
8d063cd8 873 { $$ = $1; }
79072805 874 | hsh %prec '('
8d063cd8 875 { $$ = $1; }
79072805 876 | ary %prec '('
8d063cd8 877 { $$ = $1; }
891be019 878 | arylen %prec '(' /* $#x, $#{ something } */
79072805 879 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
fad39ff1
SM
880 | subscripted
881 { $$ = $1; }
89f35911 882 | sliceme '[' expr ']' /* array slice */
2fcb4757 883 { $$ = op_prepend_elem(OP_ASLICE,
79072805 884 newOP(OP_PUSHMARK, 0),
79072805
LW
885 newLISTOP(OP_ASLICE, 0,
886 list($3),
f05e27e5 887 ref($1, OP_ASLICE)));
429a2555
FC
888 if ($$ && $1)
889 $$->op_private |=
890 $1->op_private & OPpSLICEWARNING;
f05e27e5 891 }
76eba8ab 892 | kvslice '[' expr ']' /* array key/value slice */
6dd3e0f2
RZ
893 { $$ = op_prepend_elem(OP_KVASLICE,
894 newOP(OP_PUSHMARK, 0),
895 newLISTOP(OP_KVASLICE, 0,
896 list($3),
897 ref(oopsAV($1), OP_KVASLICE)));
95a31aad
FC
898 if ($$ && $1)
899 $$->op_private |=
900 $1->op_private & OPpSLICEWARNING;
6dd3e0f2 901 }
89f35911 902 | sliceme '{' expr ';' '}' /* @hash{@keys} */
2fcb4757 903 { $$ = op_prepend_elem(OP_HSLICE,
79072805 904 newOP(OP_PUSHMARK, 0),
79072805
LW
905 newLISTOP(OP_HSLICE, 0,
906 list($3),
a0d0e21e 907 ref(oopsHV($1), OP_HSLICE)));
429a2555
FC
908 if ($$ && $1)
909 $$->op_private |=
910 $1->op_private & OPpSLICEWARNING;
f05e27e5 911 }
76eba8ab 912 | kvslice '{' expr ';' '}' /* %hash{@keys} */
5cae3edb
RZ
913 { $$ = op_prepend_elem(OP_KVHSLICE,
914 newOP(OP_PUSHMARK, 0),
915 newLISTOP(OP_KVHSLICE, 0,
916 list($3),
917 ref($1, OP_KVHSLICE)));
95a31aad
FC
918 if ($$ && $1)
919 $$->op_private |=
920 $1->op_private & OPpSLICEWARNING;
5cae3edb 921 }
79072805
LW
922 | THING %prec '('
923 { $$ = $1; }
891be019 924 | amper /* &foo; */
c07a80fd 925 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
fb602e32 926 | amper '(' ')' /* &foo() or foo() */
f05e27e5 927 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1));
f05e27e5 928 }
fb602e32 929 | amper '(' expr ')' /* &foo(@args) or foo(@args) */
f05e27e5
DM
930 {
931 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 932 op_append_elem(OP_LIST, $3, scalar($1)));
f05e27e5 933 }
fb602e32 934 | NOAMP subname optlistexpr /* foo @args (no parens) */
a0d0e21e 935 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 936 op_append_elem(OP_LIST, $3, scalar($2)));
f05e27e5 937 }
89f35911 938 | term ARROW '$' '*'
b5bbe64a 939 { $$ = newSVREF($1); }
89f35911 940 | term ARROW '@' '*'
b5bbe64a 941 { $$ = newAVREF($1); }
89f35911 942 | term ARROW '%' '*'
b5bbe64a 943 { $$ = newHVREF($1); }
89f35911
FC
944 | term ARROW '&' '*'
945 { $$ = newUNOP(OP_ENTERSUB, 0,
b5bbe64a 946 scalar(newCVREF($3,$1))); }
89f35911 947 | term ARROW '*' '*' %prec '('
b5bbe64a 948 { $$ = newGVREF(0,$1); }
891be019 949 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
b5bbe64a
JH
950 { $$ = newOP($1, OPf_SPECIAL);
951 PL_hints |= HINT_BLOCK_SCOPE; }
a0d0e21e 952 | LOOPEX term
b5bbe64a 953 { $$ = newLOOPEX($1,$2); }
09b1cffe 954 | NOTOP listexpr /* not $foo */
b5bbe64a 955 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
891be019 956 | UNIOP /* Unary op, $_ implied */
b5bbe64a 957 { $$ = newOP($1, 0); }
f05e27e5 958 | UNIOP block /* eval { foo }* */
b5bbe64a 959 { $$ = newUNOP($1, 0, $2); }
891be019 960 | UNIOP term /* Unary op */
b5bbe64a 961 { $$ = newUNOP($1, 0, $2); }
d2fdf8fd 962 | REQUIRE /* require, $_ implied */
b5bbe64a 963 { $$ = newOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0); }
d2fdf8fd 964 | REQUIRE term /* require Foo */
b5bbe64a 965 { $$ = newUNOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0, $2); }
3cd0a11a
RGS
966 | UNIOPSUB
967 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
891be019 968 | UNIOPSUB term /* Sub treated as unop */
4633a7c4 969 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 970 op_append_elem(OP_LIST, $2, scalar($1))); }
891be019 971 | FUNC0 /* Nullary operator */
b5bbe64a 972 { $$ = newOP($1, 0); }
ae986130 973 | FUNC0 '(' ')'
b5bbe64a 974 { $$ = newOP($1, 0);}
7eb971ee
FC
975 | FUNC0OP /* Same as above, but op created in toke.c */
976 { $$ = $1; }
977 | FUNC0OP '(' ')'
b5bbe64a 978 { $$ = $1; }
891be019 979 | FUNC0SUB /* Sub treated as nullop */
b5bbe64a 980 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
891be019 981 | FUNC1 '(' ')' /* not () */
b5bbe64a
JH
982 { $$ = ($1 == OP_NOT)
983 ? newUNOP($1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
984 : newOP($1, OPf_SPECIAL); }
891be019 985 | FUNC1 '(' expr ')' /* not($foo) */
b5bbe64a 986 { $$ = newUNOP($1, 0, $3); }
d63c20f2
DM
987 | PMFUNC /* m//, s///, qr//, tr/// */
988 {
989 if ( $1->op_type != OP_TRANS
990 && $1->op_type != OP_TRANSR
991 && (((PMOP*)$1)->op_pmflags & PMf_HAS_CV))
992 {
993 $<ival>$ = start_subparse(FALSE, CVf_ANON);
994 SAVEFREESV(PL_compcv);
995 } else
996 $<ival>$ = 0;
997 }
998 '(' listexpr ')'
b5bbe64a 999 { $$ = pmruntime($1, $4, 1, $<ival>2); }
79072805 1000 | WORD
378cc40b 1001 | listop
be25f609 1002 | YADAYADA
1003 {
1004 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
1005 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
1006 }
88e1f1a2 1007 | PLUGEXPR
8d063cd8
LW
1008 ;
1009
891be019 1010/* "my" declarations, with optional attributes */
09bef843 1011myattrterm: MY myterm myattrlist
b5bbe64a 1012 { $$ = my_attrs($2,$3); }
09bef843 1013 | MY myterm
b5bbe64a 1014 { $$ = localize($2,$1); }
09bef843
SB
1015 ;
1016
891be019 1017/* Things that can be "my"'d */
09bef843 1018myterm : '(' expr ')'
b5bbe64a 1019 { $$ = sawparens($2); }
09bef843 1020 | '(' ')'
b5bbe64a
JH
1021 { $$ = sawparens(newNULLLIST()); }
1022
09bef843
SB
1023 | scalar %prec '('
1024 { $$ = $1; }
1025 | hsh %prec '('
1026 { $$ = $1; }
1027 | ary %prec '('
1028 { $$ = $1; }
1029 ;
1030
891be019 1031/* Basic list expressions */
09b1cffe 1032optlistexpr: /* NULL */ %prec PREC_LOW
bcabcc50 1033 { $$ = (OP*)NULL; }
09b1cffe 1034 | listexpr %prec PREC_LOW
a0d0e21e
LW
1035 { $$ = $1; }
1036 ;
1037
09b1cffe 1038optexpr: /* NULL */
bcabcc50 1039 { $$ = (OP*)NULL; }
79072805
LW
1040 | expr
1041 { $$ = $1; }
1042 ;
1043
891be019
SC
1044/* A little bit of trickery to make "for my $foo (@bar)" actually be
1045 lexical */
55497cff 1046my_scalar: scalar
624fa8bd 1047 { parser->in_my = 0; $$ = my($1); }
55497cff
PP
1048 ;
1049
d39c26a6
FC
1050my_var : scalar
1051 | ary
1052 | hsh
1053 ;
1054
1055refgen_topic: my_var
1056 | amper
1057 ;
1058
79072805 1059amper : '&' indirob
b5bbe64a 1060 { $$ = newCVREF($1,$2); }
a687059c
LW
1061 ;
1062
79072805 1063scalar : '$' indirob
b5bbe64a 1064 { $$ = newSVREF($2); }
a687059c
LW
1065 ;
1066
79072805 1067ary : '@' indirob
f05e27e5 1068 { $$ = newAVREF($2);
b5bbe64a 1069 if ($$) $$->op_private |= $1;
f05e27e5 1070 }
79072805
LW
1071 ;
1072
1073hsh : '%' indirob
f05e27e5 1074 { $$ = newHVREF($2);
b5bbe64a 1075 if ($$) $$->op_private |= $1;
f05e27e5 1076 }
79072805
LW
1077 ;
1078
1079arylen : DOLSHARP indirob
b5bbe64a 1080 { $$ = newAVREF($2); }
ff25e5db 1081 | term ARROW DOLSHARP '*'
b5bbe64a 1082 { $$ = newAVREF($1); }
79072805
LW
1083 ;
1084
1085star : '*' indirob
b5bbe64a 1086 { $$ = newGVREF(0,$2); }
79072805
LW
1087 ;
1088
89f35911
FC
1089sliceme : ary
1090 | term ARROW '@'
b5bbe64a 1091 { $$ = newAVREF($1); }
89f35911
FC
1092 ;
1093
76eba8ab
FC
1094kvslice : hsh
1095 | term ARROW '%'
b5bbe64a 1096 { $$ = newHVREF($1); }
76eba8ab
FC
1097 ;
1098
89f35911
FC
1099gelem : star
1100 | term ARROW '*'
b5bbe64a 1101 { $$ = newGVREF(0,$1); }
89f35911
FC
1102 ;
1103
891be019 1104/* Indirect objects */
79072805
LW
1105indirob : WORD
1106 { $$ = scalar($1); }
fad39ff1 1107 | scalar %prec PREC_LOW
f05e27e5 1108 { $$ = scalar($1); }
79072805 1109 | block
3ad73efd 1110 { $$ = op_scope($1); }
79072805 1111
93a17b20
LW
1112 | PRIVATEREF
1113 { $$ = $1; }
8d063cd8 1114 ;