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