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