This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perldelta for f57000b
[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 {
115 PL_parser->expect = XSTATE;
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 '}'
b5bbe64a
JH
180 { if (PL_parser->copline > (line_t)$1)
181 PL_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 ';' '.'
b5bbe64a
JH
188 { if (PL_parser->copline > (line_t)$1)
189 PL_parser->copline = (line_t)$1;
705fe0e5 190 $$ = block_end($2, $5);
7c70caa5
FC
191 }
192 ;
193
55497cff 194remember: /* NULL */ /* start a full lexical scope */
195 { $$ = block_start(TRUE); }
196 ;
197
5f211341 198mblock : '{' mremember stmtseq '}'
b5bbe64a
JH
199 { if (PL_parser->copline > (line_t)$1)
200 PL_parser->copline = (line_t)$1;
f05e27e5 201 $$ = block_end($2, $3);
f05e27e5 202 }
55497cff 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);
764212cf
FC
282 PL_parser->in_my = 0;
283 PL_parser->in_my_stash = NULL;
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));
b5bbe64a 314 PL_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));
b5bbe64a 320 PL_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));
b5bbe64a 331 PL_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));
b5bbe64a 342 PL_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));
b5bbe64a 349 PL_parser->copline = (line_t)$1;
eae48c89 350 }
417a992d 351 | FOR '(' remember mnexpr ';' texpr ';' mintro mnexpr ')'
eae48c89
Z
352 mblock
353 {
b5bbe64a 354 OP *initop = $4;
eae48c89 355 OP *forop = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
94bf0465 356 scalar($6), $11, $9, $8);
eae48c89
Z
357 if (initop) {
358 forop = op_prepend_elem(OP_LINESEQ, initop,
359 op_append_elem(OP_LINESEQ,
360 newOP(OP_UNSTACK, OPf_SPECIAL),
361 forop));
5f211341 362 }
eae48c89 363 $$ = block_end($3, forop);
b5bbe64a 364 PL_parser->copline = (line_t)$1;
eae48c89 365 }
417a992d 366 | FOR MY remember my_scalar '(' mexpr ')' mblock cont
eae48c89 367 {
94bf0465 368 $$ = block_end($3, newFOROP(0, $4, $6, $8, $9));
b5bbe64a 369 PL_parser->copline = (line_t)$1;
eae48c89 370 }
417a992d 371 | FOR scalar '(' remember mexpr ')' mblock cont
eae48c89 372 {
94bf0465 373 $$ = block_end($4, newFOROP(0,
3ad73efd 374 op_lvalue($2, OP_ENTERLOOP), $5, $7, $8));
b5bbe64a 375 PL_parser->copline = (line_t)$1;
eae48c89 376 }
417a992d 377 | FOR '(' remember mexpr ')' mblock cont
eae48c89
Z
378 {
379 $$ = block_end($3,
94bf0465 380 newFOROP(0, (OP*)NULL, $4, $6, $7));
b5bbe64a 381 PL_parser->copline = (line_t)$1;
eae48c89
Z
382 }
383 | block cont
384 {
385 /* a block is a loop that happens once */
386 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
94bf0465 387 (OP*)NULL, $1, $2, 0);
eae48c89
Z
388 }
389 | PACKAGE WORD WORD '{' remember
390 {
eae48c89 391 package($3);
eae48c89 392 if ($2) {
eae48c89 393 package_version($2);
eae48c89
Z
394 }
395 }
396 stmtseq '}'
397 {
398 /* a block is a loop that happens once */
94bf0465 399 $$ = newWHILEOP(0, 1, (LOOP*)(OP*)NULL,
eae48c89 400 (OP*)NULL, block_end($5, $7), (OP*)NULL, 0);
b5bbe64a
JH
401 if (PL_parser->copline > (line_t)$4)
402 PL_parser->copline = (line_t)$4;
eae48c89
Z
403 }
404 | sideff ';'
405 {
406 PL_parser->expect = XSTATE;
407 $$ = $1;
eae48c89
Z
408 }
409 | ';'
410 {
411 PL_parser->expect = XSTATE;
b5bbe64a 412 $$ = (OP*)NULL;
eae48c89 413 PL_parser->copline = NOLINE;
5f211341 414 }
8d063cd8
LW
415 ;
416
705fe0e5
FC
417/* Format line */
418formline: THING formarg
419 { OP *list;
420 if ($2) {
421 OP *term = $2;
705fe0e5
FC
422 list = op_append_elem(OP_LIST, $1, term);
423 }
424 else {
705fe0e5 425 list = $1;
705fe0e5
FC
426 }
427 if (PL_parser->copline == NOLINE)
428 PL_parser->copline = CopLINE(PL_curcop)-1;
429 else PL_parser->copline--;
430 $$ = newSTATEOP(0, NULL,
431 convert(OP_FORMLINE, 0, list));
432 }
433 ;
434
435formarg : /* NULL */
436 { $$ = NULL; }
437 | FORMLBRACK stmtseq FORMRBRACK
438 { $$ = op_unscope($2); }
439 ;
440
891be019 441/* An expression which may have a side-effect */
a687059c 442sideff : error
bcabcc50 443 { $$ = (OP*)NULL; }
a687059c 444 | expr
79072805 445 { $$ = $1; }
a687059c 446 | expr IF expr
b5bbe64a 447 { $$ = newLOGOP(OP_AND, 0, $3, $1); }
a687059c 448 | expr UNLESS expr
b5bbe64a 449 { $$ = newLOGOP(OP_OR, 0, $3, $1); }
a687059c 450 | expr WHILE expr
b5bbe64a 451 { $$ = newLOOPOP(OPf_PARENS, 1, scalar($3), $1); }
55497cff 452 | expr UNTIL iexpr
b5bbe64a 453 { $$ = newLOOPOP(OPf_PARENS, 1, $3, $1); }
ecca16b0 454 | expr FOR expr
94bf0465 455 { $$ = newFOROP(0, (OP*)NULL, $3, $1, (OP*)NULL);
b5bbe64a 456 PL_parser->copline = (line_t)$2; }
f20dcd76 457 | expr WHEN expr
3ad73efd 458 { $$ = newWHENOP($3, op_scope($1)); }
79072805
LW
459 ;
460
891be019 461/* else and elsif blocks */
79072805 462else : /* NULL */
bcabcc50 463 { $$ = (OP*)NULL; }
55497cff 464 | ELSE mblock
3ad73efd
Z
465 {
466 ($2)->op_flags |= OPf_PARENS;
467 $$ = op_scope($2);
f05e27e5 468 }
417a992d 469 | ELSIF '(' mexpr ')' mblock else
b5bbe64a 470 { PL_parser->copline = (line_t)$1;
3ad73efd
Z
471 $$ = newCONDOP(0,
472 newSTATEOP(OPf_SPECIAL,NULL,$3),
473 op_scope($5), $6);
474 PL_hints |= HINT_BLOCK_SCOPE;
f05e27e5 475 }
79072805
LW
476 ;
477
891be019 478/* Continue blocks */
79072805 479cont : /* NULL */
bcabcc50 480 { $$ = (OP*)NULL; }
79072805 481 | CONTINUE block
b5bbe64a 482 { $$ = op_scope($2); }
79072805
LW
483 ;
484
a034e688
DM
485/* determine whether there are any new my declarations */
486mintro : /* NULL */
487 { $$ = (PL_min_intro_pending &&
488 PL_max_intro_pending >= PL_min_intro_pending);
489 intro_my(); }
490
891be019 491/* Normal expression */
8d063cd8 492nexpr : /* NULL */
bcabcc50 493 { $$ = (OP*)NULL; }
8d063cd8
LW
494 | sideff
495 ;
496
891be019 497/* Boolean expression */
8d063cd8 498texpr : /* NULL means true */
f05e27e5
DM
499 { YYSTYPE tmplval;
500 (void)scan_num("1", &tmplval);
501 $$ = tmplval.opval; }
8d063cd8
LW
502 | expr
503 ;
504
891be019 505/* Inverted boolean expression */
55497cff 506iexpr : expr
507 { $$ = invert(scalar($1)); }
508 ;
509
891be019 510/* Expression with its own lexical scope */
55497cff 511mexpr : expr
bbce6d69 512 { $$ = $1; intro_my(); }
513 ;
514
515mnexpr : nexpr
516 { $$ = $1; intro_my(); }
55497cff 517 ;
518
55497cff 519miexpr : iexpr
bbce6d69 520 { $$ = $1; intro_my(); }
55497cff 521 ;
522
44a8e56a 523formname: WORD { $$ = $1; }
bcabcc50 524 | /* NULL */ { $$ = (OP*)NULL; }
8d063cd8
LW
525 ;
526
fa83b5b6 527startsub: /* NULL */ /* start a regular subroutine scope */
a8ff2fa6
DM
528 { $$ = start_subparse(FALSE, 0);
529 SAVEFREESV(PL_compcv); }
f05e27e5 530
28757baa 531 ;
532
533startanonsub: /* NULL */ /* start an anonymous subroutine scope */
a8ff2fa6
DM
534 { $$ = start_subparse(FALSE, CVf_ANON);
535 SAVEFREESV(PL_compcv); }
28757baa 536 ;
537
44a8e56a 538startformsub: /* NULL */ /* start a format subroutine scope */
a8ff2fa6
DM
539 { $$ = start_subparse(TRUE, 0);
540 SAVEFREESV(PL_compcv); }
44a8e56a 541 ;
542
891be019 543/* Name of a subroutine - must be a bareword, could be special */
50278755 544subname : WORD
4210d3f1 545 | PRIVATEREF
a0d0e21e
LW
546 ;
547
891be019 548/* Subroutine prototype */
4633a7c4 549proto : /* NULL */
bcabcc50 550 { $$ = (OP*)NULL; }
4633a7c4
LW
551 | THING
552 ;
28757baa 553
891be019 554/* Optional list of subroutine attributes */
09bef843 555subattrlist: /* NULL */
bcabcc50 556 { $$ = (OP*)NULL; }
09bef843 557 | COLONATTR THING
b5bbe64a 558 { $$ = $2; }
09bef843 559 | COLONATTR
b5bbe64a 560 { $$ = (OP*)NULL; }
09bef843
SB
561 ;
562
891be019 563/* List of attributes for a "my" variable declaration */
09bef843 564myattrlist: COLONATTR THING
b5bbe64a 565 { $$ = $2; }
09bef843 566 | COLONATTR
b5bbe64a 567 { $$ = (OP*)NULL; }
09bef843
SB
568 ;
569
30d9c59b
Z
570/* Optional subroutine signature */
571subsignature: /* NULL */ { $$ = (OP*)NULL; }
572 | '('
573 {
574 if (!FEATURE_SIGNATURES_IS_ENABLED)
575 Perl_croak(aTHX_ "Experimental "
576 "subroutine signatures not enabled");
577 Perl_ck_warner_d(aTHX_
578 packWARN(WARN_EXPERIMENTAL__SIGNATURES),
579 "The signatures feature is experimental");
580 $<opval>$ = parse_subsignature();
581 }
582 ')'
583 {
584 $$ = op_append_list(OP_LINESEQ, $<opval>2,
585 newSTATEOP(0, NULL, sawparens(newNULLLIST())));
586 PL_parser->expect = XBLOCK;
587 }
588 ;
589
590/* Subroutine body - block with optional signature */
591realsubbody: remember subsignature '{' stmtseq '}'
592 {
b5bbe64a
JH
593 if (PL_parser->copline > (line_t)$3)
594 PL_parser->copline = (line_t)$3;
30d9c59b
Z
595 $$ = block_end($1,
596 op_append_list(OP_LINESEQ, $2, $4));
30d9c59b
Z
597 }
598 ;
599
600/* Optional subroutine body, for named subroutine declaration */
601optsubbody: realsubbody { $$ = $1; }
b5bbe64a 602 | ';' { $$ = (OP*)NULL;
53a7735b 603 PL_parser->expect = XSTATE;
f05e27e5 604 }
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),
f05e27e5 641 newUNOP(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),
f05e27e5 646 newUNOP(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),
f05e27e5
DM
652 newUNOP(OP_METHOD, 0, $1)));
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),
f05e27e5 658 newUNOP(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 */
264e1af3 683 { $$ = newBINOP(OP_GELEM, 0, $1, scalar($3));
53a7735b 684 PL_parser->expect = XOPERATOR;
f05e27e5 685 }
891be019 686 | scalar '[' expr ']' /* $array[$element] */
f05e27e5 687 { $$ = newBINOP(OP_AELEM, 0, oopsAV($1), scalar($3));
f05e27e5 688 }
891be019 689 | term ARROW '[' expr ']' /* somearef->[$element] */
fad39ff1
SM
690 { $$ = newBINOP(OP_AELEM, 0,
691 ref(newAVREF($1),OP_RV2AV),
f05e27e5 692 scalar($4));
f05e27e5 693 }
891be019 694 | subscripted '[' expr ']' /* $foo->[$bar]->[$baz] */
fad39ff1
SM
695 { $$ = newBINOP(OP_AELEM, 0,
696 ref(newAVREF($1),OP_RV2AV),
f05e27e5 697 scalar($3));
f05e27e5 698 }
5a63ceef 699 | scalar '{' expr ';' '}' /* $foo{bar();} */
fad39ff1 700 { $$ = newBINOP(OP_HELEM, 0, oopsHV($1), jmaybe($3));
53a7735b 701 PL_parser->expect = XOPERATOR;
f05e27e5 702 }
891be019 703 | term ARROW '{' expr ';' '}' /* somehref->{bar();} */
fad39ff1
SM
704 { $$ = newBINOP(OP_HELEM, 0,
705 ref(newHVREF($1),OP_RV2HV),
706 jmaybe($4));
53a7735b 707 PL_parser->expect = XOPERATOR;
f05e27e5 708 }
891be019 709 | subscripted '{' expr ';' '}' /* $foo->[bar]->{baz;} */
fad39ff1
SM
710 { $$ = newBINOP(OP_HELEM, 0,
711 ref(newHVREF($1),OP_RV2HV),
712 jmaybe($3));
53a7735b 713 PL_parser->expect = XOPERATOR;
f05e27e5 714 }
891be019 715 | term ARROW '(' ')' /* $subref->() */
fad39ff1 716 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
b5bbe64a 717 newCVREF(0, scalar($1))); }
891be019 718 | term ARROW '(' expr ')' /* $subref->(@args) */
fad39ff1 719 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 720 op_append_elem(OP_LIST, $4,
b5bbe64a 721 newCVREF(0, scalar($1)))); }
fad39ff1 722
417a992d 723 | subscripted '(' expr ')' /* $foo->{bar}->(@args) */
fad39ff1 724 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 725 op_append_elem(OP_LIST, $3,
b5bbe64a 726 newCVREF(0, scalar($1)))); }
417a992d 727 | subscripted '(' ')' /* $foo->{bar}->() */
fad39ff1 728 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
b5bbe64a 729 newCVREF(0, scalar($1))); }
9a9798c2 730 | '(' expr ')' '[' expr ']' /* list slice */
b5bbe64a 731 { $$ = newSLICEOP(0, $5, $2); }
ea25a9b2 732 | QWLIST '[' expr ']' /* list literal slice */
b5bbe64a 733 { $$ = newSLICEOP(0, $3, $1); }
9a9798c2 734 | '(' ')' '[' expr ']' /* empty list slice! */
b5bbe64a 735 { $$ = newSLICEOP(0, $4, (OP*)NULL); }
891be019 736 ;
fad39ff1 737
891be019 738/* Binary operators between terms */
f05e27e5 739termbinop: term ASSIGNOP term /* $x = $y */
b5bbe64a 740 { $$ = newASSIGNOP(OPf_STACKED, $1, $2, $3); }
891be019 741 | term POWOP term /* $x ** $y */
b5bbe64a 742 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 743 | term MULOP term /* $x * $y, $x x $y */
b5bbe64a 744 { if ($2 != OP_REPEAT)
79072805 745 scalar($1);
b5bbe64a 746 $$ = newBINOP($2, 0, $1, scalar($3));
f05e27e5 747 }
891be019 748 | term ADDOP term /* $x + $y */
b5bbe64a 749 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 750 | term SHIFTOP term /* $x >> $y, $x << $y */
b5bbe64a 751 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 752 | term RELOP term /* $x > $y, etc. */
b5bbe64a 753 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 754 | term EQOP term /* $x == $y, $x eq $y */
b5bbe64a 755 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 756 | term BITANDOP term /* $x & $y */
b5bbe64a 757 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 758 | term BITOROP term /* $x | $y */
b5bbe64a 759 { $$ = newBINOP($2, 0, scalar($1), scalar($3)); }
891be019 760 | term DOTDOT term /* $x..$y, $x...$y */
b5bbe64a 761 { $$ = newRANGE($2, scalar($1), scalar($3)); }
891be019 762 | term ANDAND term /* $x && $y */
b5bbe64a 763 { $$ = newLOGOP(OP_AND, 0, $1, $3); }
891be019 764 | term OROR term /* $x || $y */
b5bbe64a 765 { $$ = newLOGOP(OP_OR, 0, $1, $3); }
c963b151 766 | term DORDOR term /* $x // $y */
b5bbe64a 767 { $$ = newLOGOP(OP_DOR, 0, $1, $3); }
891be019 768 | term MATCHOP term /* $x =~ /$y/ */
b5bbe64a 769 { $$ = bind_match($2, $1, $3); }
891be019 770 ;
8d063cd8 771
891be019
SC
772/* Unary operators and terms */
773termunop : '-' term %prec UMINUS /* -$x */
b5bbe64a 774 { $$ = newUNOP(OP_NEGATE, 0, scalar($2)); }
891be019 775 | '+' term %prec UMINUS /* +$x */
b5bbe64a
JH
776 { $$ = $2; }
777
891be019 778 | '!' term /* !$x */
b5bbe64a 779 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
891be019 780 | '~' term /* ~$x */
b5bbe64a 781 { $$ = newUNOP(OP_COMPLEMENT, 0, scalar($2)); }
891be019 782 | term POSTINC /* $x++ */
79072805 783 { $$ = newUNOP(OP_POSTINC, 0,
b5bbe64a 784 op_lvalue(scalar($1), OP_POSTINC)); }
891be019 785 | term POSTDEC /* $x-- */
79072805 786 { $$ = newUNOP(OP_POSTDEC, 0,
b5bbe64a 787 op_lvalue(scalar($1), OP_POSTDEC));}
cc624add
FC
788 | term POSTJOIN /* implicit join after interpolated ->@ */
789 { $$ = convert(OP_JOIN, 0,
790 op_append_elem(
791 OP_LIST,
792 newSVREF(scalar(
793 newSVOP(OP_CONST,0,
794 newSVpvs("\""))
795 )),
796 $1
797 ));
cc624add 798 }
891be019 799 | PREINC term /* ++$x */
79072805 800 { $$ = newUNOP(OP_PREINC, 0,
b5bbe64a 801 op_lvalue(scalar($2), OP_PREINC)); }
891be019 802 | PREDEC term /* --$x */
79072805 803 { $$ = newUNOP(OP_PREDEC, 0,
b5bbe64a 804 op_lvalue(scalar($2), OP_PREDEC)); }
891be019
SC
805
806 ;
807
808/* Constructors for anonymous data */
809anonymous: '[' expr ']'
b5bbe64a 810 { $$ = newANONLIST($2); }
891be019 811 | '[' ']'
b5bbe64a 812 { $$ = newANONLIST((OP*)NULL);}
891be019 813 | HASHBRACK expr ';' '}' %prec '(' /* { foo => "Bar" } */
b5bbe64a 814 { $$ = newANONHASH($2); }
891be019 815 | HASHBRACK ';' '}' %prec '(' /* { } (';' by tokener) */
b5bbe64a 816 { $$ = newANONHASH((OP*)NULL); }
30d9c59b 817 | ANONSUB startanonsub proto subattrlist realsubbody %prec '('
5a5094bd 818 { SvREFCNT_inc_simple_void(PL_compcv);
b5bbe64a 819 $$ = newANONATTRSUB($2, $3, $4, $5); }
891be019
SC
820
821 ;
822
823/* Things called with "do" */
824termdo : DO term %prec UNIOP /* do $filename */
b5bbe64a 825 { $$ = dofile($2, $1);}
891be019 826 | DO block %prec '(' /* do { code */
b5bbe64a 827 { $$ = newUNOP(OP_NULL, OPf_SPECIAL, op_scope($2));}
891be019
SC
828 ;
829
830term : termbinop
831 | termunop
832 | anonymous
833 | termdo
e9bdcc27 834 | term '?' term ':' term
b5bbe64a 835 { $$ = newCONDOP(0, $1, $3, $5); }
891be019 836 | REFGEN term /* \$x, \@y, \%z */
b5bbe64a 837 { $$ = newUNOP(OP_REFGEN, 0, op_lvalue($2,OP_REFGEN)); }
09bef843
SB
838 | myattrterm %prec UNIOP
839 { $$ = $1; }
840 | LOCAL term %prec UNIOP
b5bbe64a 841 { $$ = localize($2,$1); }
a0d0e21e 842 | '(' expr ')'
b5bbe64a 843 { $$ = sawparens($2); }
ea25a9b2 844 | QWLIST
b5bbe64a 845 { $$ = $1; }
8d063cd8 846 | '(' ')'
b5bbe64a 847 { $$ = sawparens(newNULLLIST()); }
79072805 848 | scalar %prec '('
8d063cd8 849 { $$ = $1; }
79072805 850 | star %prec '('
8d063cd8 851 { $$ = $1; }
79072805 852 | hsh %prec '('
8d063cd8 853 { $$ = $1; }
79072805 854 | ary %prec '('
8d063cd8 855 { $$ = $1; }
891be019 856 | arylen %prec '(' /* $#x, $#{ something } */
79072805 857 { $$ = newUNOP(OP_AV2ARYLEN, 0, ref($1, OP_AV2ARYLEN));}
fad39ff1
SM
858 | subscripted
859 { $$ = $1; }
89f35911 860 | sliceme '[' expr ']' /* array slice */
2fcb4757 861 { $$ = op_prepend_elem(OP_ASLICE,
79072805 862 newOP(OP_PUSHMARK, 0),
79072805
LW
863 newLISTOP(OP_ASLICE, 0,
864 list($3),
f05e27e5 865 ref($1, OP_ASLICE)));
429a2555
FC
866 if ($$ && $1)
867 $$->op_private |=
868 $1->op_private & OPpSLICEWARNING;
f05e27e5 869 }
76eba8ab 870 | kvslice '[' expr ']' /* array key/value slice */
6dd3e0f2
RZ
871 { $$ = op_prepend_elem(OP_KVASLICE,
872 newOP(OP_PUSHMARK, 0),
873 newLISTOP(OP_KVASLICE, 0,
874 list($3),
875 ref(oopsAV($1), OP_KVASLICE)));
95a31aad
FC
876 if ($$ && $1)
877 $$->op_private |=
878 $1->op_private & OPpSLICEWARNING;
6dd3e0f2 879 }
89f35911 880 | sliceme '{' expr ';' '}' /* @hash{@keys} */
2fcb4757 881 { $$ = op_prepend_elem(OP_HSLICE,
79072805 882 newOP(OP_PUSHMARK, 0),
79072805
LW
883 newLISTOP(OP_HSLICE, 0,
884 list($3),
a0d0e21e 885 ref(oopsHV($1), OP_HSLICE)));
429a2555
FC
886 if ($$ && $1)
887 $$->op_private |=
888 $1->op_private & OPpSLICEWARNING;
53a7735b 889 PL_parser->expect = XOPERATOR;
f05e27e5 890 }
76eba8ab 891 | kvslice '{' expr ';' '}' /* %hash{@keys} */
5cae3edb
RZ
892 { $$ = op_prepend_elem(OP_KVHSLICE,
893 newOP(OP_PUSHMARK, 0),
894 newLISTOP(OP_KVHSLICE, 0,
895 list($3),
896 ref($1, OP_KVHSLICE)));
95a31aad
FC
897 if ($$ && $1)
898 $$->op_private |=
899 $1->op_private & OPpSLICEWARNING;
5cae3edb 900 PL_parser->expect = XOPERATOR;
5cae3edb 901 }
79072805
LW
902 | THING %prec '('
903 { $$ = $1; }
891be019 904 | amper /* &foo; */
c07a80fd 905 { $$ = newUNOP(OP_ENTERSUB, 0, scalar($1)); }
fb602e32 906 | amper '(' ')' /* &foo() or foo() */
f05e27e5 907 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1));
f05e27e5 908 }
fb602e32 909 | amper '(' expr ')' /* &foo(@args) or foo(@args) */
f05e27e5
DM
910 {
911 $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 912 op_append_elem(OP_LIST, $3, scalar($1)));
f05e27e5 913 }
fb602e32 914 | NOAMP subname optlistexpr /* foo @args (no parens) */
a0d0e21e 915 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 916 op_append_elem(OP_LIST, $3, scalar($2)));
f05e27e5 917 }
89f35911 918 | term ARROW '$' '*'
b5bbe64a 919 { $$ = newSVREF($1); }
89f35911 920 | term ARROW '@' '*'
b5bbe64a 921 { $$ = newAVREF($1); }
89f35911 922 | term ARROW '%' '*'
b5bbe64a 923 { $$ = newHVREF($1); }
89f35911
FC
924 | term ARROW '&' '*'
925 { $$ = newUNOP(OP_ENTERSUB, 0,
b5bbe64a 926 scalar(newCVREF($3,$1))); }
89f35911 927 | term ARROW '*' '*' %prec '('
b5bbe64a 928 { $$ = newGVREF(0,$1); }
891be019 929 | LOOPEX /* loop exiting command (goto, last, dump, etc) */
b5bbe64a
JH
930 { $$ = newOP($1, OPf_SPECIAL);
931 PL_hints |= HINT_BLOCK_SCOPE; }
a0d0e21e 932 | LOOPEX term
b5bbe64a 933 { $$ = newLOOPEX($1,$2); }
09b1cffe 934 | NOTOP listexpr /* not $foo */
b5bbe64a 935 { $$ = newUNOP(OP_NOT, 0, scalar($2)); }
891be019 936 | UNIOP /* Unary op, $_ implied */
b5bbe64a 937 { $$ = newOP($1, 0); }
f05e27e5 938 | UNIOP block /* eval { foo }* */
b5bbe64a 939 { $$ = newUNOP($1, 0, $2); }
891be019 940 | UNIOP term /* Unary op */
b5bbe64a 941 { $$ = newUNOP($1, 0, $2); }
d2fdf8fd 942 | REQUIRE /* require, $_ implied */
b5bbe64a 943 { $$ = newOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0); }
d2fdf8fd 944 | REQUIRE term /* require Foo */
b5bbe64a 945 { $$ = newUNOP(OP_REQUIRE, $1 ? OPf_SPECIAL : 0, $2); }
3cd0a11a
RGS
946 | UNIOPSUB
947 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
891be019 948 | UNIOPSUB term /* Sub treated as unop */
4633a7c4 949 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED,
2fcb4757 950 op_append_elem(OP_LIST, $2, scalar($1))); }
891be019 951 | FUNC0 /* Nullary operator */
b5bbe64a 952 { $$ = newOP($1, 0); }
ae986130 953 | FUNC0 '(' ')'
b5bbe64a 954 { $$ = newOP($1, 0);}
7eb971ee
FC
955 | FUNC0OP /* Same as above, but op created in toke.c */
956 { $$ = $1; }
957 | FUNC0OP '(' ')'
b5bbe64a 958 { $$ = $1; }
891be019 959 | FUNC0SUB /* Sub treated as nullop */
b5bbe64a 960 { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); }
891be019 961 | FUNC1 '(' ')' /* not () */
b5bbe64a
JH
962 { $$ = ($1 == OP_NOT)
963 ? newUNOP($1, 0, newSVOP(OP_CONST, 0, newSViv(0)))
964 : newOP($1, OPf_SPECIAL); }
891be019 965 | FUNC1 '(' expr ')' /* not($foo) */
b5bbe64a 966 { $$ = newUNOP($1, 0, $3); }
d63c20f2
DM
967 | PMFUNC /* m//, s///, qr//, tr/// */
968 {
969 if ( $1->op_type != OP_TRANS
970 && $1->op_type != OP_TRANSR
971 && (((PMOP*)$1)->op_pmflags & PMf_HAS_CV))
972 {
973 $<ival>$ = start_subparse(FALSE, CVf_ANON);
974 SAVEFREESV(PL_compcv);
975 } else
976 $<ival>$ = 0;
977 }
978 '(' listexpr ')'
b5bbe64a 979 { $$ = pmruntime($1, $4, 1, $<ival>2); }
79072805 980 | WORD
378cc40b 981 | listop
be25f609 982 | YADAYADA
983 {
984 $$ = newLISTOP(OP_DIE, 0, newOP(OP_PUSHMARK, 0),
985 newSVOP(OP_CONST, 0, newSVpvs("Unimplemented")));
986 }
88e1f1a2 987 | PLUGEXPR
8d063cd8
LW
988 ;
989
891be019 990/* "my" declarations, with optional attributes */
09bef843 991myattrterm: MY myterm myattrlist
b5bbe64a 992 { $$ = my_attrs($2,$3); }
09bef843 993 | MY myterm
b5bbe64a 994 { $$ = localize($2,$1); }
09bef843
SB
995 ;
996
891be019 997/* Things that can be "my"'d */
09bef843 998myterm : '(' expr ')'
b5bbe64a 999 { $$ = sawparens($2); }
09bef843 1000 | '(' ')'
b5bbe64a
JH
1001 { $$ = sawparens(newNULLLIST()); }
1002
09bef843
SB
1003 | scalar %prec '('
1004 { $$ = $1; }
1005 | hsh %prec '('
1006 { $$ = $1; }
1007 | ary %prec '('
1008 { $$ = $1; }
1009 ;
1010
891be019 1011/* Basic list expressions */
09b1cffe 1012optlistexpr: /* NULL */ %prec PREC_LOW
bcabcc50 1013 { $$ = (OP*)NULL; }
09b1cffe 1014 | listexpr %prec PREC_LOW
a0d0e21e
LW
1015 { $$ = $1; }
1016 ;
1017
09b1cffe 1018optexpr: /* NULL */
bcabcc50 1019 { $$ = (OP*)NULL; }
79072805
LW
1020 | expr
1021 { $$ = $1; }
1022 ;
1023
891be019
SC
1024/* A little bit of trickery to make "for my $foo (@bar)" actually be
1025 lexical */
55497cff 1026my_scalar: scalar
12bd6ede 1027 { PL_parser->in_my = 0; $$ = my($1); }
55497cff 1028 ;
1029
79072805 1030amper : '&' indirob
b5bbe64a 1031 { $$ = newCVREF($1,$2); }
a687059c
LW
1032 ;
1033
79072805 1034scalar : '$' indirob
b5bbe64a 1035 { $$ = newSVREF($2); }
a687059c
LW
1036 ;
1037
79072805 1038ary : '@' indirob
f05e27e5 1039 { $$ = newAVREF($2);
b5bbe64a 1040 if ($$) $$->op_private |= $1;
f05e27e5 1041 }
79072805
LW
1042 ;
1043
1044hsh : '%' indirob
f05e27e5 1045 { $$ = newHVREF($2);
b5bbe64a 1046 if ($$) $$->op_private |= $1;
f05e27e5 1047 }
79072805
LW
1048 ;
1049
1050arylen : DOLSHARP indirob
b5bbe64a 1051 { $$ = newAVREF($2); }
ff25e5db 1052 | term ARROW DOLSHARP '*'
b5bbe64a 1053 { $$ = newAVREF($1); }
79072805
LW
1054 ;
1055
1056star : '*' indirob
b5bbe64a 1057 { $$ = newGVREF(0,$2); }
79072805
LW
1058 ;
1059
89f35911
FC
1060sliceme : ary
1061 | term ARROW '@'
b5bbe64a 1062 { $$ = newAVREF($1); }
89f35911
FC
1063 ;
1064
76eba8ab
FC
1065kvslice : hsh
1066 | term ARROW '%'
b5bbe64a 1067 { $$ = newHVREF($1); }
76eba8ab
FC
1068 ;
1069
89f35911
FC
1070gelem : star
1071 | term ARROW '*'
b5bbe64a 1072 { $$ = newGVREF(0,$1); }
89f35911
FC
1073 ;
1074
891be019 1075/* Indirect objects */
79072805
LW
1076indirob : WORD
1077 { $$ = scalar($1); }
fad39ff1 1078 | scalar %prec PREC_LOW
f05e27e5 1079 { $$ = scalar($1); }
79072805 1080 | block
3ad73efd 1081 { $$ = op_scope($1); }
79072805 1082
93a17b20
LW
1083 | PRIVATEREF
1084 { $$ = $1; }
8d063cd8 1085 ;