This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix OUTSIDE for named subs inside predeclared subs
[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 }
8b9fb2f9 266 parser->parsed_sub = 1;
eae48c89 267 }
50278755
FC
268 | SUB subname startsub
269 {
270 if ($2->op_type == OP_CONST) {
271 const char *const name =
272 SvPV_nolen_const(((SVOP*)$2)->op_sv);
273 if (strEQ(name, "BEGIN") || strEQ(name, "END")
764212cf
FC
274 || strEQ(name, "INIT") || strEQ(name, "CHECK")
275 || strEQ(name, "UNITCHECK"))
276 CvSPECIAL_on(PL_compcv);
50278755 277 }
e07561e6
FC
278 else
279 /* State subs inside anonymous subs need to be
280 clonable themselves. */
6d5c2147
FC
281 if (CvANON(CvOUTSIDE(PL_compcv))
282 || CvCLONE(CvOUTSIDE(PL_compcv))
283 || !PadnameIsSTATE(PadlistNAMESARRAY(CvPADLIST(
284 CvOUTSIDE(PL_compcv)
285 ))[$2->op_targ]))
e07561e6 286 CvCLONE_on(PL_compcv);
624fa8bd
FC
287 parser->in_my = 0;
288 parser->in_my_stash = NULL;
764212cf 289 }
30d9c59b 290 proto subattrlist optsubbody
eae48c89
Z
291 {
292 SvREFCNT_inc_simple_void(PL_compcv);
50278755
FC
293 $2->op_type == OP_CONST
294 ? newATTRSUB($3, $2, $5, $6, $7)
295 : newMYSUB($3, $2, $5, $6, $7)
50278755 296 ;
eae48c89 297 $$ = (OP*)NULL;
764212cf 298 intro_my();
34b54951 299 parser->parsed_sub = 1;
f05e27e5 300 }
eae48c89 301 | PACKAGE WORD WORD ';'
5f211341 302 {
eae48c89
Z
303 package($3);
304 if ($2)
305 package_version($2);
306 $$ = (OP*)NULL;
eae48c89
Z
307 }
308 | USE startsub
309 { CvSPECIAL_on(PL_compcv); /* It's a BEGIN {} */ }
09b1cffe 310 WORD WORD optlistexpr ';'
eae48c89
Z
311 {
312 SvREFCNT_inc_simple_void(PL_compcv);
b5bbe64a 313 utilize($1, $2, $4, $5, $6);
34b54951 314 parser->parsed_sub = 1;
eae48c89 315 $$ = (OP*)NULL;
eae48c89 316 }
417a992d 317 | IF '(' remember mexpr ')' mblock else
eae48c89 318 {
3ad73efd
Z
319 $$ = block_end($3,
320 newCONDOP(0, $4, op_scope($6), $7));
624fa8bd 321 parser->copline = (line_t)$1;
eae48c89 322 }
417a992d 323 | UNLESS '(' remember miexpr ')' mblock else
eae48c89 324 {
3ad73efd
Z
325 $$ = block_end($3,
326 newCONDOP(0, $4, op_scope($6), $7));
624fa8bd 327 parser->copline = (line_t)$1;
eae48c89 328 }
b5a64814 329 | GIVEN '(' remember mexpr ')' mblock
eae48c89 330 {
b5a64814 331 const PADOFFSET offset = pad_findmy_pvs("$_", 0);
eae48c89 332 $$ = block_end($3,
b5a64814
FC
333 newGIVENOP($4, op_scope($6),
334 offset == NOT_IN_PAD
335 || PAD_COMPNAME_FLAGS_isOUR(offset)
336 ? 0
337 : offset));
624fa8bd 338 parser->copline = (line_t)$1;
eae48c89 339 }
417a992d 340 | WHEN '(' remember mexpr ')' mblock
3ad73efd 341 { $$ = block_end($3, newWHENOP($4, op_scope($6))); }
eae48c89 342 | DEFAULT block
3ad73efd 343 { $$ = newWHENOP(0, op_scope($2)); }
417a992d 344 | WHILE '(' remember texpr ')' mintro mblock cont
eae48c89
Z
345 {
346 $$ = block_end($3,
347 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
94bf0465 348 $4, $7, $8, $6));
624fa8bd 349 parser->copline = (line_t)$1;
eae48c89 350 }
417a992d 351 | UNTIL '(' remember iexpr ')' mintro mblock cont
eae48c89
Z
352 {
353 $$ = block_end($3,
94bf0465
Z
354 newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
355 $4, $7, $8, $6));
624fa8bd 356 parser->copline = (line_t)$1;
eae48c89 357 }
2d0e3c96
FC
358 | FOR '(' remember mnexpr ';'
359 { parser->expect = XTERM; }
360 texpr ';'
361 { parser->expect = XTERM; }
362 mintro mnexpr ')'
eae48c89
Z
363 mblock
364 {
b5bbe64a 365 OP *initop = $4;
eae48c89 366 OP *forop = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
2d0e3c96 367 scalar($7), $13, $11, $10);
eae48c89
Z
368 if (initop) {
369 forop = op_prepend_elem(OP_LINESEQ, initop,
370 op_append_elem(OP_LINESEQ,
371 newOP(OP_UNSTACK, OPf_SPECIAL),
372 forop));
5f211341 373 }
0f602692 374 PL_hints |= HINT_BLOCK_SCOPE;
eae48c89 375 $$ = block_end($3, forop);
624fa8bd 376 parser->copline = (line_t)$1;
eae48c89 377 }
417a992d 378 | FOR MY remember my_scalar '(' mexpr ')' mblock cont
eae48c89 379 {
94bf0465 380 $$ = block_end($3, newFOROP(0, $4, $6, $8, $9));
624fa8bd 381 parser->copline = (line_t)$1;
eae48c89 382 }
417a992d 383 | FOR scalar '(' remember mexpr ')' mblock cont
eae48c89 384 {
94bf0465 385 $$ = block_end($4, newFOROP(0,
3ad73efd 386 op_lvalue($2, OP_ENTERLOOP), $5, $7, $8));
624fa8bd 387 parser->copline = (line_t)$1;
eae48c89 388 }
d39c26a6
FC
389 | FOR REFGEN MY remember my_var
390 { parser->in_my = 0; $<opval>$ = my($5); }
391 '(' mexpr ')' mblock cont
392 {
393 $$ = block_end(
394 $4,
395 newFOROP(0,
396 op_lvalue(
397 newUNOP(OP_REFGEN, 0,
96801525 398 $<opval>6),
d39c26a6
FC
399 OP_ENTERLOOP),
400 $8, $10, $11)
401 );
402 parser->copline = (line_t)$1;
403 }
404 | FOR REFGEN refgen_topic '(' remember mexpr ')' mblock cont
405 {
406 $$ = block_end($5, newFOROP(
407 0, op_lvalue(newUNOP(OP_REFGEN, 0,
96801525 408 $3),
d39c26a6
FC
409 OP_ENTERLOOP), $6, $8, $9));
410 parser->copline = (line_t)$1;
411 }
417a992d 412 | FOR '(' remember mexpr ')' mblock cont
eae48c89
Z
413 {
414 $$ = block_end($3,
94bf0465 415 newFOROP(0, (OP*)NULL, $4, $6, $7));
624fa8bd 416 parser->copline = (line_t)$1;
eae48c89
Z
417 }
418 | block cont
419 {
420 /* a block is a loop that happens once */
421 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
94bf0465 422 (OP*)NULL, $1, $2, 0);
eae48c89
Z
423 }
424 | PACKAGE WORD WORD '{' remember
425 {
eae48c89 426 package($3);
eae48c89 427 if ($2) {
eae48c89 428 package_version($2);
eae48c89
Z
429 }
430 }
431 stmtseq '}'
432 {
433 /* a block is a loop that happens once */
94bf0465 434 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
eae48c89 435 (OP*)NULL, block_end($5, $7), (OP*)NULL, 0);
624fa8bd
FC
436 if (parser->copline > (line_t)$4)
437 parser->copline = (line_t)$4;
eae48c89
Z
438 }
439 | sideff ';'
440 {
eae48c89 441 $$ = $1;
eae48c89
Z
442 }
443 | ';'
444 {
b5bbe64a 445 $$ = (OP*)NULL;
624fa8bd 446 parser->copline = NOLINE;
5f211341 447 }
8d063cd8
LW
448 ;
449
705fe0e5
FC
450/* Format line */
451formline: THING formarg
452 { OP *list;
453 if ($2) {
454 OP *term = $2;
705fe0e5
FC
455 list = op_append_elem(OP_LIST, $1, term);
456 }
457 else {
705fe0e5 458 list = $1;
705fe0e5 459 }
624fa8bd
FC
460 if (parser->copline == NOLINE)
461 parser->copline = CopLINE(PL_curcop)-1;
462 else parser->copline--;
705fe0e5 463 $$ = newSTATEOP(0, NULL,
03d05f6e 464 op_convert_list(OP_FORMLINE, 0, list));
705fe0e5
FC
465 }
466 ;
467
468formarg : /* NULL */
469 { $$ = NULL; }
470 | FORMLBRACK stmtseq FORMRBRACK
471 { $$ = op_unscope($2); }
472 ;
473
891be019 474/* An expression which may have a side-effect */
a687059c 475sideff : error
bcabcc50 476 { $$ = (OP*)NULL; }
a687059c 477 | expr
79072805 478 { $$ = $1; }
a687059c 479 | expr IF expr
b5bbe64a 480 { $$ = newLOGOP(OP_AND, 0, $3, $1); }
a687059c 481 | expr UNLESS expr
b5bbe64a 482 { $$ = newLOGOP(OP_OR, 0, $3, $1); }
a687059c 483 | expr WHILE expr
b5bbe64a 484 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); }
55497cff 485 | expr UNTIL iexpr
b5bbe64a 486 { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1); }
ecca16b0 487 | expr FOR expr
94bf0465 488 { $$ = newFOROP(0, (OP*)NULL, $3, $1, (OP*)NULL);
624fa8bd 489 parser->copline = (line_t)$2; }
f20dcd76 490 | expr WHEN expr
3ad73efd 491 { $$ = newWHENOP($3, op_scope($1)); }
79072805
LW
492 ;
493
891be019 494/* else and elsif blocks */
79072805 495else : /* NULL */
bcabcc50 496 { $$ = (OP*)NULL; }
55497cff 497 | ELSE mblock
3ad73efd
Z
498 {
499 ($2)->op_flags |= OPf_PARENS;
500 $$ = op_scope($2);
f05e27e5 501 }
417a992d 502 | ELSIF '(' mexpr ')' mblock else
624fa8bd 503 { parser->copline = (line_t)$1;
3ad73efd
Z
504 $$ = newCONDOP(0,
505 newSTATEOP(OPf_SPECIAL,NULL,$3),
506 op_scope($5), $6);
507 PL_hints |= HINT_BLOCK_SCOPE;
f05e27e5 508 }
79072805
LW
509 ;
510
891be019 511/* Continue blocks */
79072805 512cont : /* NULL */
bcabcc50 513 { $$ = (OP*)NULL; }
79072805 514 | CONTINUE block
b5bbe64a 515 { $$ = op_scope($2); }
79072805
LW
516 ;
517
a034e688
DM
518/* determine whether there are any new my declarations */
519mintro : /* NULL */
520 { $$ = (PL_min_intro_pending &&
521 PL_max_intro_pending >= PL_min_intro_pending);
522 intro_my(); }
523
891be019 524/* Normal expression */
8d063cd8 525nexpr : /* NULL */
bcabcc50 526 { $$ = (OP*)NULL; }
8d063cd8
LW
527 | sideff
528 ;
529
891be019 530/* Boolean expression */
8d063cd8 531texpr : /* NULL means true */
f05e27e5
DM
532 { YYSTYPE tmplval;
533 (void)scan_num("1", &tmplval);
534 $$ = tmplval.opval; }
8d063cd8
LW
535 | expr
536 ;
537
891be019 538/* Inverted boolean expression */
55497cff
PP
539iexpr : expr
540 { $$ = invert(scalar($1)); }
541 ;
542
891be019 543/* Expression with its own lexical scope */
55497cff 544mexpr : expr
bbce6d69
PP
545 { $$ = $1; intro_my(); }
546 ;
547
548mnexpr : nexpr
549 { $$ = $1; intro_my(); }
55497cff
PP
550 ;
551
55497cff 552miexpr : iexpr
bbce6d69 553 { $$ = $1; intro_my(); }
55497cff
PP
554 ;
555
44a8e56a 556formname: WORD { $$ = $1; }
bcabcc50 557 | /* NULL */ { $$ = (OP*)NULL; }
8d063cd8
LW
558 ;
559
fa83b5b6 560startsub: /* NULL */ /* start a regular subroutine scope */
a8ff2fa6
DM
561 { $$ = start_subparse(FALSE, 0);
562 SAVEFREESV(PL_compcv); }
f05e27e5 563
28757baa
PP
564 ;
565
566startanonsub: /* NULL */ /* start an anonymous subroutine scope */
a8ff2fa6
DM
567 { $$ = start_subparse(FALSE, CVf_ANON);
568 SAVEFREESV(PL_compcv); }
28757baa
PP
569 ;
570
44a8e56a 571startformsub: /* NULL */ /* start a format subroutine scope */
a8ff2fa6
DM
572 { $$ = start_subparse(TRUE, 0);
573 SAVEFREESV(PL_compcv); }
44a8e56a
PP
574 ;
575
891be019 576/* Name of a subroutine - must be a bareword, could be special */
50278755 577subname : WORD
4210d3f1 578 | PRIVATEREF
a0d0e21e
LW
579 ;
580
891be019 581/* Subroutine prototype */
4633a7c4 582proto : /* NULL */
bcabcc50 583 { $$ = (OP*)NULL; }
4633a7c4
LW
584 | THING
585 ;
28757baa 586
891be019 587/* Optional list of subroutine attributes */
09bef843 588subattrlist: /* NULL */
bcabcc50 589 { $$ = (OP*)NULL; }
09bef843 590 | COLONATTR THING
b5bbe64a 591 { $$ = $2; }
09bef843 592 | COLONATTR
b5bbe64a 593 { $$ = (OP*)NULL; }
09bef843
SB
594 ;
595
891be019 596/* List of attributes for a "my" variable declaration */
09bef843 597myattrlist: COLONATTR THING
b5bbe64a 598 { $$ = $2; }
09bef843 599 | COLONATTR
b5bbe64a 600 { $$ = (OP*)NULL; }
09bef843
SB
601 ;
602
30d9c59b
Z
603/* Optional subroutine signature */
604subsignature: /* NULL */ { $$ = (OP*)NULL; }
605 | '('
606 {
607 if (!FEATURE_SIGNATURES_IS_ENABLED)
608 Perl_croak(aTHX_ "Experimental "
609 "subroutine signatures not enabled");
610 Perl_ck_warner_d(aTHX_
611 packWARN(WARN_EXPERIMENTAL__SIGNATURES),
612 "The signatures feature is experimental");
613 $<opval>$ = parse_subsignature();
614 }
615 ')'
616 {
617 $$ = op_append_list(OP_LINESEQ, $<opval>2,
618 newSTATEOP(0, NULL, sawparens(newNULLLIST())));
624fa8bd 619 parser->expect = XBLOCK;
30d9c59b
Z
620 }
621 ;
622
623/* Subroutine body - block with optional signature */
624realsubbody: remember subsignature '{' stmtseq '}'
625 {
624fa8bd
FC
626 if (parser->copline > (line_t)$3)
627 parser->copline = (line_t)$3;
30d9c59b
Z
628 $$ = block_end($1,
629 op_append_list(OP_LINESEQ, $2, $4));
30d9c59b
Z
630 }
631 ;
632
633/* Optional subroutine body, for named subroutine declaration */
634optsubbody: realsubbody { $$ = $1; }
2d0e3c96 635 | ';' { $$ = (OP*)NULL; }
8d063cd8
LW
636 ;
637
891be019 638/* Ordinary expressions; logical combinations */
a0d0e21e 639expr : expr ANDOP expr
b5bbe64a 640 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
a0d0e21e 641 | expr OROP expr
b5bbe64a 642 { $$ = newLOGOP($2, 0, $1, $3); }
c963b151 643 | expr DOROP expr
b5bbe64a 644 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
09b1cffe 645 | listexpr %prec PREC_LOW
a0d0e21e
LW
646 ;
647
891be019 648/* Expressions are a list of terms joined by commas */
09b1cffe 649listexpr: listexpr ','
b5bbe64a 650 { $$ = $1; }
09b1cffe 651 | listexpr ',' term
f05e27e5 652 {
29522234 653 OP* term = $3;
2fcb4757 654 $$ = op_append_elem(OP_LIST, $1, term);
f05e27e5 655 }
fad39ff1 656 | term %prec PREC_LOW
8d063cd8
LW
657 ;
658
891be019 659/* List operators */
09b1cffe 660listop : LSTOP indirob listexpr /* map {...} @args or print $fh @args */
03d05f6e 661 { $$ = op_convert_list($1, OPf_STACKED,
b5bbe64a 662 op_prepend_elem(OP_LIST, newGVREF($1,$2), $3) );
f05e27e5 663 }
891be019 664 | FUNC '(' indirob expr ')' /* print ($fh @args */
03d05f6e 665 { $$ = op_convert_list($1, OPf_STACKED,
b5bbe64a 666 op_prepend_elem(OP_LIST, newGVREF($1,$3), $4) );
f05e27e5 667 }
417a992d 668 | term ARROW method '(' optexpr ')' /* $foo->bar(list) */
03d05f6e 669 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757
Z
670 op_append_elem(OP_LIST,
671 op_prepend_elem(OP_LIST, scalar($1), $5),
b46e009d 672 newMETHOP(OP_METHOD, 0, $3)));
f05e27e5 673 }
891be019 674 | term ARROW method /* $foo->bar */
03d05f6e 675 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757 676 op_append_elem(OP_LIST, scalar($1),
b46e009d 677 newMETHOP(OP_METHOD, 0, $3)));
f05e27e5 678 }
09b1cffe 679 | METHOD indirob optlistexpr /* new Class @args */
03d05f6e 680 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757
Z
681 op_append_elem(OP_LIST,
682 op_prepend_elem(OP_LIST, $2, $3),
b46e009d 683 newMETHOP(OP_METHOD, 0, $1)));
f05e27e5 684 }
09b1cffe 685 | FUNCMETH indirob '(' optexpr ')' /* method $object (@args) */
03d05f6e 686 { $$ = op_convert_list(OP_ENTERSUB, OPf_STACKED,
2fcb4757
Z
687 op_append_elem(OP_LIST,
688 op_prepend_elem(OP_LIST, $2, $4),
b46e009d 689 newMETHOP(OP_METHOD, 0, $1)));
f05e27e5 690 }
09b1cffe 691 | LSTOP optlistexpr /* print @args */
03d05f6e 692 { $$ = op_convert_list($1, 0, $2); }
09b1cffe 693 | FUNC '(' optexpr ')' /* print (@args) */
03d05f6e 694 { $$ = op_convert_list($1, 0, $3); }
718a7425 695 | LSTOPSUB startanonsub block /* sub f(&@); f { foo } ... */
5a5094bd 696 { SvREFCNT_inc_simple_void(PL_compcv);
bcabcc50 697 $<opval>$ = newANONATTRSUB($2, 0, (OP*)NULL, $3); }
09b1cffe 698 optlistexpr %prec LSTOP /* ... @bar */
4633a7c4 699 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757
Z
700 op_append_elem(OP_LIST,
701 op_prepend_elem(OP_LIST, $<opval>4, $5), $1));
f05e27e5 702 }
a687059c
LW
703 ;
704
891be019 705/* Names of methods. May use $object->$methodname */
a0d0e21e
LW
706method : METHOD
707 | scalar
708 ;
709
891be019 710/* Some kind of subscripted expression */
89f35911 711subscripted: gelem '{' expr ';' '}' /* *main::{something} */
891be019
SC
712 /* In this and all the hash accessors, ';' is
713 * provided by the tokeniser */
5c86b6df 714 { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3)); }
891be019 715 | scalar '[' expr ']' /* $array[$element] */
f05e27e5 716 { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3));
f05e27e5 717 }
891be019 718 | term ARROW '[' expr ']' /* somearef->[$element] */
fad39ff1
SM
719 { $$ = newBINOP(OP_AELEM, 0,
720 ref(newAVREF($1),OP_RV2AV),
f05e27e5 721 scalar($4));
f05e27e5 722 }
891be019 723 | subscripted '[' expr ']' /* $foo->[$bar]->[$baz] */
fad39ff1
SM
724 { $$ = newBINOP(OP_AELEM, 0,
725 ref(newAVREF($1),OP_RV2AV),
f05e27e5 726 scalar($3));
f05e27e5 727 }
5a63ceef 728 | scalar '{' expr ';' '}' /* $foo{bar();} */
fad39ff1 729 { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
f05e27e5 730 }
891be019 731 | term ARROW '{' expr ';' '}' /* somehref->{bar();} */
fad39ff1
SM
732 { $$ = newBINOP(OP_HELEM, 0,
733 ref(newHVREF($1),OP_RV2HV),
5c86b6df 734 jmaybe($4)); }
891be019 735 | subscripted '{' expr ';' '}' /* $foo->[bar]->{baz;} */
fad39ff1
SM
736 { $$ = newBINOP(OP_HELEM, 0,
737 ref(newHVREF($1),OP_RV2HV),
5c86b6df 738 jmaybe($3)); }
891be019 739 | term ARROW '(' ')' /* $subref->() */
fad39ff1 740 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
b5bbe64a 741 newCVREF(0, scalar($1))); }
891be019 742 | term ARROW '(' expr ')' /* $subref->(@args) */
fad39ff1 743 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 744 op_append_elem(OP_LIST, $4,
b5bbe64a 745 newCVREF(0, scalar($1)))); }
fad39ff1 746
417a992d 747 | subscripted '(' expr ')' /* $foo->{bar}->(@args) */
fad39ff1 748 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 749 op_append_elem(OP_LIST, $3,
b5bbe64a 750 newCVREF(0, scalar($1)))); }
417a992d 751 | subscripted '(' ')' /* $foo->{bar}->() */
fad39ff1 752 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
b5bbe64a 753 newCVREF(0, scalar($1))); }
9a9798c2 754 | '(' expr ')' '[' expr ']' /* list slice */
b5bbe64a 755 { $$ = newSLICEOP(0, $5, $2); }
ea25a9b2 756 | QWLIST '[' expr ']' /* list literal slice */
b5bbe64a 757 { $$ = newSLICEOP(0, $3, $1); }
9a9798c2 758 | '(' ')' '[' expr ']' /* empty list slice! */
b5bbe64a 759 { $$ = newSLICEOP(0, $4, (OP*)NULL); }
891be019 760 ;
fad39ff1 761
891be019 762/* Binary operators between terms */
f05e27e5 763termbinop: term ASSIGNOP term /* $x = $y */
b5bbe64a 764 { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); }
891be019 765 | term POWOP term /* $x ** $y */
b5bbe64a 766 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 767 | term MULOP term /* $x * $y, $x x $y */
b5bbe64a 768 { if ($2 != OP_REPEAT)
79072805 769 scalar($1);
b5bbe64a 770 $$ = newBINOP($2, 0, $1, scalar($3));
f05e27e5 771 }
891be019 772 | term ADDOP term /* $x + $y */
b5bbe64a 773 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 774 | term SHIFTOP term /* $x >> $y, $x << $y */
b5bbe64a 775 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 776 | term RELOP term /* $x > $y, etc. */
b5bbe64a 777 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 778 | term EQOP term /* $x == $y, $x eq $y */
b5bbe64a 779 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 780 | term BITANDOP term /* $x & $y */
b5bbe64a 781 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 782 | term BITOROP term /* $x | $y */
b5bbe64a 783 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 784 | term DOTDOT term /* $x..$y, $x...$y */
b5bbe64a 785 { $$ = newRANGE($2, scalar($1), scalar($3)); }
891be019 786 | term ANDAND term /* $x && $y */
b5bbe64a 787 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
891be019 788 | term OROR term /* $x || $y */
b5bbe64a 789 { $$ = newLOGOP(OP_OR, 0, $1, $3); }
c963b151 790 | term DORDOR term /* $x // $y */
b5bbe64a 791 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
891be019 792 | term MATCHOP term /* $x =~ /$y/ */
b5bbe64a 793 { $$ = bind_match($2, $1, $3); }
891be019 794 ;
8d063cd8 795
891be019
SC
796/* Unary operators and terms */
797termunop : '-' term %prec UMINUS /* -$x */
b5bbe64a 798 { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); }
891be019 799 | '+' term %prec UMINUS /* +$x */
b5bbe64a
JH
800 { $$ = $2; }
801
891be019 802 | '!' term /* !$x */
b5bbe64a 803 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
891be019 804 | '~' term /* ~$x */
b5bbe64a 805 { $$ = newUNOP(OP_COMPLEMENT, 0, scalar($2)); }
891be019 806 | term POSTINC /* $x++ */
79072805 807 { $$ = newUNOP(OP_POSTINC, 0,
b5bbe64a 808 op_lvalue(scalar($1), OP_POSTINC)); }
891be019 809 | term POSTDEC /* $x-- */
79072805 810 { $$ = newUNOP(OP_POSTDEC, 0,
b5bbe64a 811 op_lvalue(scalar($1), OP_POSTDEC));}
cc624add 812 | term POSTJOIN /* implicit join after interpolated ->@ */
03d05f6e 813 { $$ = op_convert_list(OP_JOIN, 0,
cc624add
FC
814 op_append_elem(
815 OP_LIST,
816 newSVREF(scalar(
817 newSVOP(OP_CONST,0,
818 newSVpvs("\""))
819 )),
820 $1
821 ));
cc624add 822 }
891be019 823 | PREINC term /* ++$x */
79072805 824 { $$ = newUNOP(OP_PREINC, 0,
b5bbe64a 825 op_lvalue(scalar($2), OP_PREINC)); }
891be019 826 | PREDEC term /* --$x */
79072805 827 { $$ = newUNOP(OP_PREDEC, 0,
b5bbe64a 828 op_lvalue(scalar($2), OP_PREDEC)); }
891be019
SC
829
830 ;
831
832/* Constructors for anonymous data */
833anonymous: '[' expr ']'
b5bbe64a 834 { $$ = newANONLIST($2); }
891be019 835 | '[' ']'
b5bbe64a 836 { $$ = newANONLIST((OP*)NULL);}
891be019 837 | HASHBRACK expr ';' '}' %prec '(' /* { foo => "Bar" } */
b5bbe64a 838 { $$ = newANONHASH($2); }
891be019 839 | HASHBRACK ';' '}' %prec '(' /* { } (';' by tokener) */
b5bbe64a 840 { $$ = newANONHASH((OP*)NULL); }
30d9c59b 841 | ANONSUB startanonsub proto subattrlist realsubbody %prec '('
5a5094bd 842 { SvREFCNT_inc_simple_void(PL_compcv);
b5bbe64a 843 $$ = newANONATTRSUB($2, $3, $4, $5); }
891be019
SC
844
845 ;
846
847/* Things called with "do" */
848termdo : DO term %prec UNIOP /* do $filename */
b5bbe64a 849 { $$ = dofile($2, $1);}
891be019 850 | DO block %prec '(' /* do { code */
b5bbe64a 851 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($2));}
891be019
SC
852 ;
853
854term : termbinop
855 | termunop
856 | anonymous
857 | termdo
e9bdcc27 858 | term '?' term ':' term
b5bbe64a 859 { $$ = newCONDOP(0, $1, $3, $5); }
891be019 860 | REFGEN term /* \$x, \@y, \%z */
b5bbe64a 861 { $$ = newUNOP(OP_REFGEN, 0, op_lvalue($2,OP_REFGEN)); }
09bef843
SB
862 | myattrterm %prec UNIOP
863 { $$ = $1; }
864 | LOCAL term %prec UNIOP
b5bbe64a 865 { $$ = localize($2,$1); }
a0d0e21e 866 | '(' expr ')'
b5bbe64a 867 { $$ = sawparens($2); }
ea25a9b2 868 | QWLIST
b5bbe64a 869 { $$ = $1; }
8d063cd8 870 | '(' ')'
b5bbe64a 871 { $$ = sawparens(newNULLLIST()); }
79072805 872 | scalar %prec '('
8d063cd8 873 { $$ = $1; }
79072805 874 | star %prec '('
8d063cd8 875 { $$ = $1; }
79072805 876 | hsh %prec '('
8d063cd8 877 { $$ = $1; }
79072805 878 | ary %prec '('
8d063cd8 879 { $$ = $1; }
891be019 880 | arylen %prec '(' /* $#x, $#{ something } */
79072805 881 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
fad39ff1
SM
882 | subscripted
883 { $$ = $1; }
89f35911 884 | sliceme '[' expr ']' /* array slice */
2fcb4757 885 { $$ = op_prepend_elem(OP_ASLICE,
79072805 886 newOP(OP_PUSHMARK, 0),
79072805
LW
887 newLISTOP(OP_ASLICE, 0,
888 list($3),
f05e27e5 889 ref($1, OP_ASLICE)));
429a2555
FC
890 if ($$ && $1)
891 $$->op_private |=
892 $1->op_private & OPpSLICEWARNING;
f05e27e5 893 }
76eba8ab 894 | kvslice '[' expr ']' /* array key/value slice */
6dd3e0f2
RZ
895 { $$ = op_prepend_elem(OP_KVASLICE,
896 newOP(OP_PUSHMARK, 0),
897 newLISTOP(OP_KVASLICE, 0,
898 list($3),
899 ref(oopsAV($1), OP_KVASLICE)));
95a31aad
FC
900 if ($$ && $1)
901 $$->op_private |=
902 $1->op_private & OPpSLICEWARNING;
6dd3e0f2 903 }
89f35911 904 | sliceme '{' expr ';' '}' /* @hash{@keys} */
2fcb4757 905 { $$ = op_prepend_elem(OP_HSLICE,
79072805 906 newOP(OP_PUSHMARK, 0),
79072805
LW
907 newLISTOP(OP_HSLICE, 0,
908 list($3),
a0d0e21e 909 ref(oopsHV($1), OP_HSLICE)));
429a2555
FC
910 if ($$ && $1)
911 $$->op_private |=
912 $1->op_private & OPpSLICEWARNING;
f05e27e5 913 }
76eba8ab 914 | kvslice '{' expr ';' '}' /* %hash{@keys} */
5cae3edb
RZ
915 { $$ = op_prepend_elem(OP_KVHSLICE,
916 newOP(OP_PUSHMARK, 0),
917 newLISTOP(OP_KVHSLICE, 0,
918 list($3),
919 ref($1, OP_KVHSLICE)));
95a31aad
FC
920 if ($$ && $1)
921 $$->op_private |=
922 $1->op_private & OPpSLICEWARNING;
5cae3edb 923 }
79072805
LW
924 | THING %prec '('
925 { $$ = $1; }
891be019 926 | amper /* &foo; */
c07a80fd 927 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
fb602e32 928 | amper '(' ')' /* &foo() or foo() */
f05e27e5 929 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1));
f05e27e5 930 }
fb602e32 931 | amper '(' expr ')' /* &foo(@args) or foo(@args) */
f05e27e5
DM
932 {
933 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 934 op_append_elem(OP_LIST, $3, scalar($1)));
f05e27e5 935 }
fb602e32 936 | NOAMP subname optlistexpr /* foo @args (no parens) */
a0d0e21e 937 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 938 op_append_elem(OP_LIST, $3, scalar($2)));
f05e27e5 939 }
89f35911 940 | term ARROW '$' '*'
b5bbe64a 941 { $$ = newSVREF($1); }
89f35911 942 | term ARROW '@' '*'
b5bbe64a 943 { $$ = newAVREF($1); }
89f35911 944 | term ARROW '%' '*'
b5bbe64a 945 { $$ = newHVREF($1); }
89f35911
FC
946 | term ARROW '&' '*'
947 { $$ = newUNOP(OP_ENTERSUB, 0,
b5bbe64a 948 scalar(newCVREF($3,$1))); }
89f35911 949 | term ARROW '*' '*' %prec '('
b5bbe64a 950 { $$ = newGVREF(0,$1); }
891be019 951 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
b5bbe64a
JH
952 { $$ = newOP($1, OPf_SPECIAL);
953 PL_hints |= HINT_BLOCK_SCOPE; }
a0d0e21e 954 | LOOPEX term
b5bbe64a 955 { $$ = newLOOPEX($1,$2); }
09b1cffe 956 | NOTOP listexpr /* not $foo */
b5bbe64a 957 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
891be019 958 | UNIOP /* Unary op, $_ implied */
b5bbe64a 959 { $$ = newOP($1, 0); }
f05e27e5 960 | UNIOP block /* eval { foo }* */
b5bbe64a 961 { $$ = newUNOP($1, 0, $2); }
891be019 962 | UNIOP term /* Unary op */
b5bbe64a 963 { $$ = newUNOP($1, 0, $2); }
d2fdf8fd 964 | REQUIRE /* require, $_ implied */
b5bbe64a 965 { $$ = newOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0); }
d2fdf8fd 966 | REQUIRE term /* require Foo */
b5bbe64a 967 { $$ = newUNOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0, $2); }
3cd0a11a
RGS
968 | UNIOPSUB
969 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
891be019 970 | UNIOPSUB term /* Sub treated as unop */
4633a7c4 971 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 972 op_append_elem(OP_LIST, $2, scalar($1))); }
891be019 973 | FUNC0 /* Nullary operator */
b5bbe64a 974 { $$ = newOP($1, 0); }
ae986130 975 | FUNC0 '(' ')'
b5bbe64a 976 { $$ = newOP($1, 0);}
7eb971ee
FC
977 | FUNC0OP /* Same as above, but op created in toke.c */
978 { $$ = $1; }
979 | FUNC0OP '(' ')'
b5bbe64a 980 { $$ = $1; }
891be019 981 | FUNC0SUB /* Sub treated as nullop */
b5bbe64a 982 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
891be019 983 | FUNC1 '(' ')' /* not () */
b5bbe64a
JH
984 { $$ = ($1 == OP_NOT)
985 ? newUNOP($1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
986 : newOP($1, OPf_SPECIAL); }
891be019 987 | FUNC1 '(' expr ')' /* not($foo) */
b5bbe64a 988 { $$ = newUNOP($1, 0, $3); }
d63c20f2
DM
989 | PMFUNC /* m//, s///, qr//, tr/// */
990 {
991 if ( $1->op_type != OP_TRANS
992 && $1->op_type != OP_TRANSR
993 && (((PMOP*)$1)->op_pmflags & PMf_HAS_CV))
994 {
995 $<ival>$ = start_subparse(FALSE, CVf_ANON);
996 SAVEFREESV(PL_compcv);
997 } else
998 $<ival>$ = 0;
999 }
1000 '(' listexpr ')'
b5bbe64a 1001 { $$ = pmruntime($1, $4, 1, $<ival>2); }
79072805 1002 | WORD
378cc40b 1003 | listop
be25f609 1004 | YADAYADA
1005 {
1006 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
1007 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
1008 }
88e1f1a2 1009 | PLUGEXPR
8d063cd8
LW
1010 ;
1011
891be019 1012/* "my" declarations, with optional attributes */
09bef843 1013myattrterm: MY myterm myattrlist
b5bbe64a 1014 { $$ = my_attrs($2,$3); }
09bef843 1015 | MY myterm
b5bbe64a 1016 { $$ = localize($2,$1); }
09bef843
SB
1017 ;
1018
891be019 1019/* Things that can be "my"'d */
09bef843 1020myterm : '(' expr ')'
b5bbe64a 1021 { $$ = sawparens($2); }
09bef843 1022 | '(' ')'
b5bbe64a
JH
1023 { $$ = sawparens(newNULLLIST()); }
1024
09bef843
SB
1025 | scalar %prec '('
1026 { $$ = $1; }
1027 | hsh %prec '('
1028 { $$ = $1; }
1029 | ary %prec '('
1030 { $$ = $1; }
1031 ;
1032
891be019 1033/* Basic list expressions */
09b1cffe 1034optlistexpr: /* NULL */ %prec PREC_LOW
bcabcc50 1035 { $$ = (OP*)NULL; }
09b1cffe 1036 | listexpr %prec PREC_LOW
a0d0e21e
LW
1037 { $$ = $1; }
1038 ;
1039
09b1cffe 1040optexpr: /* NULL */
bcabcc50 1041 { $$ = (OP*)NULL; }
79072805
LW
1042 | expr
1043 { $$ = $1; }
1044 ;
1045
891be019
SC
1046/* A little bit of trickery to make "for my $foo (@bar)" actually be
1047 lexical */
55497cff 1048my_scalar: scalar
624fa8bd 1049 { parser->in_my = 0; $$ = my($1); }
55497cff
PP
1050 ;
1051
d39c26a6
FC
1052my_var : scalar
1053 | ary
1054 | hsh
1055 ;
1056
1057refgen_topic: my_var
1058 | amper
1059 ;
1060
79072805 1061amper : '&' indirob
b5bbe64a 1062 { $$ = newCVREF($1,$2); }
a687059c
LW
1063 ;
1064
79072805 1065scalar : '$' indirob
b5bbe64a 1066 { $$ = newSVREF($2); }
a687059c
LW
1067 ;
1068
79072805 1069ary : '@' indirob
f05e27e5 1070 { $$ = newAVREF($2);
b5bbe64a 1071 if ($$) $$->op_private |= $1;
f05e27e5 1072 }
79072805
LW
1073 ;
1074
1075hsh : '%' indirob
f05e27e5 1076 { $$ = newHVREF($2);
b5bbe64a 1077 if ($$) $$->op_private |= $1;
f05e27e5 1078 }
79072805
LW
1079 ;
1080
1081arylen : DOLSHARP indirob
b5bbe64a 1082 { $$ = newAVREF($2); }
ff25e5db 1083 | term ARROW DOLSHARP '*'
b5bbe64a 1084 { $$ = newAVREF($1); }
79072805
LW
1085 ;
1086
1087star : '*' indirob
b5bbe64a 1088 { $$ = newGVREF(0,$2); }
79072805
LW
1089 ;
1090
89f35911
FC
1091sliceme : ary
1092 | term ARROW '@'
b5bbe64a 1093 { $$ = newAVREF($1); }
89f35911
FC
1094 ;
1095
76eba8ab
FC
1096kvslice : hsh
1097 | term ARROW '%'
b5bbe64a 1098 { $$ = newHVREF($1); }
76eba8ab
FC
1099 ;
1100
89f35911
FC
1101gelem : star
1102 | term ARROW '*'
b5bbe64a 1103 { $$ = newGVREF(0,$1); }
89f35911
FC
1104 ;
1105
891be019 1106/* Indirect objects */
79072805
LW
1107indirob : WORD
1108 { $$ = scalar($1); }
fad39ff1 1109 | scalar %prec PREC_LOW
f05e27e5 1110 { $$ = scalar($1); }
79072805 1111 | block
3ad73efd 1112 { $$ = op_scope($1); }
79072805 1113
93a17b20
LW
1114 | PRIVATEREF
1115 { $$ = $1; }
8d063cd8 1116 ;