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